ParamCommand.java
4.38 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.util.Text
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.scene7.impl.protocol.is;
import com.day.cq.dam.scene7.impl.protocol.NameValue;
import com.day.cq.dam.scene7.impl.protocol.is.ParamUtils;
import com.day.cq.dam.scene7.impl.protocol.is.Paramable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Vector;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ParamCommand
extends NameValue {
private final Logger log;
private Vector<Paramable> refs;
private boolean lock;
private String staticType;
public ParamCommand(String name, String value) {
super(name, value);
this.log = LoggerFactory.getLogger(this.getClass());
this.refs = new Vector();
this.lock = false;
this.staticType = null;
}
@Override
public void setParent(NameValue parent) {
super.setParent(parent);
String newValue = this.getValue();
if (newValue != null) {
try {
newValue = URLDecoder.decode(newValue, "utf-8");
}
catch (UnsupportedEncodingException e) {
this.log.error(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
this.log.warn("Could not decode string {}!", (Object)newValue);
}
this.setValue(newValue);
}
}
@Override
public void setName(String val) {
if (val.equals(super.getName())) {
return;
}
Vector<NameValue> arr = ParamUtils.getParameters(this.getRoot());
for (int i = 0; i < arr.size(); ++i) {
if (!val.equals(arr.get(i).getName())) continue;
this.log.debug("Duplicate parameter name: " + val);
return;
}
super.setName(val);
}
@Override
public String getValue() {
return this.getRef() != null && !this.getType().equals("text") && !this.getType().equals("textps") ? this.getRef().getDefaultParameterValue() : super.getValue();
}
@Override
public String nodeString(boolean checked, boolean encode) {
if (super.nodeString(checked, encode).length() == 0) {
return "";
}
String locValue = this.getValue();
if (encode && locValue != null) {
locValue = Text.escape((String)locValue);
}
return "&" + this.getName() + "=" + locValue;
}
public String getType() {
return this.getRef() != null ? this.getRef().getName() : this.staticType;
}
public String getDisplayName() {
return this.getName().substring(1);
}
private Paramable getRef() {
return this.refs.size() > 0 ? this.refs.get(0) : null;
}
public void addRef(Paramable inRef) {
for (int i = 0; i < this.refs.size(); ++i) {
if (this.refs.get(i) != inRef) continue;
return;
}
this.refs.add(inRef);
if (this.getParent() == null) {
inRef.getRoot().addNodeAt(this, 0);
}
}
public void removeRef(NameValue inRef) {
int idx = this.refs.indexOf(inRef);
if (idx == -1) {
return;
}
this.refs.remove(idx);
if (this.refs.size() == 0) {
this.getParent().removeNode(this.getName());
}
}
public void updateRefs(String newValue, NameValue caller) {
if (this.lock) {
return;
}
this.lock = true;
for (int i = 0; i < this.refs.size(); ++i) {
if (caller != null && caller == this.refs.get(i)) continue;
this.refs.get(i).setValue(newValue);
}
this.lock = false;
}
public Vector<Paramable> getRefs() {
return this.refs;
}
public void clearRefs() {
this.staticType = this.getType();
this.refs = new Vector();
}
private void dumpRefs() {
if (this.refs.size() == 0) {
this.log.debug("No refs left");
return;
}
this.log.debug("Param refs: ");
for (int i = 0; i < this.refs.size(); ++i) {
this.log.debug(this.refs.get(i).toString());
}
}
public static boolean validateName(String name) {
return name.matches("[^a-zA-Z0-9-_.]");
}
}