View Javadoc

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