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.struts.tiles.taglib;
24
25 import java.util.Iterator;
26
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.PageContext;
29 import javax.servlet.jsp.tagext.TagSupport;
30
31 import org.apache.struts.tiles.taglib.util.TagUtils;
32 import org.apache.struts.tiles.ComponentContext;
33
34
35
36
37
38
39
40
41 public class ImportAttributeTag extends TagSupport {
42
43
44
45
46 private String name = null;
47
48
49
50
51
52 private String scopeName = null;
53
54
55
56
57 private int scope = PageContext.PAGE_SCOPE;
58
59
60
61
62
63
64 protected boolean isErrorIgnored = false;
65
66
67
68
69
70 public void release() {
71
72 super.release();
73 name = null;
74 scopeName = null;
75 scope = PageContext.PAGE_SCOPE;
76 isErrorIgnored = false;
77 }
78
79
80
81
82
83 public String getName()
84 {
85 return (this.name);
86 }
87
88
89
90
91
92
93 public void setName(String name)
94 {
95 this.name = name;
96 }
97
98
99
100
101
102 public void setScope(String scope)
103 {
104 this.scopeName = scope;
105 }
106
107
108
109
110
111 public String getScope()
112 {
113 return scopeName;
114 }
115
116
117
118
119
120
121
122 public void setIgnore(boolean ignore)
123 {
124 this.isErrorIgnored = ignore;
125 }
126
127
128
129
130
131
132
133 public boolean getIgnore()
134 {
135 return isErrorIgnored;
136 }
137
138
139
140
141
142
143
144
145
146 public int doStartTag() throws JspException
147 {
148
149 ComponentContext compContext =
150 (ComponentContext)pageContext.getAttribute(
151 ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
152 if( compContext == null )
153 throw new JspException ( "Error - tag importAttribute : "
154 + "no tiles context found." );
155
156
157 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
158
159
160 if( name != null )
161 {
162 Object value = compContext.getAttribute(name);
163
164 if( value == null )
165 {
166 if(!isErrorIgnored)
167 {
168 throw new JspException ( "Error - tag importAttribute : property '"+
169 name + "' not found in context. Check tag syntax" );
170 }
171 }
172 else
173 {
174 pageContext.setAttribute(name, value, scope);
175 }
176 }
177 else
178 {
179 Iterator names = compContext.getAttributeNames();
180 while(names.hasNext())
181 {
182 String name = (String)names.next();
183 if(name == null ) {
184 if(!isErrorIgnored)
185 throw new JspException ( "Error - tag importAttribute : "
186 + "encountered an attribute with key 'null'" );
187 else
188 return SKIP_BODY;
189 }
190
191 Object value = compContext.getAttribute(name);
192
193 if( value == null ) {
194 if(!isErrorIgnored) {
195 throw new JspException ( "Error - tag importAttribute : property '"
196 + name + "' has a value of 'null'" );
197 }
198 }
199 pageContext.setAttribute(name, value, scope);
200 }
201 }
202
203
204 return SKIP_BODY;
205 }
206
207
208
209
210
211
212 public int doEndTag() throws JspException
213 {
214 return (EVAL_PAGE);
215 }
216
217 }