1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package cz.hobrasoft.pdfmu.operation.signature;
18
19 import com.itextpdf.text.pdf.PdfSignatureAppearance;
20 import com.itextpdf.text.pdf.PdfStamper;
21 import cz.hobrasoft.pdfmu.operation.args.ArgsConfiguration;
22 import java.util.Calendar;
23 import java.util.logging.Logger;
24 import net.sourceforge.argparse4j.inf.ArgumentGroup;
25 import net.sourceforge.argparse4j.inf.ArgumentParser;
26 import net.sourceforge.argparse4j.inf.Namespace;
27
28
29
30
31
32 class SignatureAppearanceParameters implements ArgsConfiguration {
33
34 public String reason = null;
35 public String location = null;
36 public String contact = null;
37 public Calendar signDate = null;
38 public int certificationLevel = PdfSignatureAppearance.NOT_CERTIFIED;
39
40 private static final Logger logger = Logger.getLogger(SignatureAppearanceParameters.class.getName());
41
42 @Override
43 public void addArguments(ArgumentParser parser) {
44 ArgumentGroup group = parser.addArgumentGroup("signature metadata");
45
46
47
48
49
50
51 group.addArgument("--reason")
52 .help("What was the reason for signing? (default: <none>)")
53 .type(String.class);
54 group.addArgument("--location")
55 .help("Where was the document signed? (default: <none>)")
56 .type(String.class);
57 group.addArgument("--contact")
58 .help("signer contact information (defualt: <none>)")
59 .type(String.class);
60
61 }
62
63 @Override
64 public void setFromNamespace(Namespace namespace) {
65 reason = namespace.getString("reason");
66 location = namespace.getString("location");
67 contact = namespace.getString("contact");
68
69
70
71
72 }
73
74 public void configureSignatureAppearance(PdfSignatureAppearance sap) {
75 assert sap != null;
76
77 if (reason != null) {
78 logger.info(String.format("Reason: %s", reason));
79 sap.setReason(reason);
80 }
81 if (location != null) {
82 logger.info(String.format("Location: %s", location));
83 sap.setLocation(location);
84 }
85 if (contact != null) {
86 logger.info(String.format("Contact: %s", contact));
87 sap.setContact(contact);
88 }
89 if (signDate != null) {
90
91 logger.info(String.format("Date: %s", signDate));
92 sap.setSignDate(signDate);
93 }
94 sap.setCertificationLevel(certificationLevel);
95
96
97
98 }
99
100 public PdfSignatureAppearance getSignatureAppearance(PdfStamper stp) {
101 assert stp != null;
102
103
104 PdfSignatureAppearance sap = stp.getSignatureAppearance();
105 configureSignatureAppearance(sap);
106
107 return sap;
108 }
109
110 }