KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > doc > DocumentationTagsHandler


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

5 package xdoclet.modules.doc;
6
7 import java.util.*;
8
9 import xdoclet.XDocletException;
10 import xdoclet.XDocletTagSupport;
11 import xdoclet.template.TemplateEngine;
12 import xdoclet.template.TemplateException;
13 import xdoclet.template.TemplateTagHandler;
14
15 /**
16  * @author Ara Abrahamian (ara_e@email.com)
17  * @created Nov 30, 2001
18  * @xdoclet.taghandler namespace="Doc"
19  * @version $Revision: 1.6 $
20  */

21 public class DocumentationTagsHandler extends XDocletTagSupport
22 {
23     private String JavaDoc currentNamespace;
24
25     /**
26      * Iterates over all template namespaces registered in /tagmappings.properties file and evaluates the body of the
27      * tag for each namespace.
28      *
29      * @param template The body of the block tag
30      * @exception XDocletException Description of Exception
31      * @doc.tag type="block"
32      */

33     public void forAllNamespaces(String JavaDoc template) throws XDocletException
34     {
35         for (Iterator iterator = getSortedNameSpaces().iterator(); iterator.hasNext(); ) {
36             currentNamespace = (String JavaDoc) iterator.next();
37
38             try {
39                 TemplateTagHandler th = TemplateEngine.getEngineInstance().getTagHandlerFor(currentNamespace);
40
41                 setCurrentClass(getXJavaDoc().getXClass(th.getClass().getName()));
42
43                 generate(template);
44             }
45             catch (TemplateException e) {
46                 throw new XDocletException(e, "Error getting tag handler");
47             }
48         }
49     }
50
51     /**
52      * Returns current namespace name. Use inside forAllNamespaces only.
53      *
54      * @return Current namespace name
55      * @exception XDocletException Description of Exception
56      * @doc.tag type="content"
57      */

58     public String JavaDoc namespace() throws XDocletException
59     {
60         return currentNamespace;
61     }
62
63     /**
64      * Returns current namespace tags handler class name. Use inside forAllNamespaces only.
65      *
66      * @return Current namespace tags handler class name
67      * @exception XDocletException Description of Exception
68      * @doc.tag type="content"
69      */

70     public String JavaDoc namespaceTagsHandlerClassName() throws XDocletException
71     {
72         try {
73             return TemplateEngine.getEngineInstance().getTagHandlerFor(currentNamespace).getClass().getName();
74         }
75         catch (TemplateException e) {
76             throw new XDocletException(e, "Error getting tag handler for " + currentNamespace);
77         }
78     }
79
80     /**
81      * Returns current namespace name from current class name.
82      *
83      * @return Current namespace tags handler class name
84      * @exception XDocletException Description of Exception
85      * @doc.tag type="content"
86      */

87     public String JavaDoc namespaceFromClassName() throws XDocletException
88     {
89         for (Iterator iterator = getSortedNameSpaces().iterator(); iterator.hasNext(); ) {
90             String JavaDoc tempNamespace = (String JavaDoc) iterator.next();
91
92             try {
93                 if (TemplateEngine.getEngineInstance().getTagHandlerFor(tempNamespace).getClass().getName().equals(getCurrentClass().getQualifiedName())) {
94                     return tempNamespace;
95                 }
96             }
97             catch (TemplateException e) {
98                 throw new XDocletException(e, "Error getting tag handler for" + tempNamespace);
99             }
100         }
101
102         return null;
103     }
104
105     /**
106      * Returns current namespace. Used for tags_toc.xdt.
107      *
108      * @return Current namespace tags handler class name
109      * @exception XDocletException Description of Exception
110      * @doc.tag type="content"
111      */

112     public String JavaDoc currentNamespace() throws XDocletException
113     {
114         return getActiveDocumentTagsSubTask().getCurrentNamespace();
115     }
116
117     /**
118      * Returns current namespace tags handler class name. Used for <namespace> .html files.
119      *
120      * @return Current namespace name
121      * @exception XDocletException Description of Exception
122      * @doc.tag type="content"
123      * @doc.param name="namespace" optional="false" description="The namespace name we lookup the
124      * handler."
125      */

126     public String JavaDoc currentNamespaceTagsHandlerClassName() throws XDocletException
127     {
128         try {
129             return TemplateEngine.getEngineInstance().getTagHandlerFor(getActiveDocumentTagsSubTask().getCurrentNamespace()).getClass().getName();
130         }
131         catch (TemplateException e) {
132             throw new XDocletException(e, "Error getting tag handler for " + getActiveDocumentTagsSubTask().getCurrentNamespace());
133         }
134     }
135
136     /**
137      * Returns current namespace name. Use inside forAllNamespaces only.
138      *
139      * @return Current namespace name
140      * @exception XDocletException Description of Exception
141      * @doc.tag type="content"
142      * @doc.param name="namespace" optional="false" description="The namespace name we lookup the
143      * handler."
144      */

145     public String JavaDoc currentNamespaceTagsHandlerClassNameAsDirStructure() throws XDocletException
146     {
147         return currentNamespaceTagsHandlerClassName().replace('.', '/');
148     }
149
150     private final List getSortedNameSpaces()
151     {
152         ArrayList result = new ArrayList(TemplateEngine.getEngineInstance().getNamespaces());
153
154         Collections.sort(result);
155         return result;
156     }
157
158     /**
159      * Gets the ActiveDocumentTagsSubTask attribute of the DocumentationTagsHandler object.
160      *
161      * @return The ActiveDocumentTagsSubTask value
162      */

163     private DocumentTagsSubTask getActiveDocumentTagsSubTask()
164     {
165         return (DocumentTagsSubTask) getDocletContext().getActiveSubTask();
166     }
167 }
168
Popular Tags