View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.1.2,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.profiles.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.profiles.Activation;
16  import org.apache.maven.profiles.ActivationFile;
17  import org.apache.maven.profiles.ActivationOS;
18  import org.apache.maven.profiles.ActivationProperty;
19  import org.apache.maven.profiles.Profile;
20  import org.apache.maven.profiles.ProfilesRoot;
21  import org.apache.maven.profiles.Repository;
22  import org.apache.maven.profiles.RepositoryBase;
23  import org.apache.maven.profiles.RepositoryPolicy;
24  import org.codehaus.plexus.util.xml.pull.MXSerializer;
25  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
26  
27  /**
28   * Class ProfilesXpp3Writer.
29   * 
30   * @version $Revision$ $Date$
31   */
32  @SuppressWarnings( "all" )
33  public class ProfilesXpp3Writer
34  {
35  
36        //--------------------------/
37       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * Field NAMESPACE.
42       */
43      private static final String NAMESPACE = null;
44  
45      /**
46       * Field fileComment.
47       */
48      private String fileComment = null;
49  
50  
51        //-----------/
52       //- Methods -/
53      //-----------/
54  
55      /**
56       * Method setFileComment.
57       * 
58       * @param fileComment a fileComment object.
59       */
60      public void setFileComment( String fileComment )
61      {
62          this.fileComment = fileComment;
63      } //-- void setFileComment( String )
64  
65      /**
66       * Method write.
67       * 
68       * @param writer a writer object.
69       * @param profilesRoot a profilesRoot object.
70       * @throws java.io.IOException java.io.IOException if any.
71       */
72      public void write( Writer writer, ProfilesRoot profilesRoot )
73          throws java.io.IOException
74      {
75          XmlSerializer serializer = new MXSerializer();
76          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
77          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
78          serializer.setOutput( writer );
79          serializer.startDocument( profilesRoot.getModelEncoding(), null );
80          writeProfilesRoot( profilesRoot, "profilesXml", serializer );
81          serializer.endDocument();
82      } //-- void write( Writer, ProfilesRoot )
83  
84      /**
85       * Method write.
86       * 
87       * @param stream a stream object.
88       * @param profilesRoot a profilesRoot object.
89       * @throws java.io.IOException java.io.IOException if any.
90       */
91      public void write( OutputStream stream, ProfilesRoot profilesRoot )
92          throws java.io.IOException
93      {
94          XmlSerializer serializer = new MXSerializer();
95          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
96          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
97          serializer.setOutput( stream, profilesRoot.getModelEncoding() );
98          serializer.startDocument( profilesRoot.getModelEncoding(), null );
99          writeProfilesRoot( profilesRoot, "profilesXml", serializer );
100         serializer.endDocument();
101     } //-- void write( OutputStream, ProfilesRoot )
102 
103     /**
104      * Method writeActivation.
105      * 
106      * @param activation a activation object.
107      * @param serializer a serializer object.
108      * @param tagName a tagName object.
109      * @throws java.io.IOException java.io.IOException if any.
110      */
111     private void writeActivation( Activation activation, String tagName, XmlSerializer serializer )
112         throws java.io.IOException
113     {
114         serializer.startTag( NAMESPACE, tagName );
115         if ( activation.isActiveByDefault() != false )
116         {
117             serializer.startTag( NAMESPACE, "activeByDefault" ).text( String.valueOf( activation.isActiveByDefault() ) ).endTag( NAMESPACE, "activeByDefault" );
118         }
119         if ( activation.getJdk() != null )
120         {
121             serializer.startTag( NAMESPACE, "jdk" ).text( activation.getJdk() ).endTag( NAMESPACE, "jdk" );
122         }
123         if ( activation.getOs() != null )
124         {
125             writeActivationOS( (ActivationOS) activation.getOs(), "os", serializer );
126         }
127         if ( activation.getProperty() != null )
128         {
129             writeActivationProperty( (ActivationProperty) activation.getProperty(), "property", serializer );
130         }
131         if ( activation.getFile() != null )
132         {
133             writeActivationFile( (ActivationFile) activation.getFile(), "file", serializer );
134         }
135         serializer.endTag( NAMESPACE, tagName );
136     } //-- void writeActivation( Activation, String, XmlSerializer )
137 
138     /**
139      * Method writeActivationFile.
140      * 
141      * @param activationFile a activationFile object.
142      * @param serializer a serializer object.
143      * @param tagName a tagName object.
144      * @throws java.io.IOException java.io.IOException if any.
145      */
146     private void writeActivationFile( ActivationFile activationFile, String tagName, XmlSerializer serializer )
147         throws java.io.IOException
148     {
149         serializer.startTag( NAMESPACE, tagName );
150         if ( activationFile.getMissing() != null )
151         {
152             serializer.startTag( NAMESPACE, "missing" ).text( activationFile.getMissing() ).endTag( NAMESPACE, "missing" );
153         }
154         if ( activationFile.getExists() != null )
155         {
156             serializer.startTag( NAMESPACE, "exists" ).text( activationFile.getExists() ).endTag( NAMESPACE, "exists" );
157         }
158         serializer.endTag( NAMESPACE, tagName );
159     } //-- void writeActivationFile( ActivationFile, String, XmlSerializer )
160 
161     /**
162      * Method writeActivationOS.
163      * 
164      * @param activationOS a activationOS object.
165      * @param serializer a serializer object.
166      * @param tagName a tagName object.
167      * @throws java.io.IOException java.io.IOException if any.
168      */
169     private void writeActivationOS( ActivationOS activationOS, String tagName, XmlSerializer serializer )
170         throws java.io.IOException
171     {
172         serializer.startTag( NAMESPACE, tagName );
173         if ( activationOS.getName() != null )
174         {
175             serializer.startTag( NAMESPACE, "name" ).text( activationOS.getName() ).endTag( NAMESPACE, "name" );
176         }
177         if ( activationOS.getFamily() != null )
178         {
179             serializer.startTag( NAMESPACE, "family" ).text( activationOS.getFamily() ).endTag( NAMESPACE, "family" );
180         }
181         if ( activationOS.getArch() != null )
182         {
183             serializer.startTag( NAMESPACE, "arch" ).text( activationOS.getArch() ).endTag( NAMESPACE, "arch" );
184         }
185         if ( activationOS.getVersion() != null )
186         {
187             serializer.startTag( NAMESPACE, "version" ).text( activationOS.getVersion() ).endTag( NAMESPACE, "version" );
188         }
189         serializer.endTag( NAMESPACE, tagName );
190     } //-- void writeActivationOS( ActivationOS, String, XmlSerializer )
191 
192     /**
193      * Method writeActivationProperty.
194      * 
195      * @param activationProperty a activationProperty object.
196      * @param serializer a serializer object.
197      * @param tagName a tagName object.
198      * @throws java.io.IOException java.io.IOException if any.
199      */
200     private void writeActivationProperty( ActivationProperty activationProperty, String tagName, XmlSerializer serializer )
201         throws java.io.IOException
202     {
203         serializer.startTag( NAMESPACE, tagName );
204         if ( activationProperty.getName() != null )
205         {
206             serializer.startTag( NAMESPACE, "name" ).text( activationProperty.getName() ).endTag( NAMESPACE, "name" );
207         }
208         if ( activationProperty.getValue() != null )
209         {
210             serializer.startTag( NAMESPACE, "value" ).text( activationProperty.getValue() ).endTag( NAMESPACE, "value" );
211         }
212         serializer.endTag( NAMESPACE, tagName );
213     } //-- void writeActivationProperty( ActivationProperty, String, XmlSerializer )
214 
215     /**
216      * Method writeProfile.
217      * 
218      * @param profile a profile object.
219      * @param serializer a serializer object.
220      * @param tagName a tagName object.
221      * @throws java.io.IOException java.io.IOException if any.
222      */
223     private void writeProfile( Profile profile, String tagName, XmlSerializer serializer )
224         throws java.io.IOException
225     {
226         serializer.startTag( NAMESPACE, tagName );
227         if ( profile.getId() != null )
228         {
229             serializer.startTag( NAMESPACE, "id" ).text( profile.getId() ).endTag( NAMESPACE, "id" );
230         }
231         if ( profile.getActivation() != null )
232         {
233             writeActivation( (Activation) profile.getActivation(), "activation", serializer );
234         }
235         if ( ( profile.getProperties() != null ) && ( profile.getProperties().size() > 0 ) )
236         {
237             serializer.startTag( NAMESPACE, "properties" );
238             for ( Iterator iter = profile.getProperties().keySet().iterator(); iter.hasNext(); )
239             {
240                 String key = (String) iter.next();
241                 String value = (String) profile.getProperties().get( key );
242                 serializer.startTag( NAMESPACE, key ).text( value ).endTag( NAMESPACE, key );
243             }
244             serializer.endTag( NAMESPACE, "properties" );
245         }
246         if ( ( profile.getRepositories() != null ) && ( profile.getRepositories().size() > 0 ) )
247         {
248             serializer.startTag( NAMESPACE, "repositories" );
249             for ( Iterator iter = profile.getRepositories().iterator(); iter.hasNext(); )
250             {
251                 Repository o = (Repository) iter.next();
252                 writeRepository( o, "repository", serializer );
253             }
254             serializer.endTag( NAMESPACE, "repositories" );
255         }
256         if ( ( profile.getPluginRepositories() != null ) && ( profile.getPluginRepositories().size() > 0 ) )
257         {
258             serializer.startTag( NAMESPACE, "pluginRepositories" );
259             for ( Iterator iter = profile.getPluginRepositories().iterator(); iter.hasNext(); )
260             {
261                 Repository o = (Repository) iter.next();
262                 writeRepository( o, "pluginRepository", serializer );
263             }
264             serializer.endTag( NAMESPACE, "pluginRepositories" );
265         }
266         serializer.endTag( NAMESPACE, tagName );
267     } //-- void writeProfile( Profile, String, XmlSerializer )
268 
269     /**
270      * Method writeProfilesRoot.
271      * 
272      * @param profilesRoot a profilesRoot object.
273      * @param serializer a serializer object.
274      * @param tagName a tagName object.
275      * @throws java.io.IOException java.io.IOException if any.
276      */
277     private void writeProfilesRoot( ProfilesRoot profilesRoot, String tagName, XmlSerializer serializer )
278         throws java.io.IOException
279     {
280         if ( this.fileComment != null )
281         {
282         serializer.comment(this.fileComment);
283         }
284         serializer.setPrefix( "", "http://maven.apache.org/PROFILES/1.0.0" );
285         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
286         serializer.startTag( NAMESPACE, tagName );
287         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
288         if ( ( profilesRoot.getProfiles() != null ) && ( profilesRoot.getProfiles().size() > 0 ) )
289         {
290             serializer.startTag( NAMESPACE, "profiles" );
291             for ( Iterator iter = profilesRoot.getProfiles().iterator(); iter.hasNext(); )
292             {
293                 Profile o = (Profile) iter.next();
294                 writeProfile( o, "profile", serializer );
295             }
296             serializer.endTag( NAMESPACE, "profiles" );
297         }
298         if ( ( profilesRoot.getActiveProfiles() != null ) && ( profilesRoot.getActiveProfiles().size() > 0 ) )
299         {
300             serializer.startTag( NAMESPACE, "activeProfiles" );
301             for ( Iterator iter = profilesRoot.getActiveProfiles().iterator(); iter.hasNext(); )
302             {
303                 String activeProfile = (String) iter.next();
304                 serializer.startTag( NAMESPACE, "activeProfile" ).text( activeProfile ).endTag( NAMESPACE, "activeProfile" );
305             }
306             serializer.endTag( NAMESPACE, "activeProfiles" );
307         }
308         serializer.endTag( NAMESPACE, tagName );
309     } //-- void writeProfilesRoot( ProfilesRoot, String, XmlSerializer )
310 
311     /**
312      * Method writeRepository.
313      * 
314      * @param repository a repository object.
315      * @param serializer a serializer object.
316      * @param tagName a tagName object.
317      * @throws java.io.IOException java.io.IOException if any.
318      */
319     private void writeRepository( Repository repository, String tagName, XmlSerializer serializer )
320         throws java.io.IOException
321     {
322         serializer.startTag( NAMESPACE, tagName );
323         if ( repository.getReleases() != null )
324         {
325             writeRepositoryPolicy( (RepositoryPolicy) repository.getReleases(), "releases", serializer );
326         }
327         if ( repository.getSnapshots() != null )
328         {
329             writeRepositoryPolicy( (RepositoryPolicy) repository.getSnapshots(), "snapshots", serializer );
330         }
331         if ( repository.getId() != null )
332         {
333             serializer.startTag( NAMESPACE, "id" ).text( repository.getId() ).endTag( NAMESPACE, "id" );
334         }
335         if ( repository.getName() != null )
336         {
337             serializer.startTag( NAMESPACE, "name" ).text( repository.getName() ).endTag( NAMESPACE, "name" );
338         }
339         if ( repository.getUrl() != null )
340         {
341             serializer.startTag( NAMESPACE, "url" ).text( repository.getUrl() ).endTag( NAMESPACE, "url" );
342         }
343         if ( ( repository.getLayout() != null ) && !repository.getLayout().equals( "default" ) )
344         {
345             serializer.startTag( NAMESPACE, "layout" ).text( repository.getLayout() ).endTag( NAMESPACE, "layout" );
346         }
347         serializer.endTag( NAMESPACE, tagName );
348     } //-- void writeRepository( Repository, String, XmlSerializer )
349 
350     /**
351      * Method writeRepositoryBase.
352      * 
353      * @param repositoryBase a repositoryBase object.
354      * @param serializer a serializer object.
355      * @param tagName a tagName object.
356      * @throws java.io.IOException java.io.IOException if any.
357      */
358     private void writeRepositoryBase( RepositoryBase repositoryBase, String tagName, XmlSerializer serializer )
359         throws java.io.IOException
360     {
361         serializer.startTag( NAMESPACE, tagName );
362         if ( repositoryBase.getId() != null )
363         {
364             serializer.startTag( NAMESPACE, "id" ).text( repositoryBase.getId() ).endTag( NAMESPACE, "id" );
365         }
366         if ( repositoryBase.getName() != null )
367         {
368             serializer.startTag( NAMESPACE, "name" ).text( repositoryBase.getName() ).endTag( NAMESPACE, "name" );
369         }
370         if ( repositoryBase.getUrl() != null )
371         {
372             serializer.startTag( NAMESPACE, "url" ).text( repositoryBase.getUrl() ).endTag( NAMESPACE, "url" );
373         }
374         if ( ( repositoryBase.getLayout() != null ) && !repositoryBase.getLayout().equals( "default" ) )
375         {
376             serializer.startTag( NAMESPACE, "layout" ).text( repositoryBase.getLayout() ).endTag( NAMESPACE, "layout" );
377         }
378         serializer.endTag( NAMESPACE, tagName );
379     } //-- void writeRepositoryBase( RepositoryBase, String, XmlSerializer )
380 
381     /**
382      * Method writeRepositoryPolicy.
383      * 
384      * @param repositoryPolicy a repositoryPolicy object.
385      * @param serializer a serializer object.
386      * @param tagName a tagName object.
387      * @throws java.io.IOException java.io.IOException if any.
388      */
389     private void writeRepositoryPolicy( RepositoryPolicy repositoryPolicy, String tagName, XmlSerializer serializer )
390         throws java.io.IOException
391     {
392         serializer.startTag( NAMESPACE, tagName );
393         if ( repositoryPolicy.isEnabled() != true )
394         {
395             serializer.startTag( NAMESPACE, "enabled" ).text( String.valueOf( repositoryPolicy.isEnabled() ) ).endTag( NAMESPACE, "enabled" );
396         }
397         if ( repositoryPolicy.getUpdatePolicy() != null )
398         {
399             serializer.startTag( NAMESPACE, "updatePolicy" ).text( repositoryPolicy.getUpdatePolicy() ).endTag( NAMESPACE, "updatePolicy" );
400         }
401         if ( repositoryPolicy.getChecksumPolicy() != null )
402         {
403             serializer.startTag( NAMESPACE, "checksumPolicy" ).text( repositoryPolicy.getChecksumPolicy() ).endTag( NAMESPACE, "checksumPolicy" );
404         }
405         serializer.endTag( NAMESPACE, tagName );
406     } //-- void writeRepositoryPolicy( RepositoryPolicy, String, XmlSerializer )
407 
408 }