PDFFieldLock.java
7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.digsig;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFDocMDPPermissions;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFFieldAction;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldNode;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldUtils;
public class PDFFieldLock
extends PDFCosDictionary {
public static final ASName k_SigFieldLock = ASName.create((String)"SigFieldLock");
protected PDFFieldLock(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFFieldLock getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFFieldLock pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFFieldLock.class);
if (pdfObject == null) {
pdfObject = new PDFFieldLock(cosObject);
}
return pdfObject;
}
public static PDFFieldLock newInstance(PDFDocument pdfDocument, PDFFieldAction action, PDFFieldNode[] fields) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
return PDFFieldLock.newInstance(pdfDocument, action, fields, null);
}
public static PDFFieldLock newInstance(PDFDocument pdfDocument, PDFFieldAction action, PDFFieldNode[] fields, PDFDocMDPPermissions perms) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
PDFFieldLock pdfObject = new PDFFieldLock((CosObject)cosObject);
pdfObject.setDictionaryNameValue(ASName.k_Type, k_SigFieldLock);
if (action == null) {
throw new PDFInvalidParameterException("action is a required entry so can't be null");
}
pdfObject.setDictionaryNameValue(ASName.k_Action, action.getValue());
if (action != PDFFieldAction.All) {
pdfObject.setFields(fields);
}
pdfObject.setLockPermissions(perms);
return pdfObject;
}
public PDFFieldAction getPDFFieldAction() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFieldAction.getInstance(this.getDictionaryNameValue(ASName.k_Action));
}
public void setPDFFieldAction(PDFFieldAction action) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (action == null) {
throw new PDFInvalidDocumentException("Invalid parameter:action can not be null.");
}
this.setDictionaryNameValue(ASName.k_Action, action.getValue());
if (action == PDFFieldAction.All) {
this.getCosDictionary().remove(ASName.k_Fields);
}
}
public String[] getPDFFieldNames() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_Fields);
if (cosArray == null) {
return null;
}
String[] names = new String[cosArray.size()];
for (int i = 0; i < names.length; ++i) {
names[i] = cosArray.getString(i).asString();
}
return names;
}
public void setPDFFieldNames(String[] fieldNames) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (this.getPDFFieldAction() != PDFFieldAction.All && (fieldNames == null || fieldNames.length == 0)) {
throw new PDFInvalidParameterException("The Fields entry should not be empty when the the Field action is Include or Exclude.");
}
this.getCosDictionary().remove(ASName.k_Fields);
if (fieldNames != null && fieldNames.length != 0) {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < fieldNames.length; ++i) {
if (fieldNames[i] == null) continue;
cosArray.addText(fieldNames[i]);
}
if (cosArray.size() > 0) {
this.setDictionaryArrayValue(ASName.k_Fields, cosArray);
}
if (cosArray.size() == 0) {
throw new PDFInvalidParameterException("The Fields entry should not be empty when the the Field action is Include or Exclude.");
}
}
}
public PDFFieldNode[] getFields() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
if (this.getPDFFieldAction() == PDFFieldAction.All || !this.getCosDictionary().containsKey((Object)ASName.k_Fields)) {
return null;
}
return PDFFieldUtils.searchFields(this.getPDFFieldNames(), this.getPDFDocument());
}
public void setFields(PDFFieldNode[] fieldNodes) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (this.getPDFFieldAction() == PDFFieldAction.All) {
throw new PDFInvalidParameterException("The field lock action must be Include or Exclude prior to setting the fields to be included or excluded.");
}
if (fieldNodes == null || fieldNodes.length == 0) {
throw new PDFInvalidParameterException("The fieldNodes parameter cannot be null or an empty array.");
}
boolean fieldNodesIsEmpty = true;
for (int i = 0; i < fieldNodes.length && fieldNodesIsEmpty; ++i) {
if (fieldNodes[i] == null) continue;
fieldNodesIsEmpty = false;
}
if (fieldNodesIsEmpty) {
throw new PDFInvalidParameterException("The fieldNodes array must contain at least one PDFFieldNode value.");
}
String[] fieldNames = new String[fieldNodes.length];
for (int i2 = 0; i2 < fieldNodes.length; ++i2) {
fieldNames[i2] = fieldNodes[i2] != null ? fieldNodes[i2].getQualifiedName() : null;
}
this.setPDFFieldNames(fieldNames);
}
public PDFDocMDPPermissions getLockPermissions() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)ASName.k_P)) {
int cosPerm = this.getDictionaryIntValue(ASName.k_P);
return PDFDocMDPPermissions.getInstance(cosPerm);
}
return null;
}
public void setLockPermissions(PDFDocMDPPermissions perms) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (perms == null) {
this.removeValue(ASName.k_P);
} else {
this.setDictionaryIntValue(ASName.k_P, perms.getValue());
}
}
}