Coverage Report - org.apache.maven.usability.plugin.io.xpp3.ParamdocXpp3Writer
 
Classes in this File Line Coverage Branch Coverage Complexity
ParamdocXpp3Writer
0%
0/58
0%
0/34
5.667
 
 1  
 /*
 2  
  * $Id$
 3  
  */
 4  
 
 5  
 package org.apache.maven.usability.plugin.io.xpp3;
 6  
 
 7  
   //---------------------------------/
 8  
  //- Imported classes and packages -/
 9  
 //---------------------------------/
 10  
 
 11  
 import java.io.Writer;
 12  
 import java.text.DateFormat;
 13  
 import java.util.Iterator;
 14  
 import java.util.Locale;
 15  
 import org.apache.maven.usability.plugin.Expression;
 16  
 import org.apache.maven.usability.plugin.ExpressionDocumentation;
 17  
 import org.codehaus.plexus.util.xml.pull.MXSerializer;
 18  
 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
 19  
 
 20  
 /**
 21  
  * Class ParamdocXpp3Writer.
 22  
  * 
 23  
  * @version $Revision$ $Date$
 24  
  */
 25  0
 public class ParamdocXpp3Writer {
 26  
 
 27  
 
 28  
       //--------------------------/
 29  
      //- Class/Member Variables -/
 30  
     //--------------------------/
 31  
 
 32  
     /**
 33  
      * Field NAMESPACE.
 34  
      */
 35  
     private String NAMESPACE;
 36  
 
 37  
 
 38  
       //-----------/
 39  
      //- Methods -/
 40  
     //-----------/
 41  
 
 42  
     /**
 43  
      * Method write.
 44  
      * 
 45  
      * @param writer
 46  
      * @param expressionDocumentation
 47  
      * @throws java.io.IOException
 48  
      */
 49  
     public void write( Writer writer, ExpressionDocumentation expressionDocumentation )
 50  
         throws java.io.IOException
 51  
     {
 52  0
         XmlSerializer serializer = new MXSerializer();
 53  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
 54  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
 55  0
         serializer.setOutput( writer );
 56  0
         serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
 57  0
         writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
 58  0
         serializer.endDocument();
 59  0
     } //-- void write( Writer, ExpressionDocumentation ) 
 60  
 
 61  
     /**
 62  
      * Method writeExpression.
 63  
      * 
 64  
      * @param expression
 65  
      * @param serializer
 66  
      * @param tagName
 67  
      * @throws java.io.IOException
 68  
      */
 69  
     private void writeExpression( Expression expression, String tagName, XmlSerializer serializer )
 70  
         throws java.io.IOException
 71  
     {
 72  0
         if ( expression != null )
 73  
         {
 74  0
             serializer.startTag( NAMESPACE, tagName );
 75  0
             if ( expression.getSyntax() != null )
 76  
             {
 77  0
                 serializer.startTag( NAMESPACE, "syntax" ).text( expression.getSyntax() ).endTag( NAMESPACE, "syntax" );
 78  
             }
 79  0
             if ( expression.getDescription() != null )
 80  
             {
 81  0
                 serializer.startTag( NAMESPACE, "description" ).text( expression.getDescription() ).endTag( NAMESPACE, "description" );
 82  
             }
 83  0
             if ( expression.getConfiguration() != null )
 84  
             {
 85  0
                 serializer.startTag( NAMESPACE, "configuration" ).text( expression.getConfiguration() ).endTag( NAMESPACE, "configuration" );
 86  
             }
 87  0
             if ( expression.getCliOptions() != null && expression.getCliOptions().size() > 0 )
 88  
             {
 89  0
                 serializer.startTag( NAMESPACE, "cliOptions" );
 90  0
                 for ( Iterator iter = expression.getCliOptions().keySet().iterator(); iter.hasNext(); )
 91  
                 {
 92  0
                     String key = (String) iter.next();
 93  0
                     String value = (String) expression.getCliOptions().get( key );
 94  0
                     serializer.startTag( NAMESPACE, "cliOption" );
 95  0
                     serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
 96  0
                     serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
 97  0
                     serializer.endTag( NAMESPACE, "cliOption" );
 98  0
                 }
 99  0
                 serializer.endTag( NAMESPACE, "cliOptions" );
 100  
             }
 101  0
             if ( expression.getApiMethods() != null && expression.getApiMethods().size() > 0 )
 102  
             {
 103  0
                 serializer.startTag( NAMESPACE, "apiMethods" );
 104  0
                 for ( Iterator iter = expression.getApiMethods().keySet().iterator(); iter.hasNext(); )
 105  
                 {
 106  0
                     String key = (String) iter.next();
 107  0
                     String value = (String) expression.getApiMethods().get( key );
 108  0
                     serializer.startTag( NAMESPACE, "apiMethod" );
 109  0
                     serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
 110  0
                     serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
 111  0
                     serializer.endTag( NAMESPACE, "apiMethod" );
 112  0
                 }
 113  0
                 serializer.endTag( NAMESPACE, "apiMethods" );
 114  
             }
 115  0
             if ( expression.getDeprecation() != null )
 116  
             {
 117  0
                 serializer.startTag( NAMESPACE, "deprecation" ).text( expression.getDeprecation() ).endTag( NAMESPACE, "deprecation" );
 118  
             }
 119  0
             if ( expression.getBan() != null )
 120  
             {
 121  0
                 serializer.startTag( NAMESPACE, "ban" ).text( expression.getBan() ).endTag( NAMESPACE, "ban" );
 122  
             }
 123  0
             if ( expression.isEditable() != true )
 124  
             {
 125  0
                 serializer.startTag( NAMESPACE, "editable" ).text( String.valueOf( expression.isEditable() ) ).endTag( NAMESPACE, "editable" );
 126  
             }
 127  0
             serializer.endTag( NAMESPACE, tagName );
 128  
         }
 129  0
     } //-- void writeExpression( Expression, String, XmlSerializer ) 
 130  
 
 131  
     /**
 132  
      * Method writeExpressionDocumentation.
 133  
      * 
 134  
      * @param expressionDocumentation
 135  
      * @param serializer
 136  
      * @param tagName
 137  
      * @throws java.io.IOException
 138  
      */
 139  
     private void writeExpressionDocumentation( ExpressionDocumentation expressionDocumentation, String tagName, XmlSerializer serializer )
 140  
         throws java.io.IOException
 141  
     {
 142  0
         if ( expressionDocumentation != null )
 143  
         {
 144  0
             serializer.startTag( NAMESPACE, tagName );
 145  0
             if ( expressionDocumentation.getExpressions() != null && expressionDocumentation.getExpressions().size() > 0 )
 146  
             {
 147  0
                 serializer.startTag( NAMESPACE, "expressions" );
 148  0
                 for ( Iterator iter = expressionDocumentation.getExpressions().iterator(); iter.hasNext(); )
 149  
                 {
 150  0
                     Expression o = (Expression) iter.next();
 151  0
                     writeExpression( o, "expression", serializer );
 152  0
                 }
 153  0
                 serializer.endTag( NAMESPACE, "expressions" );
 154  
             }
 155  0
             serializer.endTag( NAMESPACE, tagName );
 156  
         }
 157  0
     } //-- void writeExpressionDocumentation( ExpressionDocumentation, String, XmlSerializer ) 
 158  
 
 159  
 
 160  
 }