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.CommentBuilder;
28 import org.apache.shale.clay.parser.builder.MorphBuilder;
29 import org.apache.shale.clay.parser.builder.VerbatimBuilder;
30
31 /***
32 * <p>
33 * This is a <code>Command</code> implementation that will
34 * match a HTML {@link Node} with a matching {@link Builder}
35 * implementation. This is the default rule and will always return a
36 * {@link OutputLinkBuilder} and the chain terminated. The {@link BuilderFactory} runs this
37 * command rule as part of the <code>Globals.BUILDER_CATALOG_NAME</code>
38 * found in the <code>Globals.BUILDER_RESOURCE_NAME</code> and
39 * invoking the <code>Globals.FIND_BUILDER_COMMAND_NAME</code>
40 * </p>
41 */
42 public class DefaultBuilderRule implements Command {
43
44 /***
45 * <p>
46 * Default static instance of {@link VerbatimBuilder}.
47 * <p>
48 */
49 private static final Builder[] BUILDERS = {new CommentBuilder(), new MorphBuilder(), new VerbatimBuilder()};
50
51 /***
52 * <p>
53 * Uses the {@link BuilderRuleContext} to find the current html
54 * {@link org.apache.shale.clay.parser.Node}. This is the default rule that
55 * will return a {@link VerbatimBuilder} when the node is not a comment or
56 * has a <code>jsfid</code> attribute. When the html node is a
57 * comment, the {@link CommentBuilder} is returned. If the node is not a comment
58 * but has a <code>jsfid</code> attribute, the {@link MorphBuilder} is returned.
59 * </p>
60 *
61 * @param context commons chians
62 * @return <code>true</code> if final
63 * @exception Exception propagated to the top chain
64 */
65 public boolean execute(Context context) throws Exception {
66
67
68 BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
69 Node node = builderRuleContext.getNode();
70 if (node.isComment() || node.isCdata()) {
71 builderRuleContext.setBuilder(BUILDERS[0]);
72 } else if (node.getName() != null && node.getAttributes().containsKey("jsfid")) {
73 builderRuleContext.setBuilder(BUILDERS[1]);
74 } else {
75 builderRuleContext.setBuilder(BUILDERS[2]);
76 }
77
78 return true;
79 }
80
81 }