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 /***
24 * <p>
25 * This is a <code>Command</code> implementation that will
26 * match a HTML {@link Node} with a matching {@link Builder}
27 * implementation. If the html node is an anchored tag, a
28 * {@link OutputLinkBuilder} will be returned and the
29 * chain terminated. The {@link BuilderFactory} runs this
30 * command rule as part of the <code>Globals.BUILDER_CATALOG_NAME</code>
31 * found in the <code>Globals.BUILDER_RESOURCE_NAME</code> and
32 * invoking the <code>Globals.FIND_BUILDER_COMMAND_NAME</code>
33 * </p>
34 */
35 import org.apache.commons.chain.Command;
36 import org.apache.commons.chain.Context;
37 import org.apache.shale.clay.parser.Node;
38 import org.apache.shale.clay.parser.builder.Builder;
39 import org.apache.shale.clay.parser.builder.OutputLinkBuilder;
40
41 /***
42 *
43 *
44 */
45 public class AnchorBuilderRule implements Command {
46
47 /***
48 * <p>
49 * Static instance of the builder.
50 * </p>
51 */
52 private static final Builder BUILDER = new OutputLinkBuilder();
53
54 /***
55 * <p>
56 * Uses the {@link BuilderRuleContext} to find the current html {@link Node}.
57 * If the node is an anchored element, return an instance if the builder and
58 * stop the chain.
59 * </p>
60 *
61 * @param context commons chains
62 * @return <code>true</code> if is final
63 * @exception Exception throws back to the top of the chain
64 */
65 public boolean execute(Context context) throws Exception {
66
67 boolean isFinal = false;
68
69 BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
70 Node node = builderRuleContext.getNode();
71 if (!node.isComment() && node.getName() != null
72 && node.getName().equalsIgnoreCase("a")) {
73 builderRuleContext.setBuilder(BUILDER);
74 isFinal = true;
75
76 }
77
78 return isFinal;
79 }
80
81 }