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.taglib;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.webapp.UIComponentTag;
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import org.apache.shale.clay.component.Clay;
29 import org.apache.shale.clay.config.beans.SymbolBean;
30 import org.apache.shale.util.Messages;
31
32 /***
33 * <p>This Tag is used to add replacement symbols to the {@link Clay} component.
34 * Replacement symbols are substituted within the meta-data used to build the subtree
35 * under the Clay component. This tag is similar to the standard JSF attribute tag.
36 * The <code>name</code> attribute will be prepended with an '@' character.
37 * The "at" character is the symbol identifier.</p>
38 */
39 public class SymbolTag extends TagSupport {
40
41 /***
42 * <p>Unique id used by the <code>Serializable</code> interface.</p>
43 */
44 private static final long serialVersionUID = 3977021747121698357L;
45
46 /***
47 * <p>Message resources for this class.</p>
48 */
49 private static Messages messages = new Messages(
50 "org.apache.shale.clay.Bundle", SymbolTag.class.getClassLoader());
51
52 /***
53 * <p>The <code>name</code> of the symbol.</p>
54 */
55 private String name = null;
56
57 /***
58 * <p>The <code>value</code> of the symbol.</p>
59 */
60 private String value = null;
61
62 /***
63 * <p>Returns the name of the symbol.</p>
64 *
65 * @return name of the symbol
66 */
67 public String getName() {
68 return name;
69 }
70
71 /***
72 * <p>Sets the <code>name</code> of the symbol.</p>
73 *
74 * @param name of the symbol
75 */
76 public void setName(String name) {
77 this.name = name;
78 }
79
80 /***
81 * <p>Returns the value for the symbol.</p>
82 *
83 * @return value of the symbol
84 */
85 public String getValue() {
86 return value;
87 }
88
89 /***
90 * <p>Sets the <code>value</code> for the symbol.</p>
91 *
92 * @param value of the symbol
93 */
94 public void setValue(String value) {
95 this.value = value;
96 }
97
98 /***
99 * <p>Finds the parent component and adds the symbol to the
100 * Clay component's symbol table. The parent has to be a {@link Clay} component.
101 * </p>
102 *
103 * @return next transition
104 * @exception JspException general JSP tag
105 */
106 public int doStartTag() throws JspException {
107 UIComponentTag parentTag = UIComponentTag.getParentUIComponentTag(pageContext);
108 if (parentTag == null) {
109 throw new JspException(messages.getMessage("clayparent.notfound"));
110 }
111
112 UIComponent parentComponent = parentTag.getComponentInstance();
113 if (parentComponent == null) {
114 throw new JspException(messages.getMessage("clayparent.notfound"));
115 }
116
117 if (!(parentComponent instanceof Clay)) {
118 throw new JspException(messages.getMessage("clayparent.notfound"));
119 }
120
121 Clay clayParent = (Clay) parentComponent;
122
123 StringBuffer tmp = new StringBuffer(name);
124 if (tmp.charAt(0) != '@') {
125 tmp.insert(0, '@');
126 }
127 SymbolBean symbol = new SymbolBean();
128 symbol.setName(tmp.toString());
129 symbol.setValue(value);
130 clayParent.getSymbols().put(symbol.getName(), symbol);
131
132 return super.doStartTag();
133 }
134
135 }