View Javadoc
1   package org.apache.maven.doxia.module.xdoc;
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.codehaus.plexus.util.StringUtils;
26  import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
27  import org.codehaus.plexus.util.xml.XmlUtil;
28  
29  /**
30   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
31   * @version $Id: XmlWriterXdocSinkTest.java 1467294 2013-04-12 14:51:42Z rfscholte $
32   * @since 1.1
33   */
34  public class XmlWriterXdocSinkTest
35      extends XdocSinkTest
36  {
37      private static final String DEFAULT_INDENT = StringUtils.repeat( " ", XmlUtil.DEFAULT_INDENTATION_SIZE );
38  
39      /** {@inheritDoc} */
40      protected Sink createSink( Writer writer )
41      {
42          return new XmlWriterXdocSink( new PrettyPrintXMLWriter( writer ) );
43      }
44  
45      /** {@inheritDoc} */
46      protected String getSection1Block( String title )
47      {
48          return "<section name=\"" + title + "\"/>";
49      }
50  
51      /** {@inheritDoc} */
52      protected String getSection2Block( String title )
53      {
54          return "<subsection name=\"" + title + "\"/>";
55      }
56  
57      /** {@inheritDoc} */
58      protected String getListBlock( String item )
59      {
60          return "<ul>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<li>" + item + "</li>"
61              + XmlUtil.DEFAULT_LINE_SEPARATOR + "</ul>";
62      }
63  
64      /** {@inheritDoc} */
65      protected String getNumberedListBlock( String item )
66      {
67          return "<ol style=\"list-style-type: lower-roman\">" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT
68              + "<li>" + item + "</li>" + XmlUtil.DEFAULT_LINE_SEPARATOR + "</ol>";
69      }
70  
71      /** {@inheritDoc} */
72      protected String getDefinitionListBlock( String definum, String definition )
73      {
74          return "<dl>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<dt>" + definum + "</dt>"
75              + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<dd>" + definition + "</dd>"
76              + XmlUtil.DEFAULT_LINE_SEPARATOR + "</dl>";
77      }
78  
79      /** {@inheritDoc} */
80      protected String getFigureBlock( String source, String caption )
81      {
82          String figureBlock = "<img src=\"" + source + "\"";
83          if ( caption != null )
84          {
85              figureBlock += " alt=\"" + caption + "\"";
86          }
87          else //@todo fix DOXIA-361
88          {
89              figureBlock += " alt=\"\"";
90          }
91          figureBlock += "/>";
92          return figureBlock;
93      }
94  
95      /** {@inheritDoc} */
96      protected String getTableBlock( String cell, String caption )
97      {
98          return "<table border=\"0\">" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT
99              + "<caption>" + caption + "</caption>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT
100             + "<tr valign=\"top\">" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + DEFAULT_INDENT
101             + "<td>" + cell + "</td>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "</tr>"
102             + XmlUtil.DEFAULT_LINE_SEPARATOR + "</table>";
103     }
104 
105     /** {@inheritDoc} */
106     protected String getHorizontalRuleBlock()
107     {
108         return "<hr/>";
109     }
110 
111     /** {@inheritDoc} */
112     protected String getLineBreakBlock()
113     {
114         return "<br/>";
115     }
116 }