View Javadoc

1   package org.apache.maven.doxia.module.latex;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Writer;
23  
24  import org.apache.maven.doxia.sink.Sink;
25  import org.apache.maven.doxia.sink.AbstractSinkTest;
26  
27  /**
28   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
29   * @version $Id: LatexSinkTest.java 795033 2009-07-17 10:46:21Z ltheussl $
30   */
31  public class LatexSinkTest
32      extends AbstractSinkTest
33  {
34      /** {@inheritDoc} */
35      protected String outputExtension()
36      {
37          return "tex";
38      }
39  
40      /** {@inheritDoc} */
41      protected Sink createSink( Writer writer )
42      {
43          return new LatexSink( writer );
44      }
45  
46      /** {@inheritDoc} */
47      protected boolean isXmlSink()
48      {
49          return false;
50      }
51  
52      /** {@inheritDoc} */
53      protected String getTitleBlock( String title )
54      {
55          return "\\title{" + LatexSink.escaped( title ) + "}" + EOL;
56      }
57  
58      /** {@inheritDoc} */
59      protected String getAuthorBlock( String author )
60      {
61          return "\\author{" + LatexSink.escaped( author ) + "}" + EOL;
62      }
63  
64      /** {@inheritDoc} */
65      protected String getDateBlock( String date )
66      {
67          return "\\date{" + LatexSink.escaped( date ) + "}" + EOL;
68      }
69  
70      /** {@inheritDoc} */
71      protected String getHeadBlock()
72      {
73          return ( (LatexSink) getSink() ).defaultSinkCommands()
74              + "\\documentclass[a4paper]{article}" + EOL + EOL
75              + ( (LatexSink) getSink() ).defaultPreamble()
76              + "\\begin{document}" + EOL + EOL;
77      }
78  
79      /** {@inheritDoc} */
80      protected String getBodyBlock()
81      {
82          return "\\end{document}" + EOL;
83      }
84  
85      /** {@inheritDoc} */
86      protected String getSectionTitleBlock( String title )
87      {
88          return title;
89      }
90  
91      /** {@inheritDoc} */
92      protected String getSection1Block( String title )
93      {
94          return EOL + "\\section{" + title + "}" + EOL;
95      }
96  
97      /** {@inheritDoc} */
98      protected String getSection2Block( String title )
99      {
100         return EOL + "\\subsection{" + title + "}" + EOL;
101     }
102 
103     /** {@inheritDoc} */
104     protected String getSection3Block( String title )
105     {
106         return EOL + "\\subsubsection{" + title + "}" + EOL;
107     }
108 
109     /** {@inheritDoc} */
110     protected String getSection4Block( String title )
111     {
112         return EOL + "\\paragraph{" + title + "}" + EOL;
113     }
114 
115     /** {@inheritDoc} */
116     protected String getSection5Block( String title )
117     {
118         return EOL + "\\subparagraph{" + title + "}" + EOL;
119     }
120 
121     /** {@inheritDoc} */
122     protected String getListBlock( String item )
123     {
124         return EOL + "\\begin{itemize}" + EOL + "\\item " + LatexSink.escaped( item ) + EOL + "\\end{itemize}" + EOL;
125     }
126 
127     /** {@inheritDoc} */
128     protected String getNumberedListBlock( String item )
129     {
130         return EOL + "\\begin{enumerate}" + EOL + "\\renewcommand{\\theenumi}{\\roman{enumi}}" + EOL + "\\item "
131             + LatexSink.escaped( item ) + EOL + "\\end{enumerate}" + EOL;
132     }
133 
134     /** {@inheritDoc} */
135     protected String getDefinitionListBlock( String definum, String definition )
136     {
137         return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] "
138                 + definition + EOL + "\\end{description}" + EOL;
139     }
140 
141     /** {@inheritDoc} */
142     protected String getFigureBlock( String source, String caption )
143     {
144         return EOL + "\\begin{figure}[htb]" + EOL + "\\begin{center}" + EOL + "\\includegraphics{" + source + "}" + EOL
145             + "\\end{center}" + EOL + "\\caption{Figure\\_caption}" + EOL + "\\end{figure}" + EOL;
146     }
147 
148     /** {@inheritDoc} */
149     protected String getTableBlock( String cell, String caption )
150     {
151         return EOL + "\\begin{table}[htp]" + EOL + "\\begin{center}" + EOL + "\\begin{tabular}{c}" + EOL
152             + "\\begin{tabular}[t]{c}cell\\end{tabular}\\\\" + EOL + "\\end{tabular}" + EOL
153             + "\\end{center}" + EOL + "\\caption{Table\\_caption}" + EOL + "\\end{table}" + EOL;
154     }
155 
156     /** {@inheritDoc} */
157     protected String getParagraphBlock( String text )
158     {
159         return  EOL + EOL + text + EOL;
160     }
161 
162     /** {@inheritDoc} */
163     protected String getVerbatimBlock( String text )
164     {
165         return EOL + "\\begin{small}" + EOL + "\\begin{Verbatim}[frame=single]" + EOL + text + EOL
166             + "\\end{Verbatim}" + EOL + "\\end{small}" + EOL;
167     }
168 
169     /** {@inheritDoc} */
170     protected String getHorizontalRuleBlock()
171     {
172         return EOL + "\\begin{center}\\rule[0.5ex]{\\linewidth}{1pt}\\end{center}" + EOL;
173     }
174 
175     /** {@inheritDoc} */
176     protected String getPageBreakBlock()
177     {
178         return EOL + "\\newpage" + EOL;
179     }
180 
181     /** {@inheritDoc} */
182     protected String getAnchorBlock( String anchor )
183     {
184         return "\\hypertarget{" + anchor + "}{" + anchor + "}";
185     }
186 
187     /** {@inheritDoc} */
188     protected String getLinkBlock( String link, String text )
189     {
190         return "\\hyperlink{" + link + "}{" + text + "}";
191     }
192 
193     /** {@inheritDoc} */
194     protected String getItalicBlock( String text )
195     {
196         return "\\textit{" + text + "}";
197     }
198 
199     /** {@inheritDoc} */
200     protected String getBoldBlock( String text )
201     {
202         return "\\textbf{" + text + "}";
203     }
204 
205     /** {@inheritDoc} */
206     protected String getMonospacedBlock( String text )
207     {
208         return "\\texttt{\\small " + text + "}";
209     }
210 
211     /** {@inheritDoc} */
212     protected String getLineBreakBlock()
213     {
214         return "\\newline" + EOL;
215     }
216 
217     /** {@inheritDoc} */
218     protected String getNonBreakingSpaceBlock()
219     {
220         return "~";
221     }
222 
223     /** {@inheritDoc} */
224     protected String getTextBlock( String text )
225     {
226         // TODO: how to retrieve those outside the sink?
227         return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_],"
228                 + "\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash";
229     }
230 
231     /** {@inheritDoc} */
232     protected String getRawTextBlock( String text )
233     {
234         return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
235     }
236 
237     /** {@inheritDoc} */
238     protected String getCommentBlock( String text )
239     {
240         return EOL + "% Simple comment with ----";
241     }
242 }