001    /*
002     =================== DO NOT EDIT THIS FILE ====================
003     Generated by Modello 1.4.1 on 2012-01-20 18:05:13,
004     any modifications will be overwritten.
005     ==============================================================
006     */
007    
008    package org.apache.maven.profiles.io.xpp3;
009    
010      //---------------------------------/
011     //- Imported classes and packages -/
012    //---------------------------------/
013    
014    import java.io.OutputStream;
015    import java.io.Writer;
016    import java.text.DateFormat;
017    import java.util.Iterator;
018    import java.util.Locale;
019    import org.apache.maven.profiles.Activation;
020    import org.apache.maven.profiles.ActivationFile;
021    import org.apache.maven.profiles.ActivationOS;
022    import org.apache.maven.profiles.ActivationProperty;
023    import org.apache.maven.profiles.Profile;
024    import org.apache.maven.profiles.ProfilesRoot;
025    import org.apache.maven.profiles.Repository;
026    import org.apache.maven.profiles.RepositoryBase;
027    import org.apache.maven.profiles.RepositoryPolicy;
028    import org.codehaus.plexus.util.xml.pull.MXSerializer;
029    import org.codehaus.plexus.util.xml.pull.XmlSerializer;
030    
031    /**
032     * Class ProfilesXpp3Writer.
033     * 
034     * @version $Revision$ $Date$
035     */
036    @SuppressWarnings( "all" )
037    public class ProfilesXpp3Writer
038    {
039    
040          //--------------------------/
041         //- Class/Member Variables -/
042        //--------------------------/
043    
044        /**
045         * Field NAMESPACE.
046         */
047        private static final String NAMESPACE = null;
048    
049    
050          //-----------/
051         //- Methods -/
052        //-----------/
053    
054        /**
055         * Method write.
056         * 
057         * @param writer
058         * @param profilesRoot
059         * @throws java.io.IOException
060         */
061        public void write( Writer writer, ProfilesRoot profilesRoot )
062            throws java.io.IOException
063        {
064            XmlSerializer serializer = new MXSerializer();
065            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
066            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
067            serializer.setOutput( writer );
068            serializer.startDocument( profilesRoot.getModelEncoding(), null );
069            writeProfilesRoot( profilesRoot, "profilesXml", serializer );
070            serializer.endDocument();
071        } //-- void write( Writer, ProfilesRoot )
072    
073        /**
074         * Method write.
075         * 
076         * @param stream
077         * @param profilesRoot
078         * @throws java.io.IOException
079         */
080        public void write( OutputStream stream, ProfilesRoot profilesRoot )
081            throws java.io.IOException
082        {
083            XmlSerializer serializer = new MXSerializer();
084            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
085            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
086            serializer.setOutput( stream, profilesRoot.getModelEncoding() );
087            serializer.startDocument( profilesRoot.getModelEncoding(), null );
088            writeProfilesRoot( profilesRoot, "profilesXml", serializer );
089            serializer.endDocument();
090        } //-- void write( OutputStream, ProfilesRoot )
091    
092        /**
093         * Method writeActivation.
094         * 
095         * @param activation
096         * @param serializer
097         * @param tagName
098         * @throws java.io.IOException
099         */
100        private void writeActivation( Activation activation, String tagName, XmlSerializer serializer )
101            throws java.io.IOException
102        {
103            serializer.startTag( NAMESPACE, tagName );
104            if ( activation.isActiveByDefault() != false )
105            {
106                serializer.startTag( NAMESPACE, "activeByDefault" ).text( String.valueOf( activation.isActiveByDefault() ) ).endTag( NAMESPACE, "activeByDefault" );
107            }
108            if ( activation.getJdk() != null )
109            {
110                serializer.startTag( NAMESPACE, "jdk" ).text( activation.getJdk() ).endTag( NAMESPACE, "jdk" );
111            }
112            if ( activation.getOs() != null )
113            {
114                writeActivationOS( (ActivationOS) activation.getOs(), "os", serializer );
115            }
116            if ( activation.getProperty() != null )
117            {
118                writeActivationProperty( (ActivationProperty) activation.getProperty(), "property", serializer );
119            }
120            if ( activation.getFile() != null )
121            {
122                writeActivationFile( (ActivationFile) activation.getFile(), "file", serializer );
123            }
124            serializer.endTag( NAMESPACE, tagName );
125        } //-- void writeActivation( Activation, String, XmlSerializer )
126    
127        /**
128         * Method writeActivationFile.
129         * 
130         * @param activationFile
131         * @param serializer
132         * @param tagName
133         * @throws java.io.IOException
134         */
135        private void writeActivationFile( ActivationFile activationFile, String tagName, XmlSerializer serializer )
136            throws java.io.IOException
137        {
138            serializer.startTag( NAMESPACE, tagName );
139            if ( activationFile.getMissing() != null )
140            {
141                serializer.startTag( NAMESPACE, "missing" ).text( activationFile.getMissing() ).endTag( NAMESPACE, "missing" );
142            }
143            if ( activationFile.getExists() != null )
144            {
145                serializer.startTag( NAMESPACE, "exists" ).text( activationFile.getExists() ).endTag( NAMESPACE, "exists" );
146            }
147            serializer.endTag( NAMESPACE, tagName );
148        } //-- void writeActivationFile( ActivationFile, String, XmlSerializer )
149    
150        /**
151         * Method writeActivationOS.
152         * 
153         * @param activationOS
154         * @param serializer
155         * @param tagName
156         * @throws java.io.IOException
157         */
158        private void writeActivationOS( ActivationOS activationOS, String tagName, XmlSerializer serializer )
159            throws java.io.IOException
160        {
161            serializer.startTag( NAMESPACE, tagName );
162            if ( activationOS.getName() != null )
163            {
164                serializer.startTag( NAMESPACE, "name" ).text( activationOS.getName() ).endTag( NAMESPACE, "name" );
165            }
166            if ( activationOS.getFamily() != null )
167            {
168                serializer.startTag( NAMESPACE, "family" ).text( activationOS.getFamily() ).endTag( NAMESPACE, "family" );
169            }
170            if ( activationOS.getArch() != null )
171            {
172                serializer.startTag( NAMESPACE, "arch" ).text( activationOS.getArch() ).endTag( NAMESPACE, "arch" );
173            }
174            if ( activationOS.getVersion() != null )
175            {
176                serializer.startTag( NAMESPACE, "version" ).text( activationOS.getVersion() ).endTag( NAMESPACE, "version" );
177            }
178            serializer.endTag( NAMESPACE, tagName );
179        } //-- void writeActivationOS( ActivationOS, String, XmlSerializer )
180    
181        /**
182         * Method writeActivationProperty.
183         * 
184         * @param activationProperty
185         * @param serializer
186         * @param tagName
187         * @throws java.io.IOException
188         */
189        private void writeActivationProperty( ActivationProperty activationProperty, String tagName, XmlSerializer serializer )
190            throws java.io.IOException
191        {
192            serializer.startTag( NAMESPACE, tagName );
193            if ( activationProperty.getName() != null )
194            {
195                serializer.startTag( NAMESPACE, "name" ).text( activationProperty.getName() ).endTag( NAMESPACE, "name" );
196            }
197            if ( activationProperty.getValue() != null )
198            {
199                serializer.startTag( NAMESPACE, "value" ).text( activationProperty.getValue() ).endTag( NAMESPACE, "value" );
200            }
201            serializer.endTag( NAMESPACE, tagName );
202        } //-- void writeActivationProperty( ActivationProperty, String, XmlSerializer )
203    
204        /**
205         * Method writeProfile.
206         * 
207         * @param profile
208         * @param serializer
209         * @param tagName
210         * @throws java.io.IOException
211         */
212        private void writeProfile( Profile profile, String tagName, XmlSerializer serializer )
213            throws java.io.IOException
214        {
215            serializer.startTag( NAMESPACE, tagName );
216            if ( profile.getId() != null )
217            {
218                serializer.startTag( NAMESPACE, "id" ).text( profile.getId() ).endTag( NAMESPACE, "id" );
219            }
220            if ( profile.getActivation() != null )
221            {
222                writeActivation( (Activation) profile.getActivation(), "activation", serializer );
223            }
224            if ( ( profile.getProperties() != null ) && ( profile.getProperties().size() > 0 ) )
225            {
226                serializer.startTag( NAMESPACE, "properties" );
227                for ( Iterator iter = profile.getProperties().keySet().iterator(); iter.hasNext(); )
228                {
229                    String key = (String) iter.next();
230                    String value = (String) profile.getProperties().get( key );
231                    serializer.startTag( NAMESPACE, "" + key + "" ).text( value ).endTag( NAMESPACE, "" + key + "" );
232                }
233                serializer.endTag( NAMESPACE, "properties" );
234            }
235            if ( ( profile.getRepositories() != null ) && ( profile.getRepositories().size() > 0 ) )
236            {
237                serializer.startTag( NAMESPACE, "repositories" );
238                for ( Iterator iter = profile.getRepositories().iterator(); iter.hasNext(); )
239                {
240                    Repository o = (Repository) iter.next();
241                    writeRepository( o, "repository", serializer );
242                }
243                serializer.endTag( NAMESPACE, "repositories" );
244            }
245            if ( ( profile.getPluginRepositories() != null ) && ( profile.getPluginRepositories().size() > 0 ) )
246            {
247                serializer.startTag( NAMESPACE, "pluginRepositories" );
248                for ( Iterator iter = profile.getPluginRepositories().iterator(); iter.hasNext(); )
249                {
250                    Repository o = (Repository) iter.next();
251                    writeRepository( o, "pluginRepository", serializer );
252                }
253                serializer.endTag( NAMESPACE, "pluginRepositories" );
254            }
255            serializer.endTag( NAMESPACE, tagName );
256        } //-- void writeProfile( Profile, String, XmlSerializer )
257    
258        /**
259         * Method writeProfilesRoot.
260         * 
261         * @param profilesRoot
262         * @param serializer
263         * @param tagName
264         * @throws java.io.IOException
265         */
266        private void writeProfilesRoot( ProfilesRoot profilesRoot, String tagName, XmlSerializer serializer )
267            throws java.io.IOException
268        {
269            serializer.setPrefix( "", "http://maven.apache.org/PROFILES/1.0.0" );
270            serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
271            serializer.startTag( NAMESPACE, tagName );
272            serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PROFILES/1.0.0 http://maven.apache.org/xsd/profiles-1.0.0.xsd" );
273            if ( ( profilesRoot.getProfiles() != null ) && ( profilesRoot.getProfiles().size() > 0 ) )
274            {
275                serializer.startTag( NAMESPACE, "profiles" );
276                for ( Iterator iter = profilesRoot.getProfiles().iterator(); iter.hasNext(); )
277                {
278                    Profile o = (Profile) iter.next();
279                    writeProfile( o, "profile", serializer );
280                }
281                serializer.endTag( NAMESPACE, "profiles" );
282            }
283            if ( ( profilesRoot.getActiveProfiles() != null ) && ( profilesRoot.getActiveProfiles().size() > 0 ) )
284            {
285                serializer.startTag( NAMESPACE, "activeProfiles" );
286                for ( Iterator iter = profilesRoot.getActiveProfiles().iterator(); iter.hasNext(); )
287                {
288                    String activeProfile = (String) iter.next();
289                    serializer.startTag( NAMESPACE, "activeProfile" ).text( activeProfile ).endTag( NAMESPACE, "activeProfile" );
290                }
291                serializer.endTag( NAMESPACE, "activeProfiles" );
292            }
293            serializer.endTag( NAMESPACE, tagName );
294        } //-- void writeProfilesRoot( ProfilesRoot, String, XmlSerializer )
295    
296        /**
297         * Method writeRepository.
298         * 
299         * @param repository
300         * @param serializer
301         * @param tagName
302         * @throws java.io.IOException
303         */
304        private void writeRepository( Repository repository, String tagName, XmlSerializer serializer )
305            throws java.io.IOException
306        {
307            serializer.startTag( NAMESPACE, tagName );
308            if ( repository.getReleases() != null )
309            {
310                writeRepositoryPolicy( (RepositoryPolicy) repository.getReleases(), "releases", serializer );
311            }
312            if ( repository.getSnapshots() != null )
313            {
314                writeRepositoryPolicy( (RepositoryPolicy) repository.getSnapshots(), "snapshots", serializer );
315            }
316            if ( repository.getId() != null )
317            {
318                serializer.startTag( NAMESPACE, "id" ).text( repository.getId() ).endTag( NAMESPACE, "id" );
319            }
320            if ( repository.getName() != null )
321            {
322                serializer.startTag( NAMESPACE, "name" ).text( repository.getName() ).endTag( NAMESPACE, "name" );
323            }
324            if ( repository.getUrl() != null )
325            {
326                serializer.startTag( NAMESPACE, "url" ).text( repository.getUrl() ).endTag( NAMESPACE, "url" );
327            }
328            if ( ( repository.getLayout() != null ) && !repository.getLayout().equals( "default" ) )
329            {
330                serializer.startTag( NAMESPACE, "layout" ).text( repository.getLayout() ).endTag( NAMESPACE, "layout" );
331            }
332            serializer.endTag( NAMESPACE, tagName );
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            serializer.startTag( NAMESPACE, tagName );
347            if ( repositoryBase.getId() != null )
348            {
349                serializer.startTag( NAMESPACE, "id" ).text( repositoryBase.getId() ).endTag( NAMESPACE, "id" );
350            }
351            if ( repositoryBase.getName() != null )
352            {
353                serializer.startTag( NAMESPACE, "name" ).text( repositoryBase.getName() ).endTag( NAMESPACE, "name" );
354            }
355            if ( repositoryBase.getUrl() != null )
356            {
357                serializer.startTag( NAMESPACE, "url" ).text( repositoryBase.getUrl() ).endTag( NAMESPACE, "url" );
358            }
359            if ( ( repositoryBase.getLayout() != null ) && !repositoryBase.getLayout().equals( "default" ) )
360            {
361                serializer.startTag( NAMESPACE, "layout" ).text( repositoryBase.getLayout() ).endTag( NAMESPACE, "layout" );
362            }
363            serializer.endTag( NAMESPACE, tagName );
364        } //-- void writeRepositoryBase( RepositoryBase, String, XmlSerializer )
365    
366        /**
367         * Method writeRepositoryPolicy.
368         * 
369         * @param repositoryPolicy
370         * @param serializer
371         * @param tagName
372         * @throws java.io.IOException
373         */
374        private void writeRepositoryPolicy( RepositoryPolicy repositoryPolicy, String tagName, XmlSerializer serializer )
375            throws java.io.IOException
376        {
377            serializer.startTag( NAMESPACE, tagName );
378            if ( repositoryPolicy.isEnabled() != true )
379            {
380                serializer.startTag( NAMESPACE, "enabled" ).text( String.valueOf( repositoryPolicy.isEnabled() ) ).endTag( NAMESPACE, "enabled" );
381            }
382            if ( repositoryPolicy.getUpdatePolicy() != null )
383            {
384                serializer.startTag( NAMESPACE, "updatePolicy" ).text( repositoryPolicy.getUpdatePolicy() ).endTag( NAMESPACE, "updatePolicy" );
385            }
386            if ( repositoryPolicy.getChecksumPolicy() != null )
387            {
388                serializer.startTag( NAMESPACE, "checksumPolicy" ).text( repositoryPolicy.getChecksumPolicy() ).endTag( NAMESPACE, "checksumPolicy" );
389            }
390            serializer.endTag( NAMESPACE, tagName );
391        } //-- void writeRepositoryPolicy( RepositoryPolicy, String, XmlSerializer )
392    
393    }