NameValue.java
5.92 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
193
194
195
196
197
198
199
200
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.util.Text
*/
package com.day.cq.dam.scene7.impl.protocol;
import java.util.Vector;
import org.apache.jackrabbit.util.Text;
public class NameValue {
private String name = null;
private String value = null;
private String defaultValue = null;
private NameValue parent = null;
private boolean enabled = true;
private Vector<NameValue> children = new Vector();
public NameValue(String name, String value, String defaultValue) {
this.setName(name);
this.setValue(value);
this.setDefaultValue(defaultValue);
}
public NameValue(String name, String value) {
this(name, value, null);
}
public NameValue(String name) {
this(name, null, null);
}
public String getName() {
return this.name;
}
public void setName(String val) {
this.name = val;
}
public String getValue() {
return this.value;
}
public void setValue(String val) {
this.value = val;
}
public String getDefaultValue() {
return this.defaultValue;
}
public void setDefaultValue(String val) {
this.defaultValue = val;
}
public String getCheckedValue() {
String val = this.getValue();
if (val != null && val.equals(this.getDefaultValue())) {
return null;
}
return val;
}
public NameValue getParent() {
return this.parent;
}
public void setParent(NameValue parent) {
this.parent = parent;
}
public NameValue getRoot() {
NameValue root = this;
while (root.getParent() != null) {
root = root.getParent();
}
return root;
}
public boolean getEnabled() {
return this.enabled;
}
public void setEnabled(boolean val) {
this.enabled = val;
}
public void addNode(NameValue node) {
this.addNodeAt(node, this.children.size());
}
public void addNodeAt(NameValue node, int idx) {
this.children.add(idx < 0 ? 0 : (idx > this.children.size() ? this.children.size() : idx), node);
node.setParent(this);
}
public NameValue removeNode(String name, String value) {
for (int i = 0; i < this.children.size(); ++i) {
if (!this.children.get(i).getName().equals(name) || value != null && !this.children.get(i).getValue().equals(value)) continue;
NameValue ret = this.children.get(i);
this.children.remove(i);
ret.setParent(null);
return ret;
}
return null;
}
public NameValue removeNode(String name) {
return this.removeNode(name, null);
}
public void removeAllNodes() {
for (int i = 0; i < this.children.size(); ++i) {
this.children.get(i).setParent(null);
}
this.children = new Vector();
}
public NameValue getNode(String name, String value) {
for (int i = 0; i < this.children.size(); ++i) {
if (!this.children.get(i).getName().equals(name) || value != null && !this.children.get(i).getValue().equals(value)) continue;
return this.children.get(i);
}
return null;
}
public NameValue getNode(String name) {
return this.getNode(name, null);
}
public Vector<NameValue> getNodeArray(String name, String value, boolean includeDisabled) {
Vector<NameValue> ret = new Vector<NameValue>();
for (int i = 0; i < this.children.size(); ++i) {
if (name != null && !name.equals(this.children.get(i).getName()) || value != null && !value.equals(this.children.get(i).getValue()) || !includeDisabled && !this.children.get(i).getEnabled()) continue;
ret.add(this.children.get(i));
}
return ret;
}
public Vector<NameValue> getNodeArray() {
return this.getNodeArray(null, null, true);
}
public void searchNodeArray(Vector<NameValue> arr, String name, String value, boolean includeDisabled) {
if ((name == null || name.equals(this.getName())) && (value == null || value.equals(this.getValue())) && (includeDisabled || this.getEnabled())) {
arr.add(this);
}
for (int i = 0; i < this.children.size(); ++i) {
this.children.get(i).searchNodeArray(arr, name, value, includeDisabled);
}
}
public void searchNodeArray(Vector<NameValue> arr) {
this.searchNodeArray(arr, null, null, true);
}
public String nodeString(boolean checked, boolean encode) {
String locValue;
String string = locValue = checked ? this.getCheckedValue() : this.getValue();
if (this.getName() != null && this.getName().length() > 0 && locValue != null) {
String locName = this.getName();
if (encode && locName != null) {
locName = Text.escape((String)locName);
}
if (encode && locValue != null) {
locValue = Text.escape((String)locValue);
}
return "&" + locName + "=" + locValue;
}
return "";
}
public String childString(boolean checked, boolean encode) {
String childStr = "";
for (int i = 0; i < this.children.size(); ++i) {
if (!this.children.get(i).getEnabled()) continue;
childStr = childStr + this.children.get(i).nodeString(checked, encode) + this.children.get(i).childString(checked, encode);
}
return childStr;
}
public String toString(boolean checked, boolean encode) {
String ret = this.nodeString(checked, encode) + this.childString(checked, encode);
if (ret.length() > 0 && ret.charAt(0) == '&') {
return ret.substring(1);
}
return ret;
}
public String toString() {
return this.toString(true, false);
}
public Vector<NameValue> getChildren() {
return this.children;
}
}