001    /*
002     =================== DO NOT EDIT THIS FILE ====================
003     Generated by Modello 1.4.1 on 2012-01-20 18:32:35,
004     any modifications will be overwritten.
005     ==============================================================
006     */
007    
008    package org.apache.maven.usability.plugin.io.xpp3;
009    
010      //---------------------------------/
011     //- Imported classes and packages -/
012    //---------------------------------/
013    
014    import java.io.OutputStream;
015    import java.io.Writer;
016    import java.text.DateFormat;
017    import java.util.Iterator;
018    import java.util.Locale;
019    import org.apache.maven.usability.plugin.Expression;
020    import org.apache.maven.usability.plugin.ExpressionDocumentation;
021    import org.codehaus.plexus.util.xml.pull.MXSerializer;
022    import org.codehaus.plexus.util.xml.pull.XmlSerializer;
023    
024    /**
025     * Class ParamdocXpp3Writer.
026     * 
027     * @version $Revision$ $Date$
028     */
029    @SuppressWarnings( "all" )
030    public class ParamdocXpp3Writer
031    {
032    
033          //--------------------------/
034         //- Class/Member Variables -/
035        //--------------------------/
036    
037        /**
038         * Field NAMESPACE.
039         */
040        private static final String NAMESPACE = null;
041    
042    
043          //-----------/
044         //- Methods -/
045        //-----------/
046    
047        /**
048         * Method write.
049         * 
050         * @param writer
051         * @param expressionDocumentation
052         * @throws java.io.IOException
053         */
054        public void write( Writer writer, ExpressionDocumentation expressionDocumentation )
055            throws java.io.IOException
056        {
057            XmlSerializer serializer = new MXSerializer();
058            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
059            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
060            serializer.setOutput( writer );
061            serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
062            writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
063            serializer.endDocument();
064        } //-- void write( Writer, ExpressionDocumentation )
065    
066        /**
067         * Method write.
068         * 
069         * @param stream
070         * @param expressionDocumentation
071         * @throws java.io.IOException
072         */
073        public void write( OutputStream stream, ExpressionDocumentation expressionDocumentation )
074            throws java.io.IOException
075        {
076            XmlSerializer serializer = new MXSerializer();
077            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
078            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
079            serializer.setOutput( stream, expressionDocumentation.getModelEncoding() );
080            serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
081            writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
082            serializer.endDocument();
083        } //-- void write( OutputStream, ExpressionDocumentation )
084    
085        /**
086         * Method writeExpression.
087         * 
088         * @param expression
089         * @param serializer
090         * @param tagName
091         * @throws java.io.IOException
092         */
093        private void writeExpression( Expression expression, String tagName, XmlSerializer serializer )
094            throws java.io.IOException
095        {
096            serializer.startTag( NAMESPACE, tagName );
097            if ( expression.getSyntax() != null )
098            {
099                serializer.startTag( NAMESPACE, "syntax" ).text( expression.getSyntax() ).endTag( NAMESPACE, "syntax" );
100            }
101            if ( expression.getDescription() != null )
102            {
103                serializer.startTag( NAMESPACE, "description" ).text( expression.getDescription() ).endTag( NAMESPACE, "description" );
104            }
105            if ( expression.getConfiguration() != null )
106            {
107                serializer.startTag( NAMESPACE, "configuration" ).text( expression.getConfiguration() ).endTag( NAMESPACE, "configuration" );
108            }
109            if ( ( expression.getCliOptions() != null ) && ( expression.getCliOptions().size() > 0 ) )
110            {
111                serializer.startTag( NAMESPACE, "cliOptions" );
112                for ( Iterator iter = expression.getCliOptions().keySet().iterator(); iter.hasNext(); )
113                {
114                    String key = (String) iter.next();
115                    String value = (String) expression.getCliOptions().get( key );
116                    serializer.startTag( NAMESPACE, "cliOption" );
117                    serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
118                    serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
119                    serializer.endTag( NAMESPACE, "cliOption" );
120                }
121                serializer.endTag( NAMESPACE, "cliOptions" );
122            }
123            if ( ( expression.getApiMethods() != null ) && ( expression.getApiMethods().size() > 0 ) )
124            {
125                serializer.startTag( NAMESPACE, "apiMethods" );
126                for ( Iterator iter = expression.getApiMethods().keySet().iterator(); iter.hasNext(); )
127                {
128                    String key = (String) iter.next();
129                    String value = (String) expression.getApiMethods().get( key );
130                    serializer.startTag( NAMESPACE, "apiMethod" );
131                    serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
132                    serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
133                    serializer.endTag( NAMESPACE, "apiMethod" );
134                }
135                serializer.endTag( NAMESPACE, "apiMethods" );
136            }
137            if ( expression.getDeprecation() != null )
138            {
139                serializer.startTag( NAMESPACE, "deprecation" ).text( expression.getDeprecation() ).endTag( NAMESPACE, "deprecation" );
140            }
141            if ( expression.getBan() != null )
142            {
143                serializer.startTag( NAMESPACE, "ban" ).text( expression.getBan() ).endTag( NAMESPACE, "ban" );
144            }
145            if ( expression.isEditable() != true )
146            {
147                serializer.startTag( NAMESPACE, "editable" ).text( String.valueOf( expression.isEditable() ) ).endTag( NAMESPACE, "editable" );
148            }
149            serializer.endTag( NAMESPACE, tagName );
150        } //-- void writeExpression( Expression, String, XmlSerializer )
151    
152        /**
153         * Method writeExpressionDocumentation.
154         * 
155         * @param expressionDocumentation
156         * @param serializer
157         * @param tagName
158         * @throws java.io.IOException
159         */
160        private void writeExpressionDocumentation( ExpressionDocumentation expressionDocumentation, String tagName, XmlSerializer serializer )
161            throws java.io.IOException
162        {
163            serializer.setPrefix( "", "http://maven.apache.org/PARAMDOC/1.0.0" );
164            serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
165            serializer.startTag( NAMESPACE, tagName );
166            serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PARAMDOC/1.0.0 http://maven.apache.org/xsd/paramdoc-1.0.0.xsd" );
167            if ( ( expressionDocumentation.getExpressions() != null ) && ( expressionDocumentation.getExpressions().size() > 0 ) )
168            {
169                serializer.startTag( NAMESPACE, "expressions" );
170                for ( Iterator iter = expressionDocumentation.getExpressions().iterator(); iter.hasNext(); )
171                {
172                    Expression o = (Expression) iter.next();
173                    writeExpression( o, "expression", serializer );
174                }
175                serializer.endTag( NAMESPACE, "expressions" );
176            }
177            serializer.endTag( NAMESPACE, tagName );
178        } //-- void writeExpressionDocumentation( ExpressionDocumentation, String, XmlSerializer )
179    
180    }