1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.tiles.jsp.taglib;
24
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.TagData;
27 import javax.servlet.jsp.tagext.TagExtraInfo;
28 import javax.servlet.jsp.tagext.VariableInfo;
29
30
31 /***
32 * Exposes am attribute as a scripting variable within the page.
33 *
34 * @since Tiles 1.0
35 * @version $Rev: 727715 $ $Date: 2008-12-18 14:06:06 +0100 (Thu, 18 Dec 2008) $
36 */
37 public class UseAttributeTag extends AttributeTagSupport {
38
39 /***
40 * Class name of object.
41 */
42 private String classname = null;
43
44 /***
45 * Get class name.
46 *
47 * @return class name
48 */
49 public String getClassname() {
50 return classname;
51
52 }
53
54 /***
55 * Set the class name.
56 *
57 * @param name The new class name.
58 */
59 public void setClassname(String name) {
60 this.classname = name;
61 }
62
63 /*** {@inheritDoc} */
64 protected void reset() {
65 super.reset();
66 classname = null;
67 id = null;
68 }
69
70 /***
71 * Expose the requested attribute from attribute context.
72 *
73 * @throws JspException if a JSP exception has occurred
74 */
75 public void execute() throws JspException {
76 pageContext.setAttribute(getScriptingVariable(), attribute.getValue(), scope);
77 }
78
79 /***
80 * Returns the scripting variable to use.
81 *
82 * @return The scripting variable.
83 */
84 public String getScriptingVariable() {
85 return id == null ? getName() : id;
86 }
87
88
89 /***
90 * Implementation of <code>TagExtraInfo</code> which identifies
91 * the scripting object(s) to be made visible.
92 */
93 public static class Tei extends TagExtraInfo {
94
95 /*** {@inheritDoc} */
96 public VariableInfo[] getVariableInfo(TagData data) {
97 String classname = data.getAttributeString("classname");
98 if (classname == null) {
99 classname = "java.lang.Object";
100 }
101
102 String id = data.getAttributeString("id");
103 if (id == null) {
104 id = data.getAttributeString("name");
105 }
106
107 return new VariableInfo[] {
108 new VariableInfo(id, classname, true, VariableInfo.AT_END)
109 };
110
111 }
112 }
113 }