001package org.apache.maven.doxia.module.xdoc;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.Writer;
023
024import org.apache.maven.doxia.sink.Sink;
025import org.codehaus.plexus.util.StringUtils;
026import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
027import org.codehaus.plexus.util.xml.XmlUtil;
028
029/**
030 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
031 * @version $Id$
032 * @since 1.1
033 */
034public class XmlWriterXdocSinkTest
035    extends XdocSinkTest
036{
037    private static final String DEFAULT_INDENT = StringUtils.repeat( " ", XmlUtil.DEFAULT_INDENTATION_SIZE );
038
039    /** {@inheritDoc} */
040    protected Sink createSink( Writer writer )
041    {
042        return new XmlWriterXdocSink( new PrettyPrintXMLWriter( writer ) );
043    }
044
045    /** {@inheritDoc} */
046    protected String getSection1Block( String title )
047    {
048        return "<section name=\"" + title + "\"/>";
049    }
050
051    /** {@inheritDoc} */
052    protected String getSection2Block( String title )
053    {
054        return "<subsection name=\"" + title + "\"/>";
055    }
056
057    /** {@inheritDoc} */
058    protected String getListBlock( String item )
059    {
060        return "<ul>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<li>" + item + "</li>"
061            + XmlUtil.DEFAULT_LINE_SEPARATOR + "</ul>";
062    }
063
064    /** {@inheritDoc} */
065    protected String getNumberedListBlock( String item )
066    {
067        return "<ol style=\"list-style-type: lower-roman\">" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT
068            + "<li>" + item + "</li>" + XmlUtil.DEFAULT_LINE_SEPARATOR + "</ol>";
069    }
070
071    /** {@inheritDoc} */
072    protected String getDefinitionListBlock( String definum, String definition )
073    {
074        return "<dl>" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<dt>" + definum + "</dt>"
075            + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT + "<dd>" + definition + "</dd>"
076            + XmlUtil.DEFAULT_LINE_SEPARATOR + "</dl>";
077    }
078
079    /** {@inheritDoc} */
080    protected String getFigureBlock( String source, String caption )
081    {
082        String figureBlock = "<img src=\"" + source + "\"";
083        if ( caption != null )
084        {
085            figureBlock += " alt=\"" + caption + "\"";
086        }
087        else //@todo fix DOXIA-361
088        {
089            figureBlock += " alt=\"\"";
090        }
091        figureBlock += "/>";
092        return figureBlock;
093    }
094
095    /** {@inheritDoc} */
096    protected String getTableBlock( String cell, String caption )
097    {
098        return "<table border=\"0\">" + XmlUtil.DEFAULT_LINE_SEPARATOR + DEFAULT_INDENT
099            + "<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}