1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.tiles.taglib;
23
24 import javax.servlet.jsp.JspException;
25 import javax.servlet.jsp.PageContext;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import org.apache.struts.tiles.taglib.util.TagUtils;
29 import org.apache.struts.tiles.ComponentContext;
30
31
32
33
34
35
36 public final class AttributeToScopeTag extends TagSupport {
37
38
39
40
41
42
43
44
45 private String scopeName = null;
46
47
48
49
50 private int scope = PageContext.PAGE_SCOPE;
51
52
53
54
55
56
57 private String property = null;
58
59
60
61
62
63
64
65
66
67 public String getProperty()
68 {
69 return (this.property);
70 }
71
72
73
74
75
76
77
78 public void setProperty(String property)
79 {
80 this.property = property;
81 }
82
83
84
85
86
87
88 public void setScope(String scope)
89 {
90 this.scopeName = scope;
91 }
92
93
94
95
96
97
98
99
100
101 public int doStartTag() throws JspException
102 {
103 if( id==null )
104 id=property;
105
106 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
107
108 if( compContext == null )
109 throw new JspException ( "Error - tag.useProperty : component context is not defined. Check tag syntax" );
110
111 Object value = compContext.getAttribute(property);
112 if( value == null )
113 throw new JspException ( "Error - tag.useProperty : property '"+ property + "' not found in context. Check tag syntax" );
114
115 if( scopeName != null )
116 {
117 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
118 pageContext.setAttribute(id, value, scope);
119 }
120 else
121 pageContext.setAttribute(id, value);
122
123
124 return SKIP_BODY;
125 }
126
127
128
129
130
131
132
133
134
135 public int doEndTag() throws JspException
136 {
137 return (EVAL_PAGE);
138 }
139
140
141
142
143 public void release() {
144
145 super.release();
146 property = null;
147 scopeName = null;
148 scope = PageContext.PAGE_SCOPE;
149 }
150
151 }