View Javadoc

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