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