RequestProperty.java
5.87 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.request.RequestParameter
* org.apache.sling.api.resource.ResourceUtil
*/
package com.day.cq.dam.core.impl;
import java.util.ArrayList;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.ResourceUtil;
public class RequestProperty {
private static final RequestParameter[] EMPTY_PARAM_ARRAY = new RequestParameter[0];
public static final String DEFAULT_IGNORE = ":ignore";
public static final String DEFAULT_NULL = ":null";
private final String path;
private final String name;
private final String parentPath;
private RequestParameter[] values;
private String[] stringValues;
private String typeHint;
private boolean hasMultiValueTypeHint;
private RequestParameter[] defaultValues = EMPTY_PARAM_ARRAY;
private boolean isDelete;
private String repositoryResourcePath;
private boolean isRepositoryResourceMove;
private boolean ignoreBlanks;
private boolean useDefaultWhenMissing;
private boolean patch = false;
public RequestProperty(String path) {
assert (path.startsWith("/"));
this.path = ResourceUtil.normalize((String)path);
this.parentPath = ResourceUtil.getParent((String)path);
this.name = ResourceUtil.getName((String)path);
}
public String getTypeHint() {
return this.typeHint;
}
public boolean hasMultiValueTypeHint() {
return this.hasMultiValueTypeHint;
}
public void setTypeHintValue(String typeHint) {
if (typeHint != null && typeHint.endsWith("[]")) {
this.typeHint = typeHint.substring(0, typeHint.length() - 2);
this.hasMultiValueTypeHint = true;
} else {
this.typeHint = typeHint;
this.hasMultiValueTypeHint = false;
}
}
public String getPath() {
return this.path;
}
public String getName() {
return this.name;
}
public String getParentPath() {
return this.parentPath;
}
public boolean hasValues() {
if (this.useDefaultWhenMissing && this.defaultValues != null && this.defaultValues.length > 0) {
return true;
}
if (this.ignoreBlanks) {
return this.values != null && this.getStringValues().length > 0;
}
return this.values != null;
}
public RequestParameter[] getValues() {
return this.values;
}
public void setValues(RequestParameter[] values) {
this.values = values;
}
public RequestParameter[] getDefaultValues() {
return this.defaultValues;
}
public void setDefaultValues(RequestParameter[] defaultValues) {
this.defaultValues = defaultValues == null ? EMPTY_PARAM_ARRAY : defaultValues;
}
public boolean isFileUpload() {
return this.values != null && !this.values[0].isFormField();
}
public boolean providesValue() {
String[] sv = this.getStringValues();
if (sv == null) {
return true;
}
for (String s : sv) {
if (s.equals("")) continue;
return true;
}
return false;
}
public String[] getStringValues() {
if (this.stringValues == null) {
if (this.values == null && this.useDefaultWhenMissing) {
this.stringValues = new String[]{this.defaultValues[0].getString()};
} else if (this.values.length > 1) {
ArrayList<String> stringValueList = new ArrayList<String>(this.values.length);
for (int i = 0; i < this.values.length; ++i) {
String value = this.values[i].getString();
if (this.ignoreBlanks && value.length() <= 0) continue;
stringValueList.add(value);
}
this.stringValues = stringValueList.toArray(new String[stringValueList.size()]);
} else {
String value = this.values[0].getString();
if (value.equals("")) {
if (this.ignoreBlanks) {
return new String[0];
}
if (this.defaultValues.length == 1) {
String defValue = this.defaultValues[0].getString();
if (defValue.equals(":ignore")) {
return new String[0];
}
if (defValue.equals(":null")) {
return null;
}
value = defValue;
}
}
this.stringValues = new String[]{value};
}
}
return this.stringValues;
}
public void setDelete(boolean isDelete) {
this.isDelete = isDelete;
}
public boolean isDelete() {
return this.isDelete;
}
public void setRepositorySource(String sourcePath, boolean isMove) {
if (!sourcePath.startsWith("/")) {
sourcePath = this.getParentPath() + "/" + sourcePath;
sourcePath = ResourceUtil.normalize((String)sourcePath);
}
this.repositoryResourcePath = sourcePath;
this.isRepositoryResourceMove = isMove;
}
public boolean hasRepositoryMoveSource() {
return this.isRepositoryResourceMove;
}
public boolean hasRepositoryCopySource() {
return this.getRepositorySource() != null && !this.hasRepositoryMoveSource();
}
public String getRepositorySource() {
return this.repositoryResourcePath;
}
public void setIgnoreBlanks(boolean b) {
this.ignoreBlanks = b;
}
public void setUseDefaultWhenMissing(boolean b) {
this.useDefaultWhenMissing = b;
}
public void setPatch(boolean b) {
this.patch = b;
}
public boolean isPatch() {
return this.patch;
}
}