View Javadoc
1   package org.apache.maven.doxia.module.apt;
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.markup.Markup;
25  import org.apache.maven.doxia.sink.Sink;
26  import org.apache.maven.doxia.sink.impl.AbstractSinkTest;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  /**
30   * Test the <code>AptSink</code> class
31   *
32   * @see AptSink
33   */
34  public class AptSinkTest extends AbstractSinkTest
35  {
36      /** {@inheritDoc} */
37      protected String outputExtension()
38      {
39          return "apt";
40      }
41  
42      /** {@inheritDoc} */
43      protected Sink createSink( Writer writer )
44      {
45          return new AptSink( writer );
46      }
47  
48      /** {@inheritDoc} */
49      protected boolean isXmlSink()
50      {
51          return false;
52      }
53  
54      /** {@inheritDoc} */
55      protected String getTitleBlock( String title )
56      {
57          return title;
58      }
59  
60      /** {@inheritDoc} */
61      protected String getAuthorBlock( String author )
62      {
63          return author;
64      }
65  
66      /** {@inheritDoc} */
67      protected String getDateBlock( String date )
68      {
69          return date;
70      }
71  
72      /** {@inheritDoc} */
73      protected String getHeadBlock()
74      {
75          return AptMarkup.HEADER_START_MARKUP + EOL + AptMarkup.HEADER_START_MARKUP + EOL + AptMarkup.HEADER_START_MARKUP
76               + EOL + AptMarkup.HEADER_START_MARKUP + EOL;
77      }
78  
79      /** {@inheritDoc} */
80      protected String getBodyBlock()
81      {
82          return "";
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 + title + EOL + EOL + EOL;
95      }
96  
97      /** {@inheritDoc} */
98      protected String getSection2Block( String title )
99      {
100         return EOL + AptMarkup.SECTION_TITLE_START_MARKUP + title + EOL + EOL + EOL;
101     }
102 
103     /** {@inheritDoc} */
104     protected String getSection3Block( String title )
105     {
106         return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 2 )
107                 + title + EOL + EOL + EOL;
108     }
109 
110     /** {@inheritDoc} */
111     protected String getSection4Block( String title )
112     {
113         return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 3 )
114                 + title + EOL + EOL + EOL;
115     }
116 
117     /** {@inheritDoc} */
118     protected String getSection5Block( String title )
119     {
120         return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 4 )
121                 + title + EOL + EOL + EOL;
122     }
123 
124     /** {@inheritDoc} */
125     protected String getListBlock( String item )
126     {
127         return EOL + EOL + Markup.SPACE + "" + AptMarkup.LIST_START_MARKUP + "" + Markup.SPACE + item + EOL + EOL
128             + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL;
129     }
130 
131     /** {@inheritDoc} */
132     protected String getNumberedListBlock( String item )
133     {
134         return EOL + EOL + Markup.SPACE + "" + Markup.LEFT_SQUARE_BRACKET + ""
135             + Markup.LEFT_SQUARE_BRACKET + AptMarkup.NUMBERING_LOWER_ROMAN_CHAR + ""
136             + Markup.RIGHT_SQUARE_BRACKET + "" + Markup.RIGHT_SQUARE_BRACKET
137             + Markup.SPACE + item + EOL + EOL + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL;
138     }
139 
140     /** {@inheritDoc} */
141     protected String getDefinitionListBlock( String definum, String definition )
142     {
143         return EOL + EOL + Markup.SPACE + "" + Markup.LEFT_SQUARE_BRACKET + definum
144             + Markup.RIGHT_SQUARE_BRACKET + "" + Markup.SPACE + definition + EOL + EOL
145             + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL;
146     }
147 
148     /** {@inheritDoc} */
149     protected String getFigureBlock( String source, String caption )
150     {
151        String figureBlock = EOL + Markup.LEFT_SQUARE_BRACKET + source + Markup.RIGHT_SQUARE_BRACKET + Markup.SPACE;
152        if( caption != null )
153        {
154            figureBlock += caption + EOL;
155        }
156        return figureBlock;
157     }
158 
159     /** {@inheritDoc} */
160     protected String getTableBlock( String cell, String caption )
161     {
162         return EOL + AptMarkup.TABLE_ROW_START_MARKUP + AptMarkup.TABLE_COL_CENTERED_ALIGNED_MARKUP + EOL + cell
163             + AptMarkup.TABLE_ROW_SEPARATOR_MARKUP + EOL + AptMarkup.TABLE_ROW_START_MARKUP
164             + AptMarkup.TABLE_COL_CENTERED_ALIGNED_MARKUP + EOL + caption + EOL;
165     }
166 
167     /** {@inheritDoc} */
168     protected String getParagraphBlock( String text )
169     {
170         return EOL + Markup.SPACE + text + EOL + EOL;
171     }
172 
173     /** {@inheritDoc} */
174     protected String getVerbatimBlock( String text )
175     {
176         return EOL + EOL + AptMarkup.BOXED_VERBATIM_START_MARKUP + EOL + text + EOL
177             + AptMarkup.BOXED_VERBATIM_START_MARKUP + EOL;
178     }
179 
180     /** {@inheritDoc} */
181     protected String getHorizontalRuleBlock()
182     {
183         return EOL + AptMarkup.HORIZONTAL_RULE_MARKUP + EOL;
184     }
185 
186     /** {@inheritDoc} */
187     protected String getPageBreakBlock()
188     {
189         return EOL + AptMarkup.PAGE_BREAK_MARKUP + EOL;
190     }
191 
192     /** {@inheritDoc} */
193     protected String getAnchorBlock( String anchor )
194     {
195         return AptMarkup.ANCHOR_START_MARKUP + anchor + AptMarkup.ANCHOR_END_MARKUP;
196     }
197 
198     /** {@inheritDoc} */
199     protected String getLinkBlock( String link, String text )
200     {
201         String lnk = link.startsWith( "#" ) ? link.substring( 1 ) : link;
202         return AptMarkup.LINK_START_1_MARKUP + lnk + AptMarkup.LINK_START_2_MARKUP + text + AptMarkup.LINK_END_MARKUP;
203     }
204 
205     /** {@inheritDoc} */
206     protected String getItalicBlock( String text )
207     {
208         return AptMarkup.ITALIC_START_MARKUP + text + AptMarkup.ITALIC_END_MARKUP;
209     }
210 
211     /** {@inheritDoc} */
212     protected String getBoldBlock( String text )
213     {
214         return AptMarkup.BOLD_START_MARKUP + text + AptMarkup.BOLD_END_MARKUP;
215     }
216 
217     /** {@inheritDoc} */
218     protected String getMonospacedBlock( String text )
219     {
220         return AptMarkup.MONOSPACED_START_MARKUP + text + AptMarkup.MONOSPACED_END_MARKUP;
221     }
222 
223     /** {@inheritDoc} */
224     protected String getLineBreakBlock()
225     {
226         return String.valueOf( AptMarkup.BACKSLASH ) + EOL;
227     }
228 
229     /** {@inheritDoc} */
230     protected String getNonBreakingSpaceBlock()
231     {
232         return AptMarkup.NON_BREAKING_SPACE_MARKUP;
233     }
234 
235     /** {@inheritDoc} */
236     protected String getTextBlock( String text )
237     {
238         // "\\~, \\=, \\-, \\+, \\*, \\[, \\], \\<, \\>, \\{, \\}, \\\\"
239         StringBuilder sb = new StringBuilder();
240         sb.append( getSpecialCharacters( AptMarkup.COMMENT ) ).append( ",_" );
241         sb.append( getSpecialCharacters( Markup.EQUAL ) ).append( ",_" );
242         sb.append( getSpecialCharacters( Markup.MINUS ) ).append( ",_" );
243         sb.append( getSpecialCharacters( Markup.PLUS ) ).append( ",_" );
244         sb.append( getSpecialCharacters( Markup.STAR ) ).append( ",_" );
245         sb.append( getSpecialCharacters( Markup.LEFT_SQUARE_BRACKET ) ).append( ",_" );
246         sb.append( getSpecialCharacters( Markup.RIGHT_SQUARE_BRACKET ) ).append( ",_" );
247         sb.append( getSpecialCharacters( Markup.LESS_THAN ) ).append( ",_" );
248         sb.append( getSpecialCharacters( Markup.GREATER_THAN ) ).append( ",_" );
249         sb.append( getSpecialCharacters( Markup.LEFT_CURLY_BRACKET ) ).append( ",_" );
250         sb.append( getSpecialCharacters( Markup.RIGHT_CURLY_BRACKET ) ).append( ",_" );
251         sb.append( getSpecialCharacters( AptMarkup.BACKSLASH ) );
252 
253         return sb.toString();
254     }
255 
256     /** {@inheritDoc} */
257     protected String getRawTextBlock( String text )
258     {
259         return text;
260     }
261 
262     /**
263      * Add a backslash for a special markup character
264      *
265      * @param c
266      * @return the character with a backslash before
267      */
268     private static String getSpecialCharacters( char c )
269     {
270         return AptMarkup.BACKSLASH + "" + c;
271     }
272 
273     /** {@inheritDoc} */
274     protected String getCommentBlock( String text )
275     {
276         return "~~" + text;
277     }
278 }