DoRRadioButtonElement.java
8.05 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.addon.dor.DoRUtils
* com.adobe.xfa.Attribute
* com.adobe.xfa.Element
* com.adobe.xfa.Node
* com.adobe.xfa.StringAttr
* com.adobe.xfa.XFA
* com.adobe.xfa.content.Content
* com.adobe.xfa.content.IntegerValue
* com.adobe.xfa.content.TextValue
* com.adobe.xfa.template.Value
* com.adobe.xfa.template.containers.Draw
* com.adobe.xfa.template.containers.ExclGroup
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.dor.elements;
import com.adobe.aemds.guide.addon.dor.DoRUtils;
import com.adobe.aemds.guide.addon.dor.elements.DoRElement;
import com.adobe.aemds.guide.addon.dor.elements.DoRElementUtils;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.StringAttr;
import com.adobe.xfa.XFA;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.content.IntegerValue;
import com.adobe.xfa.content.TextValue;
import com.adobe.xfa.template.Value;
import com.adobe.xfa.template.containers.Draw;
import com.adobe.xfa.template.containers.ExclGroup;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DoRRadioButtonElement
extends DoRElement {
private static Logger logger = LoggerFactory.getLogger(DoRRadioButtonElement.class);
public DoRRadioButtonElement(Element xfaElement) throws Exception {
super(xfaElement);
this.xPathExprs.put("jcr:title", "field/caption/value/text/text()");
this.xPathExprs.put("assistPriority", "field/assist/speak/@priority");
this.xPathExprs.put("custom", "field/assist/speak/text()");
this.xPathExprs.put("shortDescription", "field/assist/toolTip/text()");
this.xPathExprs.put("bindRef", "exclGroup/bind/@ref");
this.xPathExprs.put("bindMatch", "exclGroup/bind/@match");
this.xPathExprs.put("name", "exclGroup/@name");
}
@Override
public String getCaptionValueSom() {
return "#field.#caption.#value";
}
@Override
public void applyProperties(Properties properties) throws Exception {
this.adaptForBackwardCompatibility();
Map map = (Map)properties.get("options");
this.applyOptionsProperty(map);
this.adaptToTable();
this.applyDefaultValue(properties);
this.applyProperties(properties, true);
this.setWidth(this.xfaElement.getAttribute(XFA.WTAG).getAttrValue());
}
private void adaptForBackwardCompatibility() {
Node titleNode = this.xfaElement.resolveNode("AF_RADIOBUTTONLISTTITLE");
if (titleNode instanceof Draw) {
this.xPathExprs.put("jcr:title", "draw/value/text/text()");
this.xPathExprs.put("assistPriority", "draw/assist/speak/@priority");
this.xPathExprs.put("custom", "draw/assist/speak/text()");
this.xPathExprs.put("shortDescription", "draw/assist/toolTip/text()");
}
}
private void adaptToTable() {
Element parent = this.xfaElement.getXFAParent();
try {
if (parent.getAttribute(XFA.LAYOUTTAG).getAttrValue().equals("row")) {
String width = DoRElementUtils.getColumnWidthFromParent(this.xfaElement);
DoRElementUtils.adaptToTableCell(this.xfaElement, width);
Element title = (Element)this.xfaElement.resolveNode("AF_RADIOBUTTONLISTTITLE");
if (title != null) {
StringAttr attribute = new StringAttr("presence", "hidden");
title.setAttribute((Attribute)attribute, XFA.PRESENCETAG);
Node caption = title.resolveNode("#caption");
title.removeChild(caption);
Element para = (Element)title.resolveNode("#para");
para.setAttribute((Attribute)new StringAttr("hAlign", "center"), XFA.HALIGNTAG);
DoRElementUtils.adaptToTableCell(title, width);
}
Element exclusionGroup = (Element)this.xfaElement.resolveNode("#exclGroup");
DoRElementUtils.adaptToTableCell(exclusionGroup, width);
int childCount = exclusionGroup.getXFAChildCount();
for (int i = 0; i < childCount; ++i) {
Element element = (Element)exclusionGroup.getXFAChild(i);
if (!element.getClassName().equals("field")) continue;
DoRElementUtils.adaptToTableCell(element, width);
}
}
}
catch (NullPointerException e) {
logger.debug("Radio button is not inside table", (Throwable)e);
}
}
private void applyDefaultValue(Properties properties) {
String name;
Node radioButtonNode;
String key = "_value";
if (properties.containsKey(key) && (radioButtonNode = this.xfaElement.resolveNode(name = "#exclGroup." + this.xfaElement.getName() + properties.getProperty(key))) != null) {
this.xPathExprs.put(key, "exclGroup/field[@name=\"" + this.xfaElement.getName() + properties.getProperty(key) + "\"]" + "/value/text/text()");
}
}
private void applyOptionsProperty(Map<String, String> map) {
String name = this.xfaElement.getName();
Element radioButton = (Element)this.xfaElement.resolveNode("#exclGroup.AF_RADIOBUTTON");
LinkedList<Element> listOfChildren = new LinkedList<Element>();
for (Map.Entry<String, String> entry : map.entrySet()) {
IntegerValue integerValue;
Element radioButtonElement = radioButton.clone(null, true);
Value valueNode = (Value)radioButtonElement.resolveNode("#caption.#value");
Node childValueNode = valueNode.getOneOfChild();
DoRUtils.setValue((Content)((Content)childValueNode), (String)entry.getValue(), (String)null);
TextValue itemsTextValue = (TextValue)radioButtonElement.resolveNode("#items.#text");
if (itemsTextValue == null) {
itemsTextValue = new TextValue((Element)radioButtonElement.resolveNode("#items"), null);
}
if ((integerValue = (IntegerValue)radioButtonElement.resolveNode("#items.#integer")) != null) {
integerValue.remove();
}
radioButtonElement.setName(name + entry.getKey());
itemsTextValue.setValue(entry.getKey());
listOfChildren.add(radioButtonElement);
}
Element exclGroup = (Element)this.xfaElement.resolveNode("#exclGroup");
for (int i = listOfChildren.size() - 1; i >= 0; --i) {
exclGroup.appendChild((Node)listOfChildren.get(i));
}
listOfChildren.clear();
radioButton.remove();
}
private void setWidth(String width) {
Element exclusionGroup;
Element title = (Element)this.xfaElement.resolveNode("AF_RADIOBUTTONLISTTITLE");
if (title != null) {
title.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
}
if ((exclusionGroup = (Element)this.xfaElement.resolveNode("#exclGroup")) != null) {
exclusionGroup.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
int childCount = exclusionGroup.getXFAChildCount();
for (int i = 0; i < childCount; ++i) {
Element element = (Element)exclusionGroup.getXFAChild(i);
if (element == null || !element.getClassName().equals("field")) continue;
element.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
}
}
}
@Override
protected void modifyCaptionAttributes(Element node, double scalingFactor) {
int noOfChild = node.getXFAChildCount();
for (int i = 0; i < noOfChild; ++i) {
Element child = (Element)node.getXFAChild(i);
if (child instanceof ExclGroup) {
this.modifyCaptionAttributes(child, scalingFactor);
}
super.modifyCaptionAttributes(child, scalingFactor);
}
}
}