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.5.1,
20   any modifications will be overwritten.
21   ==============================================================
22   */
23  
24  package org.apache.maven.cli.internal.extension.model.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.cli.internal.extension.model.CoreExtension;
34  import org.apache.maven.cli.internal.extension.model.CoreExtensions;
35  import org.codehaus.plexus.util.xml.pull.MXSerializer;
36  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
37  
38  /**
39   * Class CoreExtensionsXpp3Writer.
40   * 
41   * @version $Revision$ $Date$
42   */
43  @SuppressWarnings( "all" )
44  public class CoreExtensionsXpp3Writer
45  {
46  
47        //--------------------------/
48       //- Class/Member Variables -/
49      //--------------------------/
50  
51      /**
52       * Field NAMESPACE.
53       */
54      private static final String NAMESPACE = null;
55  
56      /**
57       * Field fileComment.
58       */
59      private String fileComment = null;
60  
61  
62        //-----------/
63       //- Methods -/
64      //-----------/
65  
66      /**
67       * Method setFileComment.
68       * 
69       * @param fileComment a fileComment object.
70       */
71      public void setFileComment( String fileComment )
72      {
73          this.fileComment = fileComment;
74      } //-- void setFileComment( String )
75  
76      /**
77       * Method write.
78       * 
79       * @param writer a writer object.
80       * @param coreExtensions a coreExtensions object.
81       * @throws java.io.IOException java.io.IOException if any.
82       */
83      public void write( Writer writer, CoreExtensions coreExtensions )
84          throws java.io.IOException
85      {
86          XmlSerializer serializer = new MXSerializer();
87          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
88          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
89          serializer.setOutput( writer );
90          serializer.startDocument( coreExtensions.getModelEncoding(), null );
91          writeCoreExtensions( coreExtensions, "extensions", serializer );
92          serializer.endDocument();
93      } //-- void write( Writer, CoreExtensions )
94  
95      /**
96       * Method write.
97       * 
98       * @param stream a stream object.
99       * @param coreExtensions a coreExtensions object.
100      * @throws java.io.IOException java.io.IOException if any.
101      */
102     public void write( OutputStream stream, CoreExtensions coreExtensions )
103         throws java.io.IOException
104     {
105         XmlSerializer serializer = new MXSerializer();
106         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
107         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
108         serializer.setOutput( stream, coreExtensions.getModelEncoding() );
109         serializer.startDocument( coreExtensions.getModelEncoding(), null );
110         writeCoreExtensions( coreExtensions, "extensions", serializer );
111         serializer.endDocument();
112     } //-- void write( OutputStream, CoreExtensions )
113 
114     /**
115      * Method writeCoreExtension.
116      * 
117      * @param coreExtension a coreExtension object.
118      * @param serializer a serializer object.
119      * @param tagName a tagName object.
120      * @throws java.io.IOException java.io.IOException if any.
121      */
122     private void writeCoreExtension( CoreExtension coreExtension, String tagName, XmlSerializer serializer )
123         throws java.io.IOException
124     {
125         serializer.startTag( NAMESPACE, tagName );
126         if ( coreExtension.getGroupId() != null )
127         {
128             serializer.startTag( NAMESPACE, "groupId" ).text( coreExtension.getGroupId() ).endTag( NAMESPACE, "groupId" );
129         }
130         if ( coreExtension.getArtifactId() != null )
131         {
132             serializer.startTag( NAMESPACE, "artifactId" ).text( coreExtension.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
133         }
134         if ( coreExtension.getVersion() != null )
135         {
136             serializer.startTag( NAMESPACE, "version" ).text( coreExtension.getVersion() ).endTag( NAMESPACE, "version" );
137         }
138         if ( ( coreExtension.getClassLoadingStrategy() != null ) && !coreExtension.getClassLoadingStrategy().equals( "self-first" ) )
139         {
140             serializer.startTag( NAMESPACE, "classLoadingStrategy" ).text( coreExtension.getClassLoadingStrategy() ).endTag( NAMESPACE, "classLoadingStrategy" );
141         }
142         serializer.endTag( NAMESPACE, tagName );
143     } //-- void writeCoreExtension( CoreExtension, String, XmlSerializer )
144 
145     /**
146      * Method writeCoreExtensions.
147      * 
148      * @param coreExtensions a coreExtensions object.
149      * @param serializer a serializer object.
150      * @param tagName a tagName object.
151      * @throws java.io.IOException java.io.IOException if any.
152      */
153     private void writeCoreExtensions( CoreExtensions coreExtensions, String tagName, XmlSerializer serializer )
154         throws java.io.IOException
155     {
156         if ( this.fileComment != null )
157         {
158         serializer.comment(this.fileComment);
159         }
160         serializer.setPrefix( "", "http://maven.apache.org/EXTENSIONS/1.1.0" );
161         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
162         serializer.startTag( NAMESPACE, tagName );
163         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/EXTENSIONS/1.1.0 https://maven.apache.org/xsd/core-extensions-1.1.0.xsd" );
164         if ( ( coreExtensions.getExtensions() != null ) && ( coreExtensions.getExtensions().size() > 0 ) )
165         {
166             for ( Iterator iter = coreExtensions.getExtensions().iterator(); iter.hasNext(); )
167             {
168                 CoreExtension o = (CoreExtension) iter.next();
169                 writeCoreExtension( o, "extension", serializer );
170             }
171         }
172         serializer.endTag( NAMESPACE, tagName );
173     } //-- void writeCoreExtensions( CoreExtensions, String, XmlSerializer )
174 
175 }