001// =================== DO NOT EDIT THIS FILE ====================
002// Generated by Modello 1.8.3,
003// any modifications will be overwritten.
004// ==============================================================
005
006package org.apache.maven.profiles.io.xpp3;
007
008  //---------------------------------/
009 //- Imported classes and packages -/
010//---------------------------------/
011
012import java.io.OutputStream;
013import java.io.Writer;
014import java.util.Iterator;
015import org.apache.maven.profiles.Activation;
016import org.apache.maven.profiles.ActivationFile;
017import org.apache.maven.profiles.ActivationOS;
018import org.apache.maven.profiles.ActivationProperty;
019import org.apache.maven.profiles.Profile;
020import org.apache.maven.profiles.ProfilesRoot;
021import org.apache.maven.profiles.Repository;
022import org.apache.maven.profiles.RepositoryBase;
023import org.apache.maven.profiles.RepositoryPolicy;
024import org.codehaus.plexus.util.xml.pull.MXSerializer;
025import org.codehaus.plexus.util.xml.pull.XmlSerializer;
026
027/**
028 * Class ProfilesXpp3Writer.
029 * 
030 * @version $Revision: 965443 $ $Date: 2015-09-14 22:18:52 +0000 (Mon, 14 Sep 2015) $
031 */
032@SuppressWarnings( "all" )
033public class ProfilesXpp3Writer
034{
035
036      //--------------------------/
037     //- Class/Member Variables -/
038    //--------------------------/
039
040    /**
041     * Field NAMESPACE.
042     */
043    private static final String NAMESPACE = null;
044
045
046      //-----------/
047     //- Methods -/
048    //-----------/
049
050    /**
051     * Method write.
052     * 
053     * @param writer
054     * @param profilesRoot
055     * @throws java.io.IOException
056     */
057    public void write( Writer writer, ProfilesRoot profilesRoot )
058        throws java.io.IOException
059    {
060        XmlSerializer serializer = new MXSerializer();
061        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
062        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
063        serializer.setOutput( writer );
064        serializer.startDocument( profilesRoot.getModelEncoding(), null );
065        writeProfilesRoot( profilesRoot, "profilesXml", serializer );
066        serializer.endDocument();
067    } //-- void write( Writer, ProfilesRoot )
068
069    /**
070     * Method write.
071     * 
072     * @param stream
073     * @param profilesRoot
074     * @throws java.io.IOException
075     */
076    public void write( OutputStream stream, ProfilesRoot profilesRoot )
077        throws java.io.IOException
078    {
079        XmlSerializer serializer = new MXSerializer();
080        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
081        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
082        serializer.setOutput( stream, profilesRoot.getModelEncoding() );
083        serializer.startDocument( profilesRoot.getModelEncoding(), null );
084        writeProfilesRoot( profilesRoot, "profilesXml", serializer );
085        serializer.endDocument();
086    } //-- void write( OutputStream, ProfilesRoot )
087
088    /**
089     * Method writeActivation.
090     * 
091     * @param activation
092     * @param serializer
093     * @param tagName
094     * @throws java.io.IOException
095     */
096    private void writeActivation( Activation activation, String tagName, XmlSerializer serializer )
097        throws java.io.IOException
098    {
099        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}