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.Iterator;
24
25 import org.apache.shale.clay.config.beans.AttributeBean;
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>This {@link Builder} is designed to ignore processing on a
32 * block of HTML. If the jsfid attribute of the HTML node is
33 * "ignore", all of the child nodes under the marked nodes are
34 * excluded from further processing. The are treated like a
35 * verbatim block. The outer node is removed from the output.
36 * </p>
37 *
38 */
39 public class IgnoreBuilder extends CommentBuilder {
40
41 /***
42 * <p>Returns the <code>jsfid</code> for the target {@link ElementBean}.</p>
43 *
44 * @param node markup
45 * @return jsfid
46 */
47 protected String getJsfid(Node node) {
48 return "ignore";
49 }
50
51 /***
52 * <p>Builds a outputText component. The attribute value is the content of the
53 * child nodes. The root HTML {@link Node} is not included in the content
54 * of the <code>target</code> {@link ElementBean} node.
55 * </p>
56 *
57 * @param node markup
58 * @param target child config bean
59 * @param root parent config bean
60 */
61 protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
62 StringBuffer value = new StringBuffer();
63 captureComment(node, value);
64
65 AttributeBean attr = new AttributeBean();
66 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
67 attr.setName("value");
68 attr.setValue(value.toString());
69 target.addAttribute(attr);
70
71 attr = new AttributeBean();
72 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
73 attr.setName("escape");
74 attr.setValue(Boolean.FALSE.toString());
75 target.addAttribute(attr);
76
77 attr = new AttributeBean();
78 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
79 attr.setName("isTransient");
80 attr.setValue(Boolean.TRUE.toString());
81 target.addAttribute(attr);
82
83 }
84
85 /***
86 * <p>Recursively traverses the children of the HTML
87 * {@link org.apache.shale.clay.parser.Node} concatenating
88 * the raw text of each {@link org.apache.shale.clay.parser.Token}
89 * into the <code>commentBody</code>. Ending nodes are not kept
90 * with the parser. If a start node is found that is not self
91 * terminated, a matching ending node is created.</p>
92 *
93 * @param node markup
94 * @param commentBody concatenated raw text of all the children
95 */
96 protected void captureComment(Node node, StringBuffer commentBody) {
97 Iterator ni = node.getChildren().iterator();
98 while (ni.hasNext()) {
99 Node child = (Node) ni.next();
100 commentBody.append(child.getToken().getRawText());
101 captureComment(child, commentBody);
102 if (child.isStart() && !child.isEnd() && child.isWellFormed()) {
103 commentBody.append("</").append(child.getName()).append(">");
104 }
105 }
106 }
107
108 }