View Javadoc

1   /*
2    * Copyright (C) Stephan Dlugosz, 2007. All Rights Reserved.
3    *
4    * LaTeXTaglet is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser Public License as published by
6    * the Free Software Foundation; either version 2.1 of the License, or
7    * (at your option) any later version.
8    *
9    * LaTeXTaglet is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   * GNU Lesser Public License for more details.
13   * 
14   * You should have received a copy of the GNU Lesser Public License
15   * along with LaTeXTaglet; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   */
18  
19  package net.sf.latextaglet;
20  import java.util.Map;
21  
22  import net.sf.latextaglet.internal.LaTeXTaglet;
23  
24  import com.sun.javadoc.Doc;
25  import com.sun.javadoc.Tag;
26  import com.sun.tools.doclets.Taglet;
27  import com.sun.tools.doclets.internal.toolkit.Configuration;
28  import com.sun.tools.doclets.internal.toolkit.taglets.TagletOutput;
29  import com.sun.tools.doclets.internal.toolkit.taglets.TagletWriter;
30  
31  /**
32   * Taglet class for inline style formulae<br>
33   * 
34   * Usage: {&#064;latex$ \sum_i x_i }<br>
35   * 
36   * Examples: {@latex$ \sum_i x_i } and {@latex$ \int_0^1 x dx }
37   * 
38   * @author Stephan Dlugosz
39   */
40  public class LaTeXInlineTaglet extends LaTeXTaglet {
41  	/**
42       * 
43       */
44      static String NAME="latex$"; //$NON-NLS-1$
45  	
46      /**
47       * Return the name of this custom tag.
48       * @return Name
49       */
50      public String getName() {
51          return NAME;
52      }
53      
54      /**
55       * @see stephan.LaTeXTaglet#isInlineTag()
56       */
57      public boolean isInlineTag() {
58          return true;
59      }
60  
61  	/**
62       * Register this Taglet.
63       * @param tagletMap  the map to register this tag to.
64       */
65  	@SuppressWarnings("unchecked")
66  	public static void register(Map tagletMap) {
67         LaTeXInlineTaglet tag = new LaTeXInlineTaglet();
68         Taglet t = (Taglet) tagletMap.get(tag.getName());
69         if (t != null) {
70             tagletMap.remove(tag.getName());
71         }
72         tagletMap.put(tag.getName(), tag);
73      }
74  	
75      /**
76       * @param tag
77       * @param conf
78       * @return String that is printed in the corresponding html file
79       */
80      public String toString(Tag tag, Configuration conf) {
81          String name = null;
82  	
83      	name = createPicture(tag,conf,false);
84          return "<img src=\""+name+"\" alt=\""+tag.text()+"\" class=\"math-display\">";  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
85      }
86      
87      
88      /**
89       * @param tags
90       * @param conf
91       * @return String that is printed in the corresponding html file 
92       */
93      public String toString(Tag[] tags, Configuration conf) {
94          if (tags.length == 0) {
95              return null;
96          }
97          return toString(tags[0],conf);
98      }
99      
100     public TagletOutput getTagletOutput(Tag arg0, TagletWriter arg1) throws IllegalArgumentException {
101         TagletOutput ret = arg1.getOutputInstance();
102         ret.setOutput(toString(arg0, arg1.configuration()));
103         return ret;
104     }
105 
106     public TagletOutput getTagletOutput(Doc arg0, TagletWriter arg1) throws IllegalArgumentException {
107         TagletOutput ret = arg1.getOutputInstance();
108         ret.setOutput(toString(arg0.tags(getName()), arg1.configuration()));
109         return ret;
110     }
111 }