001    package hirondelle.web4jtools.taglet;
002    
003    import com.sun.tools.doclets.Taglet;    
004    import com.sun.javadoc.*;               
005    import java.util.Map;
006    import static hirondelle.web4j.util.Consts.NEW_LINE;
007    import hirondelle.web4j.util.Util;
008    
009    /**
010    * Taglet for linking to <tt>.jsp</tt> files.
011    *
012    * <P>The <tt>.jsp</tt> files need to be copied into the javadoc tree. 
013    * The typical use case is to place the <tt>.jsp</tt> file in the same 
014    * directory as the class that references it. 
015    * 
016    * <P>Example use case :<br>
017    * <tt>&ampview view.jsp</tt>
018    */
019    public final class ViewTaglet implements Taglet {
020      
021      /** Register this taglet with the javadoc tool, under the taglet name 'view'.  */
022      public static void register(Map aTagletMap){
023        if ( aTagletMap.get(TAGLET_NAME) != null ) {
024          aTagletMap.remove(TAGLET_NAME);
025        }
026        aTagletMap.put(TAGLET_NAME, new ViewTaglet());
027      }
028      
029      /** Return 'view'. */
030      public String getName() {
031        return TAGLET_NAME;
032      }
033    
034      /** Return <tt>false</tt>. */
035      public boolean isInlineTag() {
036        return false;
037      }
038      
039      /** Return <tt>false</tt>. */
040      public boolean inOverview() {
041        return false;
042      }
043      
044      /** Return <tt>false</tt>. */
045      public boolean inPackage() {
046        return false;
047      }
048      
049      /** Return <tt>true</tt>. */
050      public boolean inType() {
051        return true;
052      }
053      
054      /** Return <tt>false</tt>. */
055      public boolean inConstructor() {
056        return false;
057      }
058      
059      /** Return <tt>false</tt>. */
060      public boolean inMethod() {
061        return false;
062      }
063      
064      /** Return <tt>false</tt>. */
065      public boolean inField() {
066        return false;
067      }
068      
069      /** Render a series of <tt>&amp;view</tt> items.  */
070      public String toString(Tag[] aTags) {
071        StringBuilder result = new StringBuilder();
072        if ( aTags.length != 0 ) {
073          result.append(TAGLET_HEADER);
074          result.append(NEW_LINE );
075          result.append("<ul>" + NEW_LINE);
076          for(Tag tag: aTags){
077            if( Util.textHasContent(tag.text()) ) {
078              result.append("<li>" + getLink(tag) + NEW_LINE);
079            }
080          }
081          result.append("</ul>" + NEW_LINE);
082        }
083        return result.toString();
084      }
085      
086      /** Render a single <tt>&amp;view</tt> item.  */
087      public String toString(Tag aTag) {
088        String result = "";
089        if( Util.textHasContent(aTag.text()) )  {
090          result = TAGLET_HEADER + getLink(aTag) + NEW_LINE;
091        }
092        return result;
093      }
094      
095      // PRIVATE //
096      private static final String TAGLET_NAME = "view";
097      private static final String TAGLET_HEADER = "<b>View :</b> ";
098      
099      private String getLink(Tag aTag){
100        return "<a href='" + aTag.text() +  ".txt'><tt>" + aTag.text() + "</tt></a>";
101      }
102    }