KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > apache > tapestry > TapestryTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.apache.tapestry;
6
7 import java.util.Collection JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.Properties JavaDoc;
10
11 import org.apache.commons.logging.Log;
12
13 import xjavadoc.XTag;
14
15 import xdoclet.XDocletException;
16 import xdoclet.XDocletTagSupport;
17
18 import xdoclet.util.LogUtil;
19
20 /**
21  * @author Michael Newcomb (mnewcomb@sourceforge.net)
22  * @created February 4, 2005
23  * @version $Revision: 1.1 $
24  * @xdoclet.taghandler namespace="Tapestry"
25  */

26 public class TapestryTagsHandler extends XDocletTagSupport
27 {
28     private XTag currentBean;
29     private XTag currentComponent;
30     private XTag currentContextAsset;
31     private XTag currentExternalAsset;
32     private XTag currentPrivateAsset;
33
34     private XTag currentTag;
35
36     public String JavaDoc currentTagValue(Properties JavaDoc attributes) throws XDocletException
37     {
38         Log log = LogUtil.getLog(TapestryTagsHandler.class,
39             "currentTagValue");
40
41         String JavaDoc attrName = attributes.getProperty("attrName");
42
43         return currentTag.getAttributeValue(attrName);
44     }
45
46     public void forAllComponents(String JavaDoc template) throws XDocletException
47     {
48         Log log = LogUtil.getLog(TapestryTagsHandler.class,
49             "forAllComponents");
50
51         Collection JavaDoc components =
52             getCurrentClass().getDoc().getTags("tapestry:component", true);
53
54         for (Iterator JavaDoc i = components.iterator(); i.hasNext(); ) {
55             currentTag = (XTag) i.next();
56             currentComponent = currentTag;
57
58             generate(template);
59         }
60         currentComponent = null;
61     }
62
63     public void forAllProperties(String JavaDoc template) throws XDocletException
64     {
65         Log log = LogUtil.getLog(TapestryTagsHandler.class,
66             "forAllProperties");
67
68         Collection JavaDoc properties =
69             getCurrentClass().getDoc().getTags("tapestry:property", true);
70
71         for (Iterator JavaDoc i = properties.iterator(); i.hasNext(); ) {
72             currentTag = (XTag) i.next();
73
74             if (currentTag.getAttributeNames().contains("name") &&
75                 currentTag.getAttributeNames().contains("value") &&
76                 currentTag.getAttributeNames().size() == 2) {
77                 generate(template);
78             }
79         }
80     }
81
82     public void forAllComponentItems(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
83     {
84         Log log = LogUtil.getLog(TapestryTagsHandler.class,
85             "forAllComponentItems");
86
87         String JavaDoc tagName = attributes.getProperty("tagName");
88
89         Collection JavaDoc items = getCurrentClass().getDoc().getTags(tagName, true);
90
91         for (Iterator JavaDoc i = items.iterator(); i.hasNext(); ) {
92             currentTag = (XTag) i.next();
93
94             if (currentComponent.getAttributeValue("id").equals(
95                 currentTag.getAttributeValue("component"))) {
96                 generate(template);
97             }
98         }
99     }
100
101     public void forAllBeans(String JavaDoc template) throws XDocletException
102     {
103         Log log = LogUtil.getLog(TapestryTagsHandler.class,
104             "forAllBeans");
105
106         Collection JavaDoc beans =
107             getCurrentClass().getDoc().getTags("tapestry:bean", true);
108
109         for (Iterator JavaDoc i = beans.iterator(); i.hasNext(); ) {
110             currentTag = (XTag) i.next();
111             currentBean = currentTag;
112
113             generate(template);
114         }
115         currentBean = null;
116     }
117
118     public void forAllBeanItems(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
119     {
120         Log log = LogUtil.getLog(TapestryTagsHandler.class,
121             "forAllBeanItems");
122
123         String JavaDoc tagName = attributes.getProperty("tagName");
124
125         Collection JavaDoc items = getCurrentClass().getDoc().getTags(tagName, true);
126
127         for (Iterator JavaDoc i = items.iterator(); i.hasNext(); ) {
128             currentTag = (XTag) i.next();
129
130             if (currentBean.getAttributeValue("name").equals(
131                 currentTag.getAttributeValue("bean"))) {
132                 generate(template);
133             }
134         }
135     }
136
137     public void forAllExternalAssets(String JavaDoc template) throws XDocletException
138     {
139         Log log = LogUtil.getLog(TapestryTagsHandler.class,
140             "forAllExternalAssets");
141
142         Collection JavaDoc externalAssets =
143             getCurrentClass().getDoc().getTags("tapestry:external-asset", true);
144
145         for (Iterator JavaDoc i = externalAssets.iterator(); i.hasNext(); ) {
146             currentTag = (XTag) i.next();
147             currentExternalAsset = currentTag;
148
149             generate(template);
150         }
151         currentExternalAsset = null;
152     }
153
154     public void forAllExternalAssetItems(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
155     {
156         Log log = LogUtil.getLog(TapestryTagsHandler.class,
157             "forAllExternalAssetItems");
158
159         String JavaDoc tagName = attributes.getProperty("tagName");
160
161         Collection JavaDoc items = getCurrentClass().getDoc().getTags(tagName, true);
162
163         for (Iterator JavaDoc i = items.iterator(); i.hasNext(); ) {
164             currentTag = (XTag) i.next();
165
166             if (currentExternalAsset.getAttributeValue("name").equals(
167                 currentTag.getAttributeValue("external-asset"))) {
168                 generate(template);
169             }
170         }
171     }
172
173     public void forAllContextAssets(String JavaDoc template) throws XDocletException
174     {
175         Log log = LogUtil.getLog(TapestryTagsHandler.class,
176             "forAllContextAssets");
177
178         Collection JavaDoc contextAssets =
179             getCurrentClass().getDoc().getTags("tapestry:context-asset", true);
180
181         for (Iterator JavaDoc i = contextAssets.iterator(); i.hasNext(); ) {
182             currentTag = (XTag) i.next();
183             currentContextAsset = currentTag;
184
185             generate(template);
186         }
187         currentContextAsset = null;
188     }
189
190     public void forAllContextAssetItems(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
191     {
192         Log log = LogUtil.getLog(TapestryTagsHandler.class,
193             "forAllContextAssetItems");
194
195         String JavaDoc tagName = attributes.getProperty("tagName");
196
197         Collection JavaDoc items = getCurrentClass().getDoc().getTags(tagName, true);
198
199         for (Iterator JavaDoc i = items.iterator(); i.hasNext(); ) {
200             currentTag = (XTag) i.next();
201
202             if (currentContextAsset.getAttributeValue("name").equals(
203                 currentTag.getAttributeValue("context-asset"))) {
204                 generate(template);
205             }
206         }
207     }
208
209     public void forAllPrivateAssets(String JavaDoc template) throws XDocletException
210     {
211         Log log = LogUtil.getLog(TapestryTagsHandler.class,
212             "forAllPrivateAssets");
213
214         Collection JavaDoc privateAssets =
215             getCurrentClass().getDoc().getTags("tapestry:private-asset", true);
216
217         for (Iterator JavaDoc i = privateAssets.iterator(); i.hasNext(); ) {
218             currentTag = (XTag) i.next();
219             currentPrivateAsset = currentTag;
220
221             generate(template);
222         }
223         currentPrivateAsset = null;
224     }
225
226     public void forAllPrivateAssetItems(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
227     {
228         Log log = LogUtil.getLog(TapestryTagsHandler.class,
229             "forAllPrivateAssetItems");
230
231         String JavaDoc tagName = attributes.getProperty("tagName");
232
233         Collection JavaDoc items = getCurrentClass().getDoc().getTags(tagName, true);
234
235         for (Iterator JavaDoc i = items.iterator(); i.hasNext(); ) {
236             currentTag = (XTag) i.next();
237
238             if (currentPrivateAsset.getAttributeValue("name").equals(
239                 currentTag.getAttributeValue("private-asset"))) {
240                 generate(template);
241             }
242         }
243     }
244
245     public void forAllPropertySpecifications(String JavaDoc template) throws XDocletException
246     {
247         Log log = LogUtil.getLog(TapestryTagsHandler.class,
248             "forAllPropertySpecifications");
249
250         Collection JavaDoc propertySpecifications =
251             getCurrentClass().getDoc().getTags(
252             "tapestry:property-specification", true);
253
254         for (Iterator JavaDoc i = propertySpecifications.iterator(); i.hasNext(); ) {
255             currentTag = (XTag) i.next();
256
257             generate(template);
258         }
259     }
260
261     public void forAllParameters(String JavaDoc template) throws XDocletException
262     {
263         Log log = LogUtil.getLog(TapestryTagsHandler.class,
264             "forAllParameters");
265
266         Collection JavaDoc parameters =
267             getCurrentClass().getDoc().getTags("tapestry:parameter", true);
268
269         for (Iterator JavaDoc i = parameters.iterator(); i.hasNext(); ) {
270             currentTag = (XTag) i.next();
271
272             generate(template);
273         }
274     }
275
276     public void forAllReservedParameters(String JavaDoc template) throws XDocletException
277     {
278         Log log = LogUtil.getLog(TapestryTagsHandler.class,
279             "forAllReservedParameters");
280
281         Collection JavaDoc parameters =
282             getCurrentClass().getDoc().getTags(
283             "tapestry:reserved-parameter", true);
284
285         for (Iterator JavaDoc i = parameters.iterator(); i.hasNext(); ) {
286             currentTag = (XTag) i.next();
287
288             generate(template);
289         }
290     }
291
292     public void ifCurrentTagHasAttribute(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
293     {
294         if (currentTagValue(attributes) != null) {
295             generate(template);
296         }
297     }
298 }
299
Popular Tags