View Javadoc

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