KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > AshkelonTagResolver


1 /*
2  * Created on Jul 24, 2004
3  */

4 package org.ashkelon;
5
6 import org.ashkelon.util.Logger;
7 import org.ashkelon.util.StringUtils;
8 import com.sun.javadoc.SeeTag;
9 import com.sun.javadoc.Tag;
10
11 /**
12  * @author Eitan Suez
13  */

14 public class AshkelonTagResolver implements InlineTagResolver
15 {
16    public AshkelonTagResolver() {}
17
18    /**
19     * resolves all inline tags in a description into html links
20     * @param tags text represented as an array of tags, as returned by doc.inlineTags()
21     * @return resolved text
22     */

23    public String JavaDoc resolveDescription(DocInfo sourcedoc, Tag[] tags)
24    {
25       Logger log = Logger.getInstance();
26       
27       StringBuffer JavaDoc text = new StringBuffer JavaDoc("");
28       for (int i=0; i<tags.length; i++)
29       {
30          log.debug("tag 'kind': "+tags[i].kind());
31          
32          // thanks Matt for catching this:
33
if ("@return".equals(tags[i].kind()) && (tags[i].inlineTags() != null && tags[i].inlineTags().length > 0))
34          {
35              return resolveDescription(sourcedoc, tags[i].inlineTags());
36          }
37
38          if ("@see".equals(tags[i].kind())) // javadoc docs say 'link' - liars
39
{
40             Reference ref = new Reference(sourcedoc, (SeeTag) tags[i]);
41             String JavaDoc cmd = "";
42             if (ref.getRefDocType() == DocInfo.PACKAGE_TYPE)
43             {
44                cmd = "pkg";
45             }
46             else if (ref.getRefDocType() == DocInfo.CLASS_TYPE)
47             {
48                cmd = "cls";
49             }
50             else if (ref.getRefDocType() == DocInfo.MEMBER_TYPE || ref.getRefDocType() == DocInfo.EXECMEMBER_TYPE)
51             {
52                cmd = "member";
53                String JavaDoc name = ref.getRefDocName();
54                int idx = name.indexOf("(");
55                if (idx > 0)
56                   name = name.substring(0, idx);
57                ref.setRefDocName(name);
58             }
59             String JavaDoc var = cmd + "_name";
60             String JavaDoc value = ref.getRefDocName();
61             String JavaDoc label = ref.getLabel();
62             if (StringUtils.isBlank(label))
63             {
64                label = ref.getRefDocName();
65             }
66             
67             // <a HREF="{cmd}.main.do?{var}=$value">$caption</a>
68
text.append("<a HREF=\"").append(cmd).append(".main.do?");
69             text.append(var).append("=").append(value).append("\">");
70             text.append(label).append("</a>");
71             
72             //log.debug("Resolved inline tag: "+text);
73
}
74          else // otherwise usually will be kind 'Text'
75
{
76             //log.debug("Tag text: "+tags[i].text());
77
text.append(tags[i].text());
78          }
79          text.append(" ");
80       }
81       return text.toString().trim();
82    }
83 }
84
Popular Tags