View Javadoc

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