Coverage Report - org.apache.maven.plugins.changes.model.io.xpp3.ChangesXpp3Writer
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesXpp3Writer
0%
0/95
0%
0/76
4.778
 
 1  
 /*
 2  
  * $Id: org.apache.maven.plugins.changes.model.io.xpp3.ChangesXpp3Writer.html 816588 2012-05-08 12:37:27Z hboutemy $
 3  
  */
 4  
 
 5  
 package org.apache.maven.plugins.changes.model.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.plugins.changes.model.Action;
 16  
 import org.apache.maven.plugins.changes.model.Author;
 17  
 import org.apache.maven.plugins.changes.model.Body;
 18  
 import org.apache.maven.plugins.changes.model.ChangesDocument;
 19  
 import org.apache.maven.plugins.changes.model.DueTo;
 20  
 import org.apache.maven.plugins.changes.model.FixedIssue;
 21  
 import org.apache.maven.plugins.changes.model.Properties;
 22  
 import org.apache.maven.plugins.changes.model.Release;
 23  
 import org.codehaus.plexus.util.xml.pull.MXSerializer;
 24  
 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
 25  
 
 26  
 /**
 27  
  * Class ChangesXpp3Writer.
 28  
  * 
 29  
  * @version $Revision: 816588 $ $Date: 2012-05-08 12:37:27 +0000 (Tue, 08 May 2012) $
 30  
  */
 31  0
 public class ChangesXpp3Writer {
 32  
 
 33  
 
 34  
       //--------------------------/
 35  
      //- Class/Member Variables -/
 36  
     //--------------------------/
 37  
 
 38  
     /**
 39  
      * Field NAMESPACE.
 40  
      */
 41  
     private String NAMESPACE;
 42  
 
 43  
 
 44  
       //-----------/
 45  
      //- Methods -/
 46  
     //-----------/
 47  
 
 48  
     /**
 49  
      * Method write.
 50  
      * 
 51  
      * @param writer
 52  
      * @param changesDocument
 53  
      * @throws java.io.IOException
 54  
      */
 55  
     public void write(Writer writer, ChangesDocument changesDocument)
 56  
         throws java.io.IOException
 57  
     {
 58  0
         XmlSerializer serializer = new MXSerializer();
 59  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
 60  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
 61  0
         serializer.setOutput( writer );
 62  0
         serializer.startDocument( changesDocument.getModelEncoding(), null );
 63  0
         writeChangesDocument( changesDocument, "document", serializer );
 64  0
         serializer.endDocument();
 65  0
     } //-- void write(Writer, ChangesDocument) 
 66  
 
 67  
     /**
 68  
      * Method writeAction.
 69  
      * 
 70  
      * @param action
 71  
      * @param serializer
 72  
      * @param tagName
 73  
      * @throws java.io.IOException
 74  
      */
 75  
     private void writeAction(Action action, String tagName, XmlSerializer serializer)
 76  
         throws java.io.IOException
 77  
     {
 78  0
         if ( action != null )
 79  
         {
 80  0
             serializer.startTag( NAMESPACE, tagName );
 81  0
             if ( action.getDev() != null )
 82  
             {
 83  0
                 serializer.attribute( NAMESPACE, "dev", action.getDev() );
 84  
             }
 85  0
             if ( action.getDueTo() != null )
 86  
             {
 87  0
                 serializer.attribute( NAMESPACE, "due-to", action.getDueTo() );
 88  
             }
 89  0
             if ( action.getDueToEmail() != null )
 90  
             {
 91  0
                 serializer.attribute( NAMESPACE, "due-to-email", action.getDueToEmail() );
 92  
             }
 93  0
             if ( action.getIssue() != null )
 94  
             {
 95  0
                 serializer.attribute( NAMESPACE, "issue", action.getIssue() );
 96  
             }
 97  0
             if ( action.getType() != null )
 98  
             {
 99  0
                 serializer.attribute( NAMESPACE, "type", action.getType() );
 100  
             }
 101  0
             if ( action.getSystem() != null )
 102  
             {
 103  0
                 serializer.attribute( NAMESPACE, "system", action.getSystem() );
 104  
             }
 105  0
             if ( action.getDate() != null )
 106  
             {
 107  0
                 serializer.attribute( NAMESPACE, "date", action.getDate() );
 108  
             }
 109  0
             serializer.text( String.valueOf( action.getAction() ));
 110  0
             if ( action.getFixedIssues() != null && action.getFixedIssues().size() > 0 )
 111  
             {
 112  0
                 for ( Iterator iter = action.getFixedIssues().iterator(); iter.hasNext(); )
 113  
                 {
 114  0
                     FixedIssue o = (FixedIssue) iter.next();
 115  0
                     writeFixedIssue( o, "fixes", serializer );
 116  
                 }
 117  
             }
 118  0
             if ( action.getDueTos() != null && action.getDueTos().size() > 0 )
 119  
             {
 120  0
                 for ( Iterator iter = action.getDueTos().iterator(); iter.hasNext(); )
 121  
                 {
 122  0
                     DueTo o = (DueTo) iter.next();
 123  0
                     writeDueTo( o, "dueto", serializer );
 124  
                 }
 125  
             }
 126  0
             serializer.endTag( NAMESPACE, tagName );
 127  
         }
 128  0
     } //-- void writeAction(Action, String, XmlSerializer) 
 129  
 
 130  
     /**
 131  
      * Method writeAuthor.
 132  
      * 
 133  
      * @param author
 134  
      * @param serializer
 135  
      * @param tagName
 136  
      * @throws java.io.IOException
 137  
      */
 138  
     private void writeAuthor(Author author, String tagName, XmlSerializer serializer)
 139  
         throws java.io.IOException
 140  
     {
 141  0
         if ( author != null )
 142  
         {
 143  0
             serializer.startTag( NAMESPACE, tagName );
 144  0
             if ( author.getAuthorEmail() != null )
 145  
             {
 146  0
                 serializer.attribute( NAMESPACE, "email", author.getAuthorEmail() );
 147  
             }
 148  0
             serializer.text( String.valueOf( author.getName() ));
 149  0
             serializer.endTag( NAMESPACE, tagName );
 150  
         }
 151  0
     } //-- void writeAuthor(Author, String, XmlSerializer) 
 152  
 
 153  
     /**
 154  
      * Method writeBody.
 155  
      * 
 156  
      * @param body
 157  
      * @param serializer
 158  
      * @param tagName
 159  
      * @throws java.io.IOException
 160  
      */
 161  
     private void writeBody(Body body, String tagName, XmlSerializer serializer)
 162  
         throws java.io.IOException
 163  
     {
 164  0
         if ( body != null )
 165  
         {
 166  0
             serializer.startTag( NAMESPACE, tagName );
 167  0
             if ( body.getReleases() != null && body.getReleases().size() > 0 )
 168  
             {
 169  0
                 for ( Iterator iter = body.getReleases().iterator(); iter.hasNext(); )
 170  
                 {
 171  0
                     Release o = (Release) iter.next();
 172  0
                     writeRelease( o, "release", serializer );
 173  
                 }
 174  
             }
 175  0
             serializer.endTag( NAMESPACE, tagName );
 176  
         }
 177  0
     } //-- void writeBody(Body, String, XmlSerializer) 
 178  
 
 179  
     /**
 180  
      * Method writeChangesDocument.
 181  
      * 
 182  
      * @param changesDocument
 183  
      * @param serializer
 184  
      * @param tagName
 185  
      * @throws java.io.IOException
 186  
      */
 187  
     private void writeChangesDocument(ChangesDocument changesDocument, String tagName, XmlSerializer serializer)
 188  
         throws java.io.IOException
 189  
     {
 190  0
         if ( changesDocument != null )
 191  
         {
 192  0
             serializer.startTag( NAMESPACE, tagName );
 193  0
             if ( changesDocument.getProperties() != null )
 194  
             {
 195  0
                 writeProperties( (Properties) changesDocument.getProperties(), "properties", serializer );
 196  
             }
 197  0
             if ( changesDocument.getBody() != null )
 198  
             {
 199  0
                 writeBody( (Body) changesDocument.getBody(), "body", serializer );
 200  
             }
 201  0
             serializer.endTag( NAMESPACE, tagName );
 202  
         }
 203  0
     } //-- void writeChangesDocument(ChangesDocument, String, XmlSerializer) 
 204  
 
 205  
     /**
 206  
      * Method writeDueTo.
 207  
      * 
 208  
      * @param dueTo
 209  
      * @param serializer
 210  
      * @param tagName
 211  
      * @throws java.io.IOException
 212  
      */
 213  
     private void writeDueTo(DueTo dueTo, String tagName, XmlSerializer serializer)
 214  
         throws java.io.IOException
 215  
     {
 216  0
         if ( dueTo != null )
 217  
         {
 218  0
             serializer.startTag( NAMESPACE, tagName );
 219  0
             if ( dueTo.getName() != null )
 220  
             {
 221  0
                 serializer.attribute( NAMESPACE, "name", dueTo.getName() );
 222  
             }
 223  0
             if ( dueTo.getEmail() != null )
 224  
             {
 225  0
                 serializer.attribute( NAMESPACE, "email", dueTo.getEmail() );
 226  
             }
 227  0
             serializer.endTag( NAMESPACE, tagName );
 228  
         }
 229  0
     } //-- void writeDueTo(DueTo, String, XmlSerializer) 
 230  
 
 231  
     /**
 232  
      * Method writeFixedIssue.
 233  
      * 
 234  
      * @param fixedIssue
 235  
      * @param serializer
 236  
      * @param tagName
 237  
      * @throws java.io.IOException
 238  
      */
 239  
     private void writeFixedIssue(FixedIssue fixedIssue, String tagName, XmlSerializer serializer)
 240  
         throws java.io.IOException
 241  
     {
 242  0
         if ( fixedIssue != null )
 243  
         {
 244  0
             serializer.startTag( NAMESPACE, tagName );
 245  0
             if ( fixedIssue.getIssue() != null )
 246  
             {
 247  0
                 serializer.attribute( NAMESPACE, "issue", fixedIssue.getIssue() );
 248  
             }
 249  0
             serializer.endTag( NAMESPACE, tagName );
 250  
         }
 251  0
     } //-- void writeFixedIssue(FixedIssue, String, XmlSerializer) 
 252  
 
 253  
     /**
 254  
      * Method writeProperties.
 255  
      * 
 256  
      * @param properties
 257  
      * @param serializer
 258  
      * @param tagName
 259  
      * @throws java.io.IOException
 260  
      */
 261  
     private void writeProperties(Properties properties, String tagName, XmlSerializer serializer)
 262  
         throws java.io.IOException
 263  
     {
 264  0
         if ( properties != null )
 265  
         {
 266  0
             serializer.startTag( NAMESPACE, tagName );
 267  0
             if ( properties.getTitle() != null )
 268  
             {
 269  0
                 serializer.startTag( NAMESPACE, "title" ).text( properties.getTitle() ).endTag( NAMESPACE, "title" );
 270  
             }
 271  0
             if ( properties.getAuthor() != null )
 272  
             {
 273  0
                 writeAuthor( (Author) properties.getAuthor(), "author", serializer );
 274  
             }
 275  0
             serializer.endTag( NAMESPACE, tagName );
 276  
         }
 277  0
     } //-- void writeProperties(Properties, String, XmlSerializer) 
 278  
 
 279  
     /**
 280  
      * Method writeRelease.
 281  
      * 
 282  
      * @param release
 283  
      * @param serializer
 284  
      * @param tagName
 285  
      * @throws java.io.IOException
 286  
      */
 287  
     private void writeRelease(Release release, String tagName, XmlSerializer serializer)
 288  
         throws java.io.IOException
 289  
     {
 290  0
         if ( release != null )
 291  
         {
 292  0
             serializer.startTag( NAMESPACE, tagName );
 293  0
             if ( release.getVersion() != null )
 294  
             {
 295  0
                 serializer.attribute( NAMESPACE, "version", release.getVersion() );
 296  
             }
 297  0
             if ( release.getDateRelease() != null )
 298  
             {
 299  0
                 serializer.attribute( NAMESPACE, "date", release.getDateRelease() );
 300  
             }
 301  0
             if ( release.getDescription() != null )
 302  
             {
 303  0
                 serializer.attribute( NAMESPACE, "description", release.getDescription() );
 304  
             }
 305  0
             if ( release.getActions() != null && release.getActions().size() > 0 )
 306  
             {
 307  0
                 for ( Iterator iter = release.getActions().iterator(); iter.hasNext(); )
 308  
                 {
 309  0
                     Action o = (Action) iter.next();
 310  0
                     writeAction( o, "action", serializer );
 311  
                 }
 312  
             }
 313  0
             serializer.endTag( NAMESPACE, tagName );
 314  
         }
 315  0
     } //-- void writeRelease(Release, String, XmlSerializer) 
 316  
 
 317  
 
 318  
 }