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 org.apache.shale.clay.config.beans.AttributeBean;
24 import org.apache.shale.clay.config.beans.ComponentBean;
25 import org.apache.shale.clay.config.beans.ElementBean;
26 import org.apache.shale.clay.parser.Node;
27
28
29 /***
30 * <p>
31 * This is the default {@link Builder} that will create a {@link ElementBean}
32 * having characteristics like the JSP verbatim tag. All html elements that are
33 * not mapped to a specific {@link Builder} will be handled by the
34 * {@link org.apache.shale.clay.parser.builder.chain.DefaultBuilderRule}.
35 * </p>
36 */
37 public class VerbatimBuilder extends Builder {
38
39 /***
40 * <p>
41 * Returns the <code>jsfid</code> for the target {@link ElementBean}.
42 * </p>
43 *
44 * @param node markup
45 * @return jsfid
46 */
47 protected String getJsfid(Node node) {
48 return "f:verbatim";
49 }
50
51 /***
52 * <p>
53 * Calls to the super implementation to populate the target
54 * {@link ElementBean} and then sets the value attribute to the raw text of
55 * the html node. Set the <code>escape</code> attribute to
56 * <code>false</code> so that the special html characters will not be
57 * excaped
58 * </p>
59 *
60 * @param node markup
61 * @param target child
62 * @param root parent
63 */
64 protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
65 String value = node.getToken().getRawText();
66
67 AttributeBean attr = new AttributeBean();
68 attr.setBindingType(AttributeBean.BINDING_TYPE_VALUE);
69 attr.setName("value");
70 attr.setValue(value.toString());
71 target.addAttribute(attr);
72
73 attr = new AttributeBean();
74 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
75 attr.setName("escape");
76 attr.setValue(Boolean.FALSE.toString());
77 target.addAttribute(attr);
78
79 attr = new AttributeBean();
80 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
81 attr.setName("isTransient");
82 attr.setValue(Boolean.TRUE.toString());
83 target.addAttribute(attr);
84
85 }
86
87 /***
88 * <p>
89 * Returns a JSF component type of <code>javax.faces.HtmlOutputText</code>.
90 * </p>
91 *
92 * @param node markup
93 * @return component type
94 */
95 protected String getComponentType(Node node) {
96 return "javax.faces.HtmlOutputText";
97 }
98
99 /***
100 * <p>
101 * If the html node is well-formed, the create a ending html tag using
102 * another verbatim {@link org.apache.shale.clay.config.beans.ElementBean}.
103 * Set the <code>escape</code> attribute to <code>false</code> so that
104 * the special html characters will not be escaped
105 * </p>
106 *
107 * @param node markup
108 * @param target child
109 * @param root parent
110 */
111 protected void encodeEnd(Node node, ElementBean target, ComponentBean root) {
112
113
114
115 if (node.isStart() && !node.isEnd() && node.isWellFormed()) {
116
117 ElementBean endTarget = createElement(node);
118 root.addChild(endTarget);
119
120 StringBuffer tmp = new StringBuffer();
121 tmp.append("</").append(node.getName()).append(">");
122
123 AttributeBean attr = new AttributeBean();
124 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
125 attr.setName("value");
126 attr.setValue(tmp.toString());
127 endTarget.addAttribute(attr);
128
129 attr = new AttributeBean();
130 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
131 attr.setName("escape");
132 attr.setValue(Boolean.FALSE.toString());
133 endTarget.addAttribute(attr);
134
135 attr = new AttributeBean();
136 attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
137 attr.setName("isTransient");
138 attr.setValue(Boolean.TRUE.toString());
139 endTarget.addAttribute(attr);
140
141 }
142 }
143
144 /***
145 * <p>Skip the processing of attributes for a verbatim node. This
146 * was a bug uncovered with JSF RI 1.2. The <code>TextRenderer</code>
147 * is sensitive to pass thru attributes. If it finds a pass thru
148 * attribute, it wraps the text in a HTML span tag.</p>
149 *
150 * @param node markup node
151 * @param target config bean built for the markup node
152 */
153 protected void assignAttributes(Node node, ComponentBean target) {
154
155 }
156 }