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.metadata.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.metadata.AbstractArchetypeDescriptor;
34  import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
35  import org.apache.maven.archetype.metadata.FileSet;
36  import org.apache.maven.archetype.metadata.ModuleDescriptor;
37  import org.apache.maven.archetype.metadata.RequiredProperty;
38  import org.codehaus.plexus.util.xml.pull.MXSerializer;
39  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
40  
41  /**
42   * Class ArchetypeDescriptorXpp3Writer.
43   * 
44   * @version $Revision$ $Date$
45   */
46  @SuppressWarnings( "all" )
47  public class ArchetypeDescriptorXpp3Writer
48  {
49  
50        //--------------------------/
51       //- Class/Member Variables -/
52      //--------------------------/
53  
54      /**
55       * Field NAMESPACE.
56       */
57      private static final String NAMESPACE = null;
58  
59      /**
60       * Field fileComment.
61       */
62      private String fileComment = null;
63  
64  
65        //-----------/
66       //- Methods -/
67      //-----------/
68  
69      /**
70       * Method setFileComment.
71       * 
72       * @param fileComment a fileComment object.
73       */
74      public void setFileComment( String fileComment )
75      {
76          this.fileComment = fileComment;
77      } //-- void setFileComment( String )
78  
79      /**
80       * Method write.
81       * 
82       * @param writer a writer object.
83       * @param archetypeDescriptor a archetypeDescriptor object.
84       * @throws java.io.IOException java.io.IOException if any.
85       */
86      public void write( Writer writer, ArchetypeDescriptor archetypeDescriptor )
87          throws java.io.IOException
88      {
89          XmlSerializer serializer = new MXSerializer();
90          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
91          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
92          serializer.setOutput( writer );
93          serializer.startDocument( archetypeDescriptor.getModelEncoding(), null );
94          writeArchetypeDescriptor( archetypeDescriptor, "archetype-descriptor", serializer );
95          serializer.endDocument();
96      } //-- void write( Writer, ArchetypeDescriptor )
97  
98      /**
99       * Method write.
100      * 
101      * @param stream a stream object.
102      * @param archetypeDescriptor a archetypeDescriptor object.
103      * @throws java.io.IOException java.io.IOException if any.
104      */
105     public void write( OutputStream stream, ArchetypeDescriptor archetypeDescriptor )
106         throws java.io.IOException
107     {
108         XmlSerializer serializer = new MXSerializer();
109         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
110         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
111         serializer.setOutput( stream, archetypeDescriptor.getModelEncoding() );
112         serializer.startDocument( archetypeDescriptor.getModelEncoding(), null );
113         writeArchetypeDescriptor( archetypeDescriptor, "archetype-descriptor", serializer );
114         serializer.endDocument();
115     } //-- void write( OutputStream, ArchetypeDescriptor )
116 
117     /**
118      * Method writeAbstractArchetypeDescriptor.
119      * 
120      * @param abstractArchetypeDescriptor a
121      * abstractArchetypeDescriptor object.
122      * @param serializer a serializer object.
123      * @param tagName a tagName object.
124      * @throws java.io.IOException java.io.IOException if any.
125      */
126     private void writeAbstractArchetypeDescriptor( AbstractArchetypeDescriptor abstractArchetypeDescriptor, String tagName, XmlSerializer serializer )
127         throws java.io.IOException
128     {
129         serializer.startTag( NAMESPACE, tagName );
130         if ( ( abstractArchetypeDescriptor.getFileSets() != null ) && ( abstractArchetypeDescriptor.getFileSets().size() > 0 ) )
131         {
132             serializer.startTag( NAMESPACE, "fileSets" );
133             for ( Iterator iter = abstractArchetypeDescriptor.getFileSets().iterator(); iter.hasNext(); )
134             {
135                 FileSet o = (FileSet) iter.next();
136                 writeFileSet( o, "fileSet", serializer );
137             }
138             serializer.endTag( NAMESPACE, "fileSets" );
139         }
140         if ( ( abstractArchetypeDescriptor.getModules() != null ) && ( abstractArchetypeDescriptor.getModules().size() > 0 ) )
141         {
142             serializer.startTag( NAMESPACE, "modules" );
143             for ( Iterator iter = abstractArchetypeDescriptor.getModules().iterator(); iter.hasNext(); )
144             {
145                 ModuleDescriptor o = (ModuleDescriptor) iter.next();
146                 writeModuleDescriptor( o, "module", serializer );
147             }
148             serializer.endTag( NAMESPACE, "modules" );
149         }
150         serializer.endTag( NAMESPACE, tagName );
151     } //-- void writeAbstractArchetypeDescriptor( AbstractArchetypeDescriptor, String, XmlSerializer )
152 
153     /**
154      * Method writeArchetypeDescriptor.
155      * 
156      * @param archetypeDescriptor a archetypeDescriptor object.
157      * @param serializer a serializer object.
158      * @param tagName a tagName object.
159      * @throws java.io.IOException java.io.IOException if any.
160      */
161     private void writeArchetypeDescriptor( ArchetypeDescriptor archetypeDescriptor, String tagName, XmlSerializer serializer )
162         throws java.io.IOException
163     {
164         if ( this.fileComment != null )
165         {
166         serializer.comment(this.fileComment);
167         }
168         serializer.setPrefix( "", "https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.2.0" );
169         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
170         serializer.startTag( NAMESPACE, tagName );
171         serializer.attribute( "", "xsi:schemaLocation", "https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.2.0 https://maven.apache.org/xsd/archetype-descriptor-1.2.0.xsd" );
172         if ( archetypeDescriptor.getName() != null )
173         {
174             serializer.attribute( NAMESPACE, "name", archetypeDescriptor.getName() );
175         }
176         if ( archetypeDescriptor.isPartial() != false )
177         {
178             serializer.attribute( NAMESPACE, "partial", String.valueOf( archetypeDescriptor.isPartial() ) );
179         }
180         if ( ( archetypeDescriptor.getRequiredProperties() != null ) && ( archetypeDescriptor.getRequiredProperties().size() > 0 ) )
181         {
182             serializer.startTag( NAMESPACE, "requiredProperties" );
183             for ( Iterator iter = archetypeDescriptor.getRequiredProperties().iterator(); iter.hasNext(); )
184             {
185                 RequiredProperty o = (RequiredProperty) iter.next();
186                 writeRequiredProperty( o, "requiredProperty", serializer );
187             }
188             serializer.endTag( NAMESPACE, "requiredProperties" );
189         }
190         if ( ( archetypeDescriptor.getFileSets() != null ) && ( archetypeDescriptor.getFileSets().size() > 0 ) )
191         {
192             serializer.startTag( NAMESPACE, "fileSets" );
193             for ( Iterator iter = archetypeDescriptor.getFileSets().iterator(); iter.hasNext(); )
194             {
195                 FileSet o = (FileSet) iter.next();
196                 writeFileSet( o, "fileSet", serializer );
197             }
198             serializer.endTag( NAMESPACE, "fileSets" );
199         }
200         if ( ( archetypeDescriptor.getModules() != null ) && ( archetypeDescriptor.getModules().size() > 0 ) )
201         {
202             serializer.startTag( NAMESPACE, "modules" );
203             for ( Iterator iter = archetypeDescriptor.getModules().iterator(); iter.hasNext(); )
204             {
205                 ModuleDescriptor o = (ModuleDescriptor) iter.next();
206                 writeModuleDescriptor( o, "module", serializer );
207             }
208             serializer.endTag( NAMESPACE, "modules" );
209         }
210         serializer.endTag( NAMESPACE, tagName );
211     } //-- void writeArchetypeDescriptor( ArchetypeDescriptor, String, XmlSerializer )
212 
213     /**
214      * Method writeFileSet.
215      * 
216      * @param fileSet a fileSet object.
217      * @param serializer a serializer object.
218      * @param tagName a tagName object.
219      * @throws java.io.IOException java.io.IOException if any.
220      */
221     private void writeFileSet( FileSet fileSet, String tagName, XmlSerializer serializer )
222         throws java.io.IOException
223     {
224         serializer.startTag( NAMESPACE, tagName );
225         if ( fileSet.isFiltered() != false )
226         {
227             serializer.attribute( NAMESPACE, "filtered", String.valueOf( fileSet.isFiltered() ) );
228         }
229         if ( fileSet.isPackaged() != false )
230         {
231             serializer.attribute( NAMESPACE, "packaged", String.valueOf( fileSet.isPackaged() ) );
232         }
233         if ( fileSet.getEncoding() != null )
234         {
235             serializer.attribute( NAMESPACE, "encoding", fileSet.getEncoding() );
236         }
237         if ( fileSet.getIncludeCondition() != null )
238         {
239             serializer.attribute( NAMESPACE, "includeCondition", fileSet.getIncludeCondition() );
240         }
241         if ( ( fileSet.getDirectory() != null ) && !fileSet.getDirectory().equals( "" ) )
242         {
243             serializer.startTag( NAMESPACE, "directory" ).text( fileSet.getDirectory() ).endTag( NAMESPACE, "directory" );
244         }
245         if ( ( fileSet.getIncludes() != null ) && ( fileSet.getIncludes().size() > 0 ) )
246         {
247             serializer.startTag( NAMESPACE, "includes" );
248             for ( Iterator iter = fileSet.getIncludes().iterator(); iter.hasNext(); )
249             {
250                 String include = (String) iter.next();
251                 serializer.startTag( NAMESPACE, "include" ).text( include ).endTag( NAMESPACE, "include" );
252             }
253             serializer.endTag( NAMESPACE, "includes" );
254         }
255         if ( ( fileSet.getExcludes() != null ) && ( fileSet.getExcludes().size() > 0 ) )
256         {
257             serializer.startTag( NAMESPACE, "excludes" );
258             for ( Iterator iter = fileSet.getExcludes().iterator(); iter.hasNext(); )
259             {
260                 String exclude = (String) iter.next();
261                 serializer.startTag( NAMESPACE, "exclude" ).text( exclude ).endTag( NAMESPACE, "exclude" );
262             }
263             serializer.endTag( NAMESPACE, "excludes" );
264         }
265         serializer.endTag( NAMESPACE, tagName );
266     } //-- void writeFileSet( FileSet, String, XmlSerializer )
267 
268     /**
269      * Method writeModuleDescriptor.
270      * 
271      * @param moduleDescriptor a moduleDescriptor object.
272      * @param serializer a serializer object.
273      * @param tagName a tagName object.
274      * @throws java.io.IOException java.io.IOException if any.
275      */
276     private void writeModuleDescriptor( ModuleDescriptor moduleDescriptor, String tagName, XmlSerializer serializer )
277         throws java.io.IOException
278     {
279         serializer.startTag( NAMESPACE, tagName );
280         if ( moduleDescriptor.getId() != null )
281         {
282             serializer.attribute( NAMESPACE, "id", moduleDescriptor.getId() );
283         }
284         if ( moduleDescriptor.getDir() != null )
285         {
286             serializer.attribute( NAMESPACE, "dir", moduleDescriptor.getDir() );
287         }
288         if ( moduleDescriptor.getName() != null )
289         {
290             serializer.attribute( NAMESPACE, "name", moduleDescriptor.getName() );
291         }
292         if ( ( moduleDescriptor.getFileSets() != null ) && ( moduleDescriptor.getFileSets().size() > 0 ) )
293         {
294             serializer.startTag( NAMESPACE, "fileSets" );
295             for ( Iterator iter = moduleDescriptor.getFileSets().iterator(); iter.hasNext(); )
296             {
297                 FileSet o = (FileSet) iter.next();
298                 writeFileSet( o, "fileSet", serializer );
299             }
300             serializer.endTag( NAMESPACE, "fileSets" );
301         }
302         if ( ( moduleDescriptor.getModules() != null ) && ( moduleDescriptor.getModules().size() > 0 ) )
303         {
304             serializer.startTag( NAMESPACE, "modules" );
305             for ( Iterator iter = moduleDescriptor.getModules().iterator(); iter.hasNext(); )
306             {
307                 ModuleDescriptor o = (ModuleDescriptor) iter.next();
308                 writeModuleDescriptor( o, "module", serializer );
309             }
310             serializer.endTag( NAMESPACE, "modules" );
311         }
312         serializer.endTag( NAMESPACE, tagName );
313     } //-- void writeModuleDescriptor( ModuleDescriptor, String, XmlSerializer )
314 
315     /**
316      * Method writeRequiredProperty.
317      * 
318      * @param requiredProperty a requiredProperty object.
319      * @param serializer a serializer object.
320      * @param tagName a tagName object.
321      * @throws java.io.IOException java.io.IOException if any.
322      */
323     private void writeRequiredProperty( RequiredProperty requiredProperty, String tagName, XmlSerializer serializer )
324         throws java.io.IOException
325     {
326         serializer.startTag( NAMESPACE, tagName );
327         if ( requiredProperty.getKey() != null )
328         {
329             serializer.attribute( NAMESPACE, "key", requiredProperty.getKey() );
330         }
331         if ( requiredProperty.getDefaultValue() != null )
332         {
333             serializer.startTag( NAMESPACE, "defaultValue" ).text( requiredProperty.getDefaultValue() ).endTag( NAMESPACE, "defaultValue" );
334         }
335         if ( requiredProperty.getValidationRegex() != null )
336         {
337             serializer.startTag( NAMESPACE, "validationRegex" ).text( requiredProperty.getValidationRegex() ).endTag( NAMESPACE, "validationRegex" );
338         }
339         serializer.endTag( NAMESPACE, tagName );
340     } //-- void writeRequiredProperty( RequiredProperty, String, XmlSerializer )
341 
342 }