2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.parser.builder;
22
23 import org.apache.shale.clay.config.beans.AttributeBean;
24 import org.apache.shale.clay.config.beans.ComponentBean;
25 import org.apache.shale.clay.config.beans.ElementBean;
26 import org.apache.shale.clay.parser.Node;
27
28 /***
29 * <p>
30 * This {@link Builder} will create a {@link ElementBean} that will be used to
31 * create a single html option element. The {@link OptionBuilderRule} will
32 * handle mapping the html element to this builder.
33 * </p>
34 */
35 public class SelectItemBuilder extends Builder {
36
37 /***
38 * <p>
39 * Returns a <code>jsfid</code> that will be set on the
40 * target {@link ElementBean}. </p>
41 *
42 * @param node markup
43 * @return jsfid
44 */
45 protected String getJsfid(Node node) {
46 return "selectItem";
47 }
48
49 /***
50 * <p>
51 * Returns the JSF component type of <code>javax.faces.SelectItem</code>
52 * that will populate a {@link ElementBean} and create an html option.
53 * </p>
54 *
55 * @param node markup
56 * @return component type
57 */
58 protected String getComponentType(Node node) {
59 return "javax.faces.SelectItem";
60 }
61
62 /***
63 * <p>
64 * The default for a single option is to look at the next html node to find
65 * the label.
66 * </p>
67 *
68 * @param node markup
69 * @param target child config bean
70 * @param root parent config bean
71 */
72 protected void encodeBegin(Node node, ElementBean target,
73 ComponentBean root) {
74 super.encodeBegin(node, target, root);
75
76 if (!getBuildNodeBody(node, target)) {
77 return;
78 }
79
80 if (target.getAttributes().containsKey("itemValue")
81 && node.getAttributes().containsKey("value")) {
82 String value = (String) node.getAttributes().get("value");
83 AttributeBean attr = target.getAttribute("itemValue");
84 createAttribute(attr, value, target);
85 }
86 if (target.getAttributes().containsKey("itemLabel")
87 && node.getChildren().size() == 1) {
88
89 Node child = (Node) node.getChildren().get(0);
90 String value = child.getToken().getRawText();
91 AttributeBean attr = target.getAttribute("itemLabel");
92 createAttribute(attr, value, target);
93 }
94
95 }
96
97 /***
98 * <p>Returns <code>true</code> by default meaning that the
99 * parent will render children.</p>
100 *
101 * @param node markup
102 * @param target child config bean
103 * @return <code>false</code> if the node's children should be ignored
104 */
105 protected boolean getBuildNodeBody(Node node, ElementBean target) {
106 if (target.getAllowBody() != null) {
107 return super.getBuildNodeBody(node, target);
108 }
109
110 return true;
111 }
112
113 }