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.model.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.model.ArchetypeModel;
16  import org.apache.maven.archetype.model.Resource;
17  import org.apache.maven.archetype.model.Source;
18  import org.codehaus.plexus.util.xml.pull.MXSerializer;
19  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
20  
21  /**
22   * Class ArchetypeXpp3Writer.
23   * 
24   * @version $Revision: 942523 $ $Date: 2015-03-06 01:20:33 +0100 (Fri, 06 Mar 2015) $
25   */
26  @SuppressWarnings( "all" )
27  public class ArchetypeXpp3Writer
28  {
29  
30        //--------------------------/
31       //- Class/Member Variables -/
32      //--------------------------/
33  
34      /**
35       * Field NAMESPACE.
36       */
37      private static final String NAMESPACE = null;
38  
39  
40        //-----------/
41       //- Methods -/
42      //-----------/
43  
44      /**
45       * Method write.
46       * 
47       * @param writer
48       * @param archetypeModel
49       * @throws java.io.IOException
50       */
51      public void write( Writer writer, ArchetypeModel archetypeModel )
52          throws java.io.IOException
53      {
54          XmlSerializer serializer = new MXSerializer();
55          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
56          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
57          serializer.setOutput( writer );
58          serializer.startDocument( archetypeModel.getModelEncoding(), null );
59          writeArchetypeModel( archetypeModel, "archetype", serializer );
60          serializer.endDocument();
61      } //-- void write( Writer, ArchetypeModel )
62  
63      /**
64       * Method write.
65       * 
66       * @param stream
67       * @param archetypeModel
68       * @throws java.io.IOException
69       */
70      public void write( OutputStream stream, ArchetypeModel archetypeModel )
71          throws java.io.IOException
72      {
73          XmlSerializer serializer = new MXSerializer();
74          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
75          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
76          serializer.setOutput( stream, archetypeModel.getModelEncoding() );
77          serializer.startDocument( archetypeModel.getModelEncoding(), null );
78          writeArchetypeModel( archetypeModel, "archetype", serializer );
79          serializer.endDocument();
80      } //-- void write( OutputStream, ArchetypeModel )
81  
82      /**
83       * Method writeArchetypeModel.
84       * 
85       * @param archetypeModel
86       * @param serializer
87       * @param tagName
88       * @throws java.io.IOException
89       */
90      private void writeArchetypeModel( ArchetypeModel archetypeModel, String tagName, XmlSerializer serializer )
91          throws java.io.IOException
92      {
93          serializer.setPrefix( "", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" );
94          serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
95          serializer.startTag( NAMESPACE, tagName );
96          serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd" );
97          if ( archetypeModel.getId() != null )
98          {
99              serializer.startTag( NAMESPACE, "id" ).text( archetypeModel.getId() ).endTag( NAMESPACE, "id" );
100         }
101         if ( archetypeModel.isAllowPartial() != false )
102         {
103             serializer.startTag( NAMESPACE, "allowPartial" ).text( String.valueOf( archetypeModel.isAllowPartial() ) ).endTag( NAMESPACE, "allowPartial" );
104         }
105         if ( ( archetypeModel.getSources() != null ) && ( archetypeModel.getSources().size() > 0 ) )
106         {
107             serializer.startTag( NAMESPACE, "sources" );
108             for ( Iterator iter = archetypeModel.getSources().iterator(); iter.hasNext(); )
109             {
110                 Source o = (Source) iter.next();
111                 writeSource( o, "source", serializer );
112             }
113             serializer.endTag( NAMESPACE, "sources" );
114         }
115         if ( ( archetypeModel.getResources() != null ) && ( archetypeModel.getResources().size() > 0 ) )
116         {
117             serializer.startTag( NAMESPACE, "resources" );
118             for ( Iterator iter = archetypeModel.getResources().iterator(); iter.hasNext(); )
119             {
120                 Resource o = (Resource) iter.next();
121                 writeResource( o, "resource", serializer );
122             }
123             serializer.endTag( NAMESPACE, "resources" );
124         }
125         if ( ( archetypeModel.getTestSources() != null ) && ( archetypeModel.getTestSources().size() > 0 ) )
126         {
127             serializer.startTag( NAMESPACE, "testSources" );
128             for ( Iterator iter = archetypeModel.getTestSources().iterator(); iter.hasNext(); )
129             {
130                 Source o = (Source) iter.next();
131                 writeSource( o, "source", serializer );
132             }
133             serializer.endTag( NAMESPACE, "testSources" );
134         }
135         if ( ( archetypeModel.getTestResources() != null ) && ( archetypeModel.getTestResources().size() > 0 ) )
136         {
137             serializer.startTag( NAMESPACE, "testResources" );
138             for ( Iterator iter = archetypeModel.getTestResources().iterator(); iter.hasNext(); )
139             {
140                 Resource o = (Resource) iter.next();
141                 writeResource( o, "resource", serializer );
142             }
143             serializer.endTag( NAMESPACE, "testResources" );
144         }
145         if ( ( archetypeModel.getSiteResources() != null ) && ( archetypeModel.getSiteResources().size() > 0 ) )
146         {
147             serializer.startTag( NAMESPACE, "siteResources" );
148             for ( Iterator iter = archetypeModel.getSiteResources().iterator(); iter.hasNext(); )
149             {
150                 Resource o = (Resource) iter.next();
151                 writeResource( o, "resource", serializer );
152             }
153             serializer.endTag( NAMESPACE, "siteResources" );
154         }
155         serializer.endTag( NAMESPACE, tagName );
156     } //-- void writeArchetypeModel( ArchetypeModel, String, XmlSerializer )
157 
158     /**
159      * Method writeResource.
160      * 
161      * @param resource
162      * @param serializer
163      * @param tagName
164      * @throws java.io.IOException
165      */
166     private void writeResource( Resource resource, String tagName, XmlSerializer serializer )
167         throws java.io.IOException
168     {
169         serializer.startTag( NAMESPACE, tagName );
170         if ( resource.getEncoding() != null )
171         {
172             serializer.attribute( NAMESPACE, "encoding", resource.getEncoding() );
173         }
174         if ( resource.isFiltered() != true )
175         {
176             serializer.attribute( NAMESPACE, "filtered", String.valueOf( resource.isFiltered() ) );
177         }
178         serializer.text( resource.getFile() );
179         serializer.endTag( NAMESPACE, tagName );
180     } //-- void writeResource( Resource, String, XmlSerializer )
181 
182     /**
183      * Method writeSource.
184      * 
185      * @param source
186      * @param serializer
187      * @param tagName
188      * @throws java.io.IOException
189      */
190     private void writeSource( Source source, String tagName, XmlSerializer serializer )
191         throws java.io.IOException
192     {
193         serializer.startTag( NAMESPACE, tagName );
194         if ( source.getEncoding() != null )
195         {
196             serializer.attribute( NAMESPACE, "encoding", source.getEncoding() );
197         }
198         serializer.text( source.getFile() );
199         serializer.endTag( NAMESPACE, tagName );
200     } //-- void writeSource( Source, String, XmlSerializer )
201 
202 }