DoRCheckBoxElement.java
7.8 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
/*
* 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.template.Value
* com.adobe.xfa.template.containers.Draw
* 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.template.Value;
import com.adobe.xfa.template.containers.Draw;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DoRCheckBoxElement
extends DoRElement {
private static Logger logger = LoggerFactory.getLogger(DoRCheckBoxElement.class);
protected String CHECKBOXTITLE_NAME;
protected String CHECKBUTTON_NAME;
public DoRCheckBoxElement(Element xfaElement) throws Exception {
super(xfaElement);
this.initNameIdentifiers();
this.xPathExprs.put("jcr:title", "field[@name=\"" + this.CHECKBOXTITLE_NAME + "\"]/caption/value/text/text()");
this.xPathExprs.put("assistPriority", "field[@name=\"" + this.CHECKBOXTITLE_NAME + "\"]/assist/speak/@priority");
this.xPathExprs.put("custom", "field[@name=\"" + this.CHECKBOXTITLE_NAME + "\"]/assist/speak/text()");
this.xPathExprs.put("shortDescription", "field[@name=\"" + this.CHECKBOXTITLE_NAME + "\"]/assist/toolTip/text()");
this.xPathExprs.put("bindRef", "field[@name=\"HiddenTextField\"]/bind/@ref");
this.xPathExprs.put("bindMatch", "field[@name=\"HiddenTextField\"]/bind/@match");
}
protected void initNameIdentifiers() {
this.CHECKBOXTITLE_NAME = "AF_CHECKBOXTITLE";
this.CHECKBUTTON_NAME = "AF_CHECKBUTTON";
}
@Override
public String getCaptionValueSom() {
return this.CHECKBOXTITLE_NAME + ".#caption.#value";
}
@Override
public void applyProperties(Properties properties) throws Exception {
Node hiddenTextField;
this.adaptForBackwardCompatibility();
Map map = (Map)properties.get("options");
this.applyOptionsProperty(map);
this.adaptToTable();
this.applyDefaultValues(properties);
this.applyProperties(properties, true);
String name = properties.getProperty("name");
if (name != null && !name.isEmpty() && (hiddenTextField = this.xfaElement.resolveNode("HiddenTextField")) != null) {
hiddenTextField.setName(name);
}
this.setWidth(this.xfaElement.getAttribute(XFA.WTAG).getAttrValue());
}
private void adaptForBackwardCompatibility() {
Node titleNode = this.xfaElement.resolveNode(this.CHECKBOXTITLE_NAME);
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()");
this.xPathExprs.put("bindRef", "field[ui[textEdit]]/bind/@ref");
this.xPathExprs.put("bindMatch", "field[ui[textEdit]]/bind/@match");
}
}
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(this.CHECKBOXTITLE_NAME);
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);
}
int childCount = this.xfaElement.getXFAChildCount();
for (int i = 0; i < childCount; ++i) {
Element element = (Element)this.xfaElement.getXFAChild(i);
if (!element.getClassName().equals("field")) continue;
DoRElementUtils.adaptToTableCell(element, width);
}
}
}
catch (NullPointerException e) {
logger.debug("Check box is not inside table", (Throwable)e);
}
}
private void applyDefaultValues(Properties properties) {
String key = "_value";
if (properties.containsKey(key)) {
String name = this.xfaElement.getName();
String defaultValue = properties.getProperty("_value");
StringTokenizer tokenizer = new StringTokenizer(defaultValue, ",");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (this.xfaElement.resolveNode(name + token) == null) continue;
this.xPathExprs.put(token, "field[@name=\"" + name + token + "\"" + "]" + "/" + "value/integer/text()");
properties.put(token, "1");
}
properties.remove("_value");
}
}
protected void applyOptionsProperty(Map<String, String> map) {
String name = this.xfaElement.getName();
Element checkButton = (Element)this.xfaElement.resolveNode(this.CHECKBUTTON_NAME);
LinkedList<Element> listOfChildren = new LinkedList<Element>();
for (Map.Entry<String, String> entry : map.entrySet()) {
Element checkButtonElement = checkButton.clone(null, true);
Value valueNode = (Value)checkButtonElement.resolveNode("#caption.#value");
Node childNode = valueNode.getOneOfChild();
DoRUtils.setValue((Content)((Content)childNode), (String)entry.getValue(), (String)null);
checkButtonElement.setName(name + entry.getKey());
listOfChildren.add(checkButtonElement);
}
for (int i = listOfChildren.size() - 1; i >= 0; --i) {
this.xfaElement.appendChild((Node)listOfChildren.get(i));
}
listOfChildren.clear();
checkButton.remove();
}
private void setWidth(String width) {
Element title = (Element)this.xfaElement.resolveNode("AF_CHECKBOXTITLE");
if (title != null) {
title.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
}
int childCount = this.xfaElement.getXFAChildCount();
for (int i = 0; i < childCount; ++i) {
Element element = (Element)this.xfaElement.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);
super.modifyCaptionAttributes(child, scalingFactor);
}
}
}