Paramable.java
3.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
/*
* 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.ParamCommand;
import com.day.cq.dam.scene7.impl.protocol.is.ParamUtils;
import java.util.Vector;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Paramable
extends NameValue {
private final Logger log;
private ParamCommand paramCmd;
public Paramable(String name, String inValue, String defaultValue) {
super(name, ParamUtils.isParamRef(inValue) ? null : inValue, defaultValue);
this.log = LoggerFactory.getLogger(this.getClass());
if (this.getValue() == null) {
super.setValue(inValue);
}
}
public Paramable(String name, String inValue) {
this(name, inValue, null);
}
public Paramable(String name) {
this(name, null, null);
}
@Override
public void setParent(NameValue parent) {
super.setParent(parent);
if (parent == null) {
this.setParamCmd(null);
} else if (ParamUtils.isParamRef(super.getValue())) {
this.parameterize(super.getValue());
}
}
@Override
public void setValue(String inValue) {
super.setValue(inValue);
this.valueChanged();
}
@Override
public String nodeString(boolean checked, boolean encode) {
if (this.isVariable()) {
String locName = this.getName();
if (encode && locName != null) {
locName = Text.escape((String)locName);
}
String locValue = this.getParameterizedValue();
if (encode && locValue != null) {
locValue = Text.escape((String)locValue);
}
return "&" + locName + "=" + locValue;
}
return super.nodeString(checked, encode);
}
public ParamCommand getParamCmd() {
return this.paramCmd;
}
public void setParamCmd(ParamCommand cmd) {
if (this.paramCmd == cmd) {
return;
}
this.paramCmd = cmd;
if (this.paramCmd != null) {
this.paramCmd.addRef(this);
}
}
public boolean isVariable() {
return this.paramCmd != null;
}
public String getDefaultParameterValue() {
return this.getValue();
}
public String makeParamName() {
String paramName = "";
NameValue locCmd = this.getParent();
while (locCmd.getParent() != null) {
paramName = locCmd.getName() + "_" + locCmd.getValue() + "_" + paramName;
locCmd = locCmd.getParent();
}
paramName = "$" + paramName + this.getName();
return paramName;
}
protected void parameterize(String paramRef) {
Vector<String> refs = ParamUtils.getParamRefs(paramRef);
for (int i = 0; i < refs.size(); ++i) {
String paramName = refs.elementAt(i);
ParamCommand locParamCmd = (ParamCommand)this.getRoot().getNode(paramName.substring(0, paramName.length() - 1));
if (locParamCmd != null) {
if (!this.getName().equals("text") && !this.getName().equals("textps")) {
this.setValue(locParamCmd.getValue());
}
this.setParamCmd(locParamCmd);
continue;
}
this.log.warn("Could not locate parameter for " + this.getName() + ": " + paramRef);
}
}
protected String getParameterizedValue() {
return this.paramCmd.getName() + "$";
}
protected void valueChanged() {
if (this.isVariable() && this.getParent() != null) {
this.paramCmd.updateRefs(this.getValue(), this);
}
}
}