View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.8.3,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.archetype.catalog.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.OutputStream;
13  import java.io.Writer;
14  import java.util.Iterator;
15  import org.apache.maven.archetype.catalog.Archetype;
16  import org.apache.maven.archetype.catalog.ArchetypeCatalog;
17  import org.codehaus.plexus.util.xml.pull.MXSerializer;
18  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
19  
20  /**
21   * Class ArchetypeCatalogXpp3Writer.
22   * 
23   * @version $Revision: 942523 $ $Date: 2015-03-06 00:20:33 +0000 (Fri, 06 Mar 2015) $
24   */
25  @SuppressWarnings( "all" )
26  public class ArchetypeCatalogXpp3Writer
27  {
28  
29        //--------------------------/
30       //- Class/Member Variables -/
31      //--------------------------/
32  
33      /**
34       * Field NAMESPACE.
35       */
36      private static final String NAMESPACE = null;
37  
38  
39        //-----------/
40       //- Methods -/
41      //-----------/
42  
43      /**
44       * Method write.
45       * 
46       * @param writer
47       * @param archetypeCatalog
48       * @throws java.io.IOException
49       */
50      public void write( Writer writer, ArchetypeCatalog archetypeCatalog )
51          throws java.io.IOException
52      {
53          XmlSerializer serializer = new MXSerializer();
54          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
55          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
56          serializer.setOutput( writer );
57          serializer.startDocument( archetypeCatalog.getModelEncoding(), null );
58          writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer );
59          serializer.endDocument();
60      } //-- void write( Writer, ArchetypeCatalog )
61  
62      /**
63       * Method write.
64       * 
65       * @param stream
66       * @param archetypeCatalog
67       * @throws java.io.IOException
68       */
69      public void write( OutputStream stream, ArchetypeCatalog archetypeCatalog )
70          throws java.io.IOException
71      {
72          XmlSerializer serializer = new MXSerializer();
73          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
74          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
75          serializer.setOutput( stream, archetypeCatalog.getModelEncoding() );
76          serializer.startDocument( archetypeCatalog.getModelEncoding(), null );
77          writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer );
78          serializer.endDocument();
79      } //-- void write( OutputStream, ArchetypeCatalog )
80  
81      /**
82       * Method writeArchetype.
83       * 
84       * @param archetype
85       * @param serializer
86       * @param tagName
87       * @throws java.io.IOException
88       */
89      private void writeArchetype( Archetype archetype, String tagName, XmlSerializer serializer )
90          throws java.io.IOException
91      {
92          serializer.startTag( NAMESPACE, tagName );
93          if ( archetype.getGroupId() != null )
94          {
95              serializer.startTag( NAMESPACE, "groupId" ).text( archetype.getGroupId() ).endTag( NAMESPACE, "groupId" );
96          }
97          if ( archetype.getArtifactId() != null )
98          {
99              serializer.startTag( NAMESPACE, "artifactId" ).text( archetype.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
100         }
101         if ( archetype.getVersion() != null )
102         {
103             serializer.startTag( NAMESPACE, "version" ).text( archetype.getVersion() ).endTag( NAMESPACE, "version" );
104         }
105         if ( archetype.getRepository() != null )
106         {
107             serializer.startTag( NAMESPACE, "repository" ).text( archetype.getRepository() ).endTag( NAMESPACE, "repository" );
108         }
109         if ( archetype.getDescription() != null )
110         {
111             serializer.startTag( NAMESPACE, "description" ).text( archetype.getDescription() ).endTag( NAMESPACE, "description" );
112         }
113         serializer.endTag( NAMESPACE, tagName );
114     } //-- void writeArchetype( Archetype, String, XmlSerializer )
115 
116     /**
117      * Method writeArchetypeCatalog.
118      * 
119      * @param archetypeCatalog
120      * @param serializer
121      * @param tagName
122      * @throws java.io.IOException
123      */
124     private void writeArchetypeCatalog( ArchetypeCatalog archetypeCatalog, String tagName, XmlSerializer serializer )
125         throws java.io.IOException
126     {
127         serializer.setPrefix( "", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0" );
128         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
129         serializer.startTag( NAMESPACE, tagName );
130         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd" );
131         if ( ( archetypeCatalog.getArchetypes() != null ) && ( archetypeCatalog.getArchetypes().size() > 0 ) )
132         {
133             serializer.startTag( NAMESPACE, "archetypes" );
134             for ( Iterator iter = archetypeCatalog.getArchetypes().iterator(); iter.hasNext(); )
135             {
136                 Archetype o = (Archetype) iter.next();
137                 writeArchetype( o, "archetype", serializer );
138             }
139             serializer.endTag( NAMESPACE, "archetypes" );
140         }
141         serializer.endTag( NAMESPACE, tagName );
142     } //-- void writeArchetypeCatalog( ArchetypeCatalog, String, XmlSerializer )
143 
144 }