Coverage Report - org.apache.maven.profiles.io.xpp3.ProfilesXpp3Writer
 
Classes in this File Line Coverage Branch Coverage Complexity
ProfilesXpp3Writer
0 %
0/141
0 %
0/108
5,7
 
 1  
 /*
 2  
  =================== DO NOT EDIT THIS FILE ====================
 3  
  Generated by Modello 1.0.1 on 2009-09-09 03:07:36,
 4  
  any modifications will be overwritten.
 5  
  ==============================================================
 6  
  */
 7  
 
 8  
 package org.apache.maven.profiles.io.xpp3;
 9  
 
 10  
   //---------------------------------/
 11  
  //- Imported classes and packages -/
 12  
 //---------------------------------/
 13  
 
 14  
 import java.io.Writer;
 15  
 import java.text.DateFormat;
 16  
 import java.util.Iterator;
 17  
 import java.util.Locale;
 18  
 import org.apache.maven.profiles.Activation;
 19  
 import org.apache.maven.profiles.ActivationFile;
 20  
 import org.apache.maven.profiles.ActivationOS;
 21  
 import org.apache.maven.profiles.ActivationProperty;
 22  
 import org.apache.maven.profiles.Profile;
 23  
 import org.apache.maven.profiles.ProfilesRoot;
 24  
 import org.apache.maven.profiles.Repository;
 25  
 import org.apache.maven.profiles.RepositoryBase;
 26  
 import org.apache.maven.profiles.RepositoryPolicy;
 27  
 import org.codehaus.plexus.util.xml.pull.MXSerializer;
 28  
 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
 29  
 
 30  
 /**
 31  
  * Class ProfilesXpp3Writer.
 32  
  * 
 33  
  * @version $Revision$ $Date$
 34  
  */
 35  0
 public class ProfilesXpp3Writer
 36  
 {
 37  
 
 38  
       //--------------------------/
 39  
      //- Class/Member Variables -/
 40  
     //--------------------------/
 41  
 
 42  
     /**
 43  
      * Field NAMESPACE.
 44  
      */
 45  0
     private static final String NAMESPACE = null;
 46  
 
 47  
 
 48  
       //-----------/
 49  
      //- Methods -/
 50  
     //-----------/
 51  
 
 52  
     /**
 53  
      * Method write.
 54  
      * 
 55  
      * @param writer
 56  
      * @param profilesRoot
 57  
      * @throws java.io.IOException
 58  
      */
 59  
     public void write( Writer writer, ProfilesRoot profilesRoot )
 60  
         throws java.io.IOException
 61  
     {
 62  0
         XmlSerializer serializer = new MXSerializer();
 63  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
 64  0
         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
 65  0
         serializer.setOutput( writer );
 66  0
         serializer.startDocument( profilesRoot.getModelEncoding(), null );
 67  0
         writeProfilesRoot( profilesRoot, "profilesXml", serializer );
 68  0
         serializer.endDocument();
 69  0
     } //-- void write( Writer, ProfilesRoot )
 70  
 
 71  
     /**
 72  
      * Method writeActivation.
 73  
      * 
 74  
      * @param activation
 75  
      * @param serializer
 76  
      * @param tagName
 77  
      * @throws java.io.IOException
 78  
      */
 79  
     private void writeActivation( Activation activation, String tagName, XmlSerializer serializer )
 80  
         throws java.io.IOException
 81  
     {
 82  0
         if ( activation != null )
 83  
         {
 84  0
             serializer.startTag( NAMESPACE, tagName );
 85  0
             if ( activation.isActiveByDefault() != false )
 86  
             {
 87  0
                 serializer.startTag( NAMESPACE, "activeByDefault" ).text( String.valueOf( activation.isActiveByDefault() ) ).endTag( NAMESPACE, "activeByDefault" );
 88  
             }
 89  0
             if ( activation.getJdk() != null )
 90  
             {
 91  0
                 serializer.startTag( NAMESPACE, "jdk" ).text( activation.getJdk() ).endTag( NAMESPACE, "jdk" );
 92  
             }
 93  0
             if ( activation.getOs() != null )
 94  
             {
 95  0
                 writeActivationOS( (ActivationOS) activation.getOs(), "os", serializer );
 96  
             }
 97  0
             if ( activation.getProperty() != null )
 98  
             {
 99  0
                 writeActivationProperty( (ActivationProperty) activation.getProperty(), "property", serializer );
 100  
             }
 101  0
             if ( activation.getFile() != null )
 102  
             {
 103  0
                 writeActivationFile( (ActivationFile) activation.getFile(), "file", serializer );
 104  
             }
 105  0
             serializer.endTag( NAMESPACE, tagName );
 106  
         }
 107  0
     } //-- void writeActivation( Activation, String, XmlSerializer )
 108  
 
 109  
     /**
 110  
      * Method writeActivationFile.
 111  
      * 
 112  
      * @param activationFile
 113  
      * @param serializer
 114  
      * @param tagName
 115  
      * @throws java.io.IOException
 116  
      */
 117  
     private void writeActivationFile( ActivationFile activationFile, String tagName, XmlSerializer serializer )
 118  
         throws java.io.IOException
 119  
     {
 120  0
         if ( activationFile != null )
 121  
         {
 122  0
             serializer.startTag( NAMESPACE, tagName );
 123  0
             if ( activationFile.getMissing() != null )
 124  
             {
 125  0
                 serializer.startTag( NAMESPACE, "missing" ).text( activationFile.getMissing() ).endTag( NAMESPACE, "missing" );
 126  
             }
 127  0
             if ( activationFile.getExists() != null )
 128  
             {
 129  0
                 serializer.startTag( NAMESPACE, "exists" ).text( activationFile.getExists() ).endTag( NAMESPACE, "exists" );
 130  
             }
 131  0
             serializer.endTag( NAMESPACE, tagName );
 132  
         }
 133  0
     } //-- void writeActivationFile( ActivationFile, String, XmlSerializer )
 134  
 
 135  
     /**
 136  
      * Method writeActivationOS.
 137  
      * 
 138  
      * @param activationOS
 139  
      * @param serializer
 140  
      * @param tagName
 141  
      * @throws java.io.IOException
 142  
      */
 143  
     private void writeActivationOS( ActivationOS activationOS, String tagName, XmlSerializer serializer )
 144  
         throws java.io.IOException
 145  
     {
 146  0
         if ( activationOS != null )
 147  
         {
 148  0
             serializer.startTag( NAMESPACE, tagName );
 149  0
             if ( activationOS.getName() != null )
 150  
             {
 151  0
                 serializer.startTag( NAMESPACE, "name" ).text( activationOS.getName() ).endTag( NAMESPACE, "name" );
 152  
             }
 153  0
             if ( activationOS.getFamily() != null )
 154  
             {
 155  0
                 serializer.startTag( NAMESPACE, "family" ).text( activationOS.getFamily() ).endTag( NAMESPACE, "family" );
 156  
             }
 157  0
             if ( activationOS.getArch() != null )
 158  
             {
 159  0
                 serializer.startTag( NAMESPACE, "arch" ).text( activationOS.getArch() ).endTag( NAMESPACE, "arch" );
 160  
             }
 161  0
             if ( activationOS.getVersion() != null )
 162  
             {
 163  0
                 serializer.startTag( NAMESPACE, "version" ).text( activationOS.getVersion() ).endTag( NAMESPACE, "version" );
 164  
             }
 165  0
             serializer.endTag( NAMESPACE, tagName );
 166  
         }
 167  0
     } //-- void writeActivationOS( ActivationOS, String, XmlSerializer )
 168  
 
 169  
     /**
 170  
      * Method writeActivationProperty.
 171  
      * 
 172  
      * @param activationProperty
 173  
      * @param serializer
 174  
      * @param tagName
 175  
      * @throws java.io.IOException
 176  
      */
 177  
     private void writeActivationProperty( ActivationProperty activationProperty, String tagName, XmlSerializer serializer )
 178  
         throws java.io.IOException
 179  
     {
 180  0
         if ( activationProperty != null )
 181  
         {
 182  0
             serializer.startTag( NAMESPACE, tagName );
 183  0
             if ( activationProperty.getName() != null )
 184  
             {
 185  0
                 serializer.startTag( NAMESPACE, "name" ).text( activationProperty.getName() ).endTag( NAMESPACE, "name" );
 186  
             }
 187  0
             if ( activationProperty.getValue() != null )
 188  
             {
 189  0
                 serializer.startTag( NAMESPACE, "value" ).text( activationProperty.getValue() ).endTag( NAMESPACE, "value" );
 190  
             }
 191  0
             serializer.endTag( NAMESPACE, tagName );
 192  
         }
 193  0
     } //-- void writeActivationProperty( ActivationProperty, String, XmlSerializer )
 194  
 
 195  
     /**
 196  
      * Method writeProfile.
 197  
      * 
 198  
      * @param profile
 199  
      * @param serializer
 200  
      * @param tagName
 201  
      * @throws java.io.IOException
 202  
      */
 203  
     private void writeProfile( Profile profile, String tagName, XmlSerializer serializer )
 204  
         throws java.io.IOException
 205  
     {
 206  0
         if ( profile != null )
 207  
         {
 208  0
             serializer.startTag( NAMESPACE, tagName );
 209  0
             if ( profile.getId() != null )
 210  
             {
 211  0
                 serializer.startTag( NAMESPACE, "id" ).text( profile.getId() ).endTag( NAMESPACE, "id" );
 212  
             }
 213  0
             if ( profile.getActivation() != null )
 214  
             {
 215  0
                 writeActivation( (Activation) profile.getActivation(), "activation", serializer );
 216  
             }
 217  0
             if ( ( profile.getProperties() != null ) && ( profile.getProperties().size() > 0 ) )
 218  
             {
 219  0
                 serializer.startTag( NAMESPACE, "properties" );
 220  0
                 for ( Iterator iter = profile.getProperties().keySet().iterator(); iter.hasNext(); )
 221  
                 {
 222  0
                     String key = (String) iter.next();
 223  0
                     String value = (String) profile.getProperties().get( key );
 224  0
                     serializer.startTag( NAMESPACE, "" + key + "" ).text( value ).endTag( NAMESPACE, "" + key + "" );
 225  0
                 }
 226  0
                 serializer.endTag( NAMESPACE, "properties" );
 227  
             }
 228  0
             if ( ( profile.getRepositories() != null ) && ( profile.getRepositories().size() > 0 ) )
 229  
             {
 230  0
                 serializer.startTag( NAMESPACE, "repositories" );
 231  0
                 for ( Iterator iter = profile.getRepositories().iterator(); iter.hasNext(); )
 232  
                 {
 233  0
                     Repository o = (Repository) iter.next();
 234  0
                     writeRepository( o, "repository", serializer );
 235  0
                 }
 236  0
                 serializer.endTag( NAMESPACE, "repositories" );
 237  
             }
 238  0
             if ( ( profile.getPluginRepositories() != null ) && ( profile.getPluginRepositories().size() > 0 ) )
 239  
             {
 240  0
                 serializer.startTag( NAMESPACE, "pluginRepositories" );
 241  0
                 for ( Iterator iter = profile.getPluginRepositories().iterator(); iter.hasNext(); )
 242  
                 {
 243  0
                     Repository o = (Repository) iter.next();
 244  0
                     writeRepository( o, "pluginRepository", serializer );
 245  0
                 }
 246  0
                 serializer.endTag( NAMESPACE, "pluginRepositories" );
 247  
             }
 248  0
             serializer.endTag( NAMESPACE, tagName );
 249  
         }
 250  0
     } //-- void writeProfile( Profile, String, XmlSerializer )
 251  
 
 252  
     /**
 253  
      * Method writeProfilesRoot.
 254  
      * 
 255  
      * @param profilesRoot
 256  
      * @param serializer
 257  
      * @param tagName
 258  
      * @throws java.io.IOException
 259  
      */
 260  
     private void writeProfilesRoot( ProfilesRoot profilesRoot, String tagName, XmlSerializer serializer )
 261  
         throws java.io.IOException
 262  
     {
 263  0
         if ( profilesRoot != null )
 264  
         {
 265  0
             serializer.setPrefix( "", "http://maven.apache.org/PROFILES/1.0.0" );
 266  0
             serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
 267  0
             serializer.startTag( NAMESPACE, tagName );
 268  0
             serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
 269  0
             if ( ( profilesRoot.getProfiles() != null ) && ( profilesRoot.getProfiles().size() > 0 ) )
 270  
             {
 271  0
                 serializer.startTag( NAMESPACE, "profiles" );
 272  0
                 for ( Iterator iter = profilesRoot.getProfiles().iterator(); iter.hasNext(); )
 273  
                 {
 274  0
                     Profile o = (Profile) iter.next();
 275  0
                     writeProfile( o, "profile", serializer );
 276  0
                 }
 277  0
                 serializer.endTag( NAMESPACE, "profiles" );
 278  
             }
 279  0
             if ( ( profilesRoot.getActiveProfiles() != null ) && ( profilesRoot.getActiveProfiles().size() > 0 ) )
 280  
             {
 281  0
                 serializer.startTag( NAMESPACE, "activeProfiles" );
 282  0
                 for ( Iterator iter = profilesRoot.getActiveProfiles().iterator(); iter.hasNext(); )
 283  
                 {
 284  0
                     String activeProfile = (String) iter.next();
 285  0
                     serializer.startTag( NAMESPACE, "activeProfile" ).text( activeProfile ).endTag( NAMESPACE, "activeProfile" );
 286  0
                 }
 287  0
                 serializer.endTag( NAMESPACE, "activeProfiles" );
 288  
             }
 289  0
             serializer.endTag( NAMESPACE, tagName );
 290  
         }
 291  0
     } //-- void writeProfilesRoot( ProfilesRoot, String, XmlSerializer )
 292  
 
 293  
     /**
 294  
      * Method writeRepository.
 295  
      * 
 296  
      * @param repository
 297  
      * @param serializer
 298  
      * @param tagName
 299  
      * @throws java.io.IOException
 300  
      */
 301  
     private void writeRepository( Repository repository, String tagName, XmlSerializer serializer )
 302  
         throws java.io.IOException
 303  
     {
 304  0
         if ( repository != null )
 305  
         {
 306  0
             serializer.startTag( NAMESPACE, tagName );
 307  0
             if ( repository.getReleases() != null )
 308  
             {
 309  0
                 writeRepositoryPolicy( (RepositoryPolicy) repository.getReleases(), "releases", serializer );
 310  
             }
 311  0
             if ( repository.getSnapshots() != null )
 312  
             {
 313  0
                 writeRepositoryPolicy( (RepositoryPolicy) repository.getSnapshots(), "snapshots", serializer );
 314  
             }
 315  0
             if ( repository.getId() != null )
 316  
             {
 317  0
                 serializer.startTag( NAMESPACE, "id" ).text( repository.getId() ).endTag( NAMESPACE, "id" );
 318  
             }
 319  0
             if ( repository.getName() != null )
 320  
             {
 321  0
                 serializer.startTag( NAMESPACE, "name" ).text( repository.getName() ).endTag( NAMESPACE, "name" );
 322  
             }
 323  0
             if ( repository.getUrl() != null )
 324  
             {
 325  0
                 serializer.startTag( NAMESPACE, "url" ).text( repository.getUrl() ).endTag( NAMESPACE, "url" );
 326  
             }
 327  0
             if ( ( repository.getLayout() != null ) && !repository.getLayout().equals( "default" ) )
 328  
             {
 329  0
                 serializer.startTag( NAMESPACE, "layout" ).text( repository.getLayout() ).endTag( NAMESPACE, "layout" );
 330  
             }
 331  0
             serializer.endTag( NAMESPACE, tagName );
 332  
         }
 333  0
     } //-- void writeRepository( Repository, String, XmlSerializer )
 334  
 
 335  
     /**
 336  
      * Method writeRepositoryBase.
 337  
      * 
 338  
      * @param repositoryBase
 339  
      * @param serializer
 340  
      * @param tagName
 341  
      * @throws java.io.IOException
 342  
      */
 343  
     private void writeRepositoryBase( RepositoryBase repositoryBase, String tagName, XmlSerializer serializer )
 344  
         throws java.io.IOException
 345  
     {
 346  0
         if ( repositoryBase != null )
 347  
         {
 348  0
             serializer.startTag( NAMESPACE, tagName );
 349  0
             if ( repositoryBase.getId() != null )
 350  
             {
 351  0
                 serializer.startTag( NAMESPACE, "id" ).text( repositoryBase.getId() ).endTag( NAMESPACE, "id" );
 352  
             }
 353  0
             if ( repositoryBase.getName() != null )
 354  
             {
 355  0
                 serializer.startTag( NAMESPACE, "name" ).text( repositoryBase.getName() ).endTag( NAMESPACE, "name" );
 356  
             }
 357  0
             if ( repositoryBase.getUrl() != null )
 358  
             {
 359  0
                 serializer.startTag( NAMESPACE, "url" ).text( repositoryBase.getUrl() ).endTag( NAMESPACE, "url" );
 360  
             }
 361  0
             if ( ( repositoryBase.getLayout() != null ) && !repositoryBase.getLayout().equals( "default" ) )
 362  
             {
 363  0
                 serializer.startTag( NAMESPACE, "layout" ).text( repositoryBase.getLayout() ).endTag( NAMESPACE, "layout" );
 364  
             }
 365  0
             serializer.endTag( NAMESPACE, tagName );
 366  
         }
 367  0
     } //-- void writeRepositoryBase( RepositoryBase, String, XmlSerializer )
 368  
 
 369  
     /**
 370  
      * Method writeRepositoryPolicy.
 371  
      * 
 372  
      * @param repositoryPolicy
 373  
      * @param serializer
 374  
      * @param tagName
 375  
      * @throws java.io.IOException
 376  
      */
 377  
     private void writeRepositoryPolicy( RepositoryPolicy repositoryPolicy, String tagName, XmlSerializer serializer )
 378  
         throws java.io.IOException
 379  
     {
 380  0
         if ( repositoryPolicy != null )
 381  
         {
 382  0
             serializer.startTag( NAMESPACE, tagName );
 383  0
             if ( repositoryPolicy.isEnabled() != true )
 384  
             {
 385  0
                 serializer.startTag( NAMESPACE, "enabled" ).text( String.valueOf( repositoryPolicy.isEnabled() ) ).endTag( NAMESPACE, "enabled" );
 386  
             }
 387  0
             if ( repositoryPolicy.getUpdatePolicy() != null )
 388  
             {
 389  0
                 serializer.startTag( NAMESPACE, "updatePolicy" ).text( repositoryPolicy.getUpdatePolicy() ).endTag( NAMESPACE, "updatePolicy" );
 390  
             }
 391  0
             if ( repositoryPolicy.getChecksumPolicy() != null )
 392  
             {
 393  0
                 serializer.startTag( NAMESPACE, "checksumPolicy" ).text( repositoryPolicy.getChecksumPolicy() ).endTag( NAMESPACE, "checksumPolicy" );
 394  
             }
 395  0
             serializer.endTag( NAMESPACE, tagName );
 396  
         }
 397  0
     } //-- void writeRepositoryPolicy( RepositoryPolicy, String, XmlSerializer )
 398  
 
 399  
 
 400  
 }