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.chain;
22
23 import org.apache.commons.chain.Command;
24 import org.apache.commons.chain.Context;
25 import org.apache.shale.clay.parser.Node;
26 import org.apache.shale.clay.parser.builder.Builder;
27 import org.apache.shale.clay.parser.builder.CommandButtonBuilder;
28 import org.apache.shale.clay.parser.builder.InputTextBuilder;
29 import org.apache.shale.clay.parser.builder.SelectBooleanCheckboxBuilder;
30 import org.apache.shale.clay.parser.builder.SelectOneRadioBuilder;
31
32 /***
33 * <p>
34 * This rule <code>Command</code> has an implied mapping to several html
35 * element types. The associated {@link Builder} will be returned regardless of
36 * the <code>jsfid</code>.
37 * <p>
38 */
39 public class InputBuilderRule implements Command {
40
41 /***
42 * <p>Array of target input {@link Builder}s.</p>
43 */
44 private static final Builder[] BUILDERS = { new InputTextBuilder(),
45 new SelectBooleanCheckboxBuilder(), new SelectOneRadioBuilder(),
46 new CommandButtonBuilder() };
47
48 /***
49 * <p>
50 * If the html {@link Node} is a input element, return the correct builder.
51 * If a match is found, the chain is ended.<br>
52 * <dl>
53 * <dt>Input type attribute to {@link Builder}
54 * <dd><b>text</b> {@link org.apache.shale.clay.parser.builder.InputTextBuilder}
55 * <dd><b>checkbox</b> {@link org.apache.shale.clay.parser.builder.SelectBooleanCheckboxBuilder}
56 * <dd><b>raido</b> {@link org.apache.shale.clay.parser.builder.SelectOneRadioBuilder}
57 * <dd><b>submit</b>{@link org.apache.shale.clay.parser.builder.CommandButtonBuilder}
58 * </dl>
59 * <br>
60 * The {@link BuilderRuleContext} will hold the current html {@link Node} and
61 * target {@link Builder}.
62 * </p>
63 *
64 * @param context common chains context
65 * @return <code>true</code> if the chain is done
66 * @throws Exception checked exception
67 */
68 public boolean execute(Context context) throws Exception {
69
70 boolean isFinal = false;
71
72 BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
73 Node node = builderRuleContext.getNode();
74 if (!node.isComment() && node.getName() != null
75 && node.getName().equalsIgnoreCase("input")) {
76
77 String type = (String) node.getAttributes().get("type");
78 if (type != null && type.equalsIgnoreCase("text")) {
79 builderRuleContext.setBuilder(BUILDERS[0]);
80 isFinal = true;
81 } else if (type != null && type.equalsIgnoreCase("checkbox")) {
82 builderRuleContext.setBuilder(BUILDERS[1]);
83 isFinal = true;
84 } else if (type != null && type.equalsIgnoreCase("radio")) {
85 builderRuleContext.setBuilder(BUILDERS[2]);
86 isFinal = true;
87 } else if (type != null && type.equalsIgnoreCase("submit")) {
88 builderRuleContext.setBuilder(BUILDERS[BUILDERS.length - 1]);
89 isFinal = true;
90 }
91
92 }
93
94 return isFinal;
95 }
96
97 }
98