View Javadoc
1   /*
2    Licensed to the Apache Software Foundation (ASF) under one
3    or more contributor license agreements.  See the NOTICE file
4    distributed with this work for additional information
5    regarding copyright ownership.  The ASF licenses this file
6    to you under the Apache License, Version 2.0 (the
7    "License"); you may not use this file except in compliance
8    with the License.  You may obtain a copy of the License at
9    
10       http://www.apache.org/licenses/LICENSE-2.0
11   
12   Unless required by applicable law or agreed to in writing,
13   software distributed under the License is distributed on an
14   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   KIND, either express or implied.  See the License for the
16   specific language governing permissions and limitations
17   under the License.
18   =================== DO NOT EDIT THIS FILE ====================
19   Generated by Modello 2.4.0,
20   any modifications will be overwritten.
21   ==============================================================
22   */
23  
24  package org.apache.maven.archetype.catalog.io.xpp3;
25  
26    //---------------------------------/
27   //- Imported classes and packages -/
28  //---------------------------------/
29  
30  import java.io.OutputStream;
31  import java.io.Writer;
32  import java.util.Iterator;
33  import org.apache.maven.archetype.catalog.Archetype;
34  import org.apache.maven.archetype.catalog.ArchetypeCatalog;
35  import org.codehaus.plexus.util.xml.pull.MXSerializer;
36  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
37  
38  /**
39   * Class ArchetypeCatalogXpp3Writer.
40   * 
41   * @version $Revision$ $Date$
42   */
43  @SuppressWarnings( "all" )
44  public class ArchetypeCatalogXpp3Writer
45  {
46  
47        //--------------------------/
48       //- Class/Member Variables -/
49      //--------------------------/
50  
51      /**
52       * Field NAMESPACE.
53       */
54      private static final String NAMESPACE = null;
55  
56      /**
57       * Field fileComment.
58       */
59      private String fileComment = null;
60  
61  
62        //-----------/
63       //- Methods -/
64      //-----------/
65  
66      /**
67       * Method setFileComment.
68       * 
69       * @param fileComment a fileComment object.
70       */
71      public void setFileComment( String fileComment )
72      {
73          this.fileComment = fileComment;
74      } //-- void setFileComment( String )
75  
76      /**
77       * Method write.
78       * 
79       * @param writer a writer object.
80       * @param archetypeCatalog a archetypeCatalog object.
81       * @throws java.io.IOException java.io.IOException if any.
82       */
83      public void write( Writer writer, ArchetypeCatalog archetypeCatalog )
84          throws java.io.IOException
85      {
86          XmlSerializer serializer = new MXSerializer();
87          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
88          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
89          serializer.setOutput( writer );
90          serializer.startDocument( archetypeCatalog.getModelEncoding(), null );
91          writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer );
92          serializer.endDocument();
93      } //-- void write( Writer, ArchetypeCatalog )
94  
95      /**
96       * Method write.
97       * 
98       * @param stream a stream object.
99       * @param archetypeCatalog a archetypeCatalog object.
100      * @throws java.io.IOException java.io.IOException if any.
101      */
102     public void write( OutputStream stream, ArchetypeCatalog archetypeCatalog )
103         throws java.io.IOException
104     {
105         XmlSerializer serializer = new MXSerializer();
106         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
107         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
108         serializer.setOutput( stream, archetypeCatalog.getModelEncoding() );
109         serializer.startDocument( archetypeCatalog.getModelEncoding(), null );
110         writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer );
111         serializer.endDocument();
112     } //-- void write( OutputStream, ArchetypeCatalog )
113 
114     /**
115      * Method writeArchetype.
116      * 
117      * @param archetype a archetype object.
118      * @param serializer a serializer object.
119      * @param tagName a tagName object.
120      * @throws java.io.IOException java.io.IOException if any.
121      */
122     private void writeArchetype( Archetype archetype, String tagName, XmlSerializer serializer )
123         throws java.io.IOException
124     {
125         serializer.startTag( NAMESPACE, tagName );
126         if ( archetype.getGroupId() != null )
127         {
128             serializer.startTag( NAMESPACE, "groupId" ).text( archetype.getGroupId() ).endTag( NAMESPACE, "groupId" );
129         }
130         if ( archetype.getArtifactId() != null )
131         {
132             serializer.startTag( NAMESPACE, "artifactId" ).text( archetype.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
133         }
134         if ( archetype.getVersion() != null )
135         {
136             serializer.startTag( NAMESPACE, "version" ).text( archetype.getVersion() ).endTag( NAMESPACE, "version" );
137         }
138         if ( archetype.getRepository() != null )
139         {
140             serializer.startTag( NAMESPACE, "repository" ).text( archetype.getRepository() ).endTag( NAMESPACE, "repository" );
141         }
142         if ( archetype.getDescription() != null )
143         {
144             serializer.startTag( NAMESPACE, "description" ).text( archetype.getDescription() ).endTag( NAMESPACE, "description" );
145         }
146         serializer.endTag( NAMESPACE, tagName );
147     } //-- void writeArchetype( Archetype, String, XmlSerializer )
148 
149     /**
150      * Method writeArchetypeCatalog.
151      * 
152      * @param archetypeCatalog a archetypeCatalog object.
153      * @param serializer a serializer object.
154      * @param tagName a tagName object.
155      * @throws java.io.IOException java.io.IOException if any.
156      */
157     private void writeArchetypeCatalog( ArchetypeCatalog archetypeCatalog, String tagName, XmlSerializer serializer )
158         throws java.io.IOException
159     {
160         if ( this.fileComment != null )
161         {
162         serializer.comment(this.fileComment);
163         }
164         serializer.setPrefix( "", "https://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0" );
165         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
166         serializer.startTag( NAMESPACE, tagName );
167         serializer.attribute( "", "xsi:schemaLocation", "https://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 https://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd" );
168         if ( ( archetypeCatalog.getArchetypes() != null ) && ( archetypeCatalog.getArchetypes().size() > 0 ) )
169         {
170             serializer.startTag( NAMESPACE, "archetypes" );
171             for ( Iterator iter = archetypeCatalog.getArchetypes().iterator(); iter.hasNext(); )
172             {
173                 Archetype o = (Archetype) iter.next();
174                 writeArchetype( o, "archetype", serializer );
175             }
176             serializer.endTag( NAMESPACE, "archetypes" );
177         }
178         serializer.endTag( NAMESPACE, tagName );
179     } //-- void writeArchetypeCatalog( ArchetypeCatalog, String, XmlSerializer )
180 
181 }