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 java.util.ArrayList;
24 import java.util.Iterator;
25
26 import org.apache.shale.clay.config.beans.ComponentBean;
27 import org.apache.shale.clay.config.beans.ElementBean;
28 import org.apache.shale.clay.parser.Node;
29
30 /***
31 * <p>
32 * This {@link Builder} will create a target
33 * {@link org.apache.shale.clay.config.beans.ElementBean} for a single
34 * select html {@link org.apache.shale.clay.parser.Node}. The mapping between the
35 * html and the builder is handled by the
36 * {@link org.apache.shale.clay.parser.builder.chain.SelectBuilderRule}.
37 * </p>
38 */
39 public class SelectOneMenuBuilder extends Builder {
40
41 /***
42 * <p>
43 * Returns a JSF component type of
44 * <code>javax.faces.HtmlSelectOneMenu</code> that will populate the
45 * target {@link org.apache.shale.clay.config.beans.ElementBean}.
46 * </p>
47 *
48 * @param node markup node
49 * @return component type
50 */
51 protected String getComponentType(Node node) {
52 return "javax.faces.HtmlSelectOneMenu";
53 }
54
55 /***
56 * <p>
57 * Returns the <code>jsfid</code> that will populate the target
58 * {@link org.apache.shale.clay.config.beans.ElementBean}.
59 * </p>
60 *
61 * @param node markup node
62 * @return jsfid
63 */
64 protected String getJsfid(Node node) {
65 return "selectOneMenu";
66 }
67
68 /***
69 * <p>
70 * Returns a <code>true</code> value indicating that the target JSF
71 * component can have children.
72 * </p>
73 *
74 * @return <code>true</code>
75 */
76 public boolean isChildrenAllowed() {
77 return true;
78 }
79
80
81 /***
82 * <p>Remove any child nodes that are not "option" nodes.</p>
83 *
84 * @param node markup
85 * @param target child node
86 * @param root child's parent
87 */
88 protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
89
90
91 ArrayList delList = new ArrayList();
92 Iterator ci = node.getChildren().iterator();
93 while (ci.hasNext()) {
94 Node child = (Node) ci.next();
95 if (child.getName() == null || !child.getName().equalsIgnoreCase("option")) {
96 delList.add(child);
97 }
98 }
99 for (int i = 0; i < delList.size(); i++) {
100 node.getChildren().remove(delList.get(i));
101 }
102 delList.clear();
103
104 super.encodeBegin(node, target, root);
105 }
106
107 }
108