View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.1.2,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.artifact.repository.metadata.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.OutputStream;
13  import java.io.Writer;
14  import java.util.Iterator;
15  import org.apache.maven.artifact.repository.metadata.Metadata;
16  import org.apache.maven.artifact.repository.metadata.Plugin;
17  import org.apache.maven.artifact.repository.metadata.Snapshot;
18  import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
19  import org.apache.maven.artifact.repository.metadata.Versioning;
20  import org.codehaus.plexus.util.xml.pull.MXSerializer;
21  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
22  
23  /**
24   * Class MetadataXpp3Writer.
25   * 
26   * @version $Revision$ $Date$
27   */
28  @SuppressWarnings( "all" )
29  public class MetadataXpp3Writer
30  {
31  
32        //--------------------------/
33       //- Class/Member Variables -/
34      //--------------------------/
35  
36      /**
37       * Field NAMESPACE.
38       */
39      private static final String NAMESPACE = null;
40  
41      /**
42       * Field fileComment.
43       */
44      private String fileComment = null;
45  
46  
47        //-----------/
48       //- Methods -/
49      //-----------/
50  
51      /**
52       * Method setFileComment.
53       * 
54       * @param fileComment a fileComment object.
55       */
56      public void setFileComment( String fileComment )
57      {
58          this.fileComment = fileComment;
59      } //-- void setFileComment( String )
60  
61      /**
62       * Method write.
63       * 
64       * @param writer a writer object.
65       * @param metadata a metadata object.
66       * @throws java.io.IOException java.io.IOException if any.
67       */
68      public void write( Writer writer, Metadata metadata )
69          throws java.io.IOException
70      {
71          XmlSerializer serializer = new MXSerializer();
72          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
73          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
74          serializer.setOutput( writer );
75          serializer.startDocument( metadata.getModelEncoding(), null );
76          writeMetadata( metadata, "metadata", serializer );
77          serializer.endDocument();
78      } //-- void write( Writer, Metadata )
79  
80      /**
81       * Method write.
82       * 
83       * @param stream a stream object.
84       * @param metadata a metadata object.
85       * @throws java.io.IOException java.io.IOException if any.
86       */
87      public void write( OutputStream stream, Metadata metadata )
88          throws java.io.IOException
89      {
90          XmlSerializer serializer = new MXSerializer();
91          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
92          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
93          serializer.setOutput( stream, metadata.getModelEncoding() );
94          serializer.startDocument( metadata.getModelEncoding(), null );
95          writeMetadata( metadata, "metadata", serializer );
96          serializer.endDocument();
97      } //-- void write( OutputStream, Metadata )
98  
99      /**
100      * Method writeMetadata.
101      * 
102      * @param metadata a metadata object.
103      * @param serializer a serializer object.
104      * @param tagName a tagName object.
105      * @throws java.io.IOException java.io.IOException if any.
106      */
107     private void writeMetadata( Metadata metadata, String tagName, XmlSerializer serializer )
108         throws java.io.IOException
109     {
110         serializer.startTag( NAMESPACE, tagName );
111         if ( metadata.getModelVersion() != null )
112         {
113             serializer.attribute( NAMESPACE, "modelVersion", metadata.getModelVersion() );
114         }
115         if ( metadata.getGroupId() != null )
116         {
117             serializer.startTag( NAMESPACE, "groupId" ).text( metadata.getGroupId() ).endTag( NAMESPACE, "groupId" );
118         }
119         if ( metadata.getArtifactId() != null )
120         {
121             serializer.startTag( NAMESPACE, "artifactId" ).text( metadata.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
122         }
123         if ( metadata.getVersioning() != null )
124         {
125             writeVersioning( (Versioning) metadata.getVersioning(), "versioning", serializer );
126         }
127         if ( metadata.getVersion() != null )
128         {
129             serializer.startTag( NAMESPACE, "version" ).text( metadata.getVersion() ).endTag( NAMESPACE, "version" );
130         }
131         if ( ( metadata.getPlugins() != null ) && ( metadata.getPlugins().size() > 0 ) )
132         {
133             serializer.startTag( NAMESPACE, "plugins" );
134             for ( Iterator iter = metadata.getPlugins().iterator(); iter.hasNext(); )
135             {
136                 Plugin o = (Plugin) iter.next();
137                 writePlugin( o, "plugin", serializer );
138             }
139             serializer.endTag( NAMESPACE, "plugins" );
140         }
141         serializer.endTag( NAMESPACE, tagName );
142     } //-- void writeMetadata( Metadata, String, XmlSerializer )
143 
144     /**
145      * Method writePlugin.
146      * 
147      * @param plugin a plugin object.
148      * @param serializer a serializer object.
149      * @param tagName a tagName object.
150      * @throws java.io.IOException java.io.IOException if any.
151      */
152     private void writePlugin( Plugin plugin, String tagName, XmlSerializer serializer )
153         throws java.io.IOException
154     {
155         serializer.startTag( NAMESPACE, tagName );
156         if ( plugin.getName() != null )
157         {
158             serializer.startTag( NAMESPACE, "name" ).text( plugin.getName() ).endTag( NAMESPACE, "name" );
159         }
160         if ( plugin.getPrefix() != null )
161         {
162             serializer.startTag( NAMESPACE, "prefix" ).text( plugin.getPrefix() ).endTag( NAMESPACE, "prefix" );
163         }
164         if ( plugin.getArtifactId() != null )
165         {
166             serializer.startTag( NAMESPACE, "artifactId" ).text( plugin.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
167         }
168         serializer.endTag( NAMESPACE, tagName );
169     } //-- void writePlugin( Plugin, String, XmlSerializer )
170 
171     /**
172      * Method writeSnapshot.
173      * 
174      * @param snapshot a snapshot object.
175      * @param serializer a serializer object.
176      * @param tagName a tagName object.
177      * @throws java.io.IOException java.io.IOException if any.
178      */
179     private void writeSnapshot( Snapshot snapshot, String tagName, XmlSerializer serializer )
180         throws java.io.IOException
181     {
182         serializer.startTag( NAMESPACE, tagName );
183         if ( snapshot.getTimestamp() != null )
184         {
185             serializer.startTag( NAMESPACE, "timestamp" ).text( snapshot.getTimestamp() ).endTag( NAMESPACE, "timestamp" );
186         }
187         if ( snapshot.getBuildNumber() != 0 )
188         {
189             serializer.startTag( NAMESPACE, "buildNumber" ).text( String.valueOf( snapshot.getBuildNumber() ) ).endTag( NAMESPACE, "buildNumber" );
190         }
191         if ( snapshot.isLocalCopy() != false )
192         {
193             serializer.startTag( NAMESPACE, "localCopy" ).text( String.valueOf( snapshot.isLocalCopy() ) ).endTag( NAMESPACE, "localCopy" );
194         }
195         serializer.endTag( NAMESPACE, tagName );
196     } //-- void writeSnapshot( Snapshot, String, XmlSerializer )
197 
198     /**
199      * Method writeSnapshotVersion.
200      * 
201      * @param snapshotVersion a snapshotVersion object.
202      * @param serializer a serializer object.
203      * @param tagName a tagName object.
204      * @throws java.io.IOException java.io.IOException if any.
205      */
206     private void writeSnapshotVersion( SnapshotVersion snapshotVersion, String tagName, XmlSerializer serializer )
207         throws java.io.IOException
208     {
209         serializer.startTag( NAMESPACE, tagName );
210         if ( ( snapshotVersion.getClassifier() != null ) && !snapshotVersion.getClassifier().equals( "" ) )
211         {
212             serializer.startTag( NAMESPACE, "classifier" ).text( snapshotVersion.getClassifier() ).endTag( NAMESPACE, "classifier" );
213         }
214         if ( snapshotVersion.getExtension() != null )
215         {
216             serializer.startTag( NAMESPACE, "extension" ).text( snapshotVersion.getExtension() ).endTag( NAMESPACE, "extension" );
217         }
218         if ( snapshotVersion.getVersion() != null )
219         {
220             serializer.startTag( NAMESPACE, "value" ).text( snapshotVersion.getVersion() ).endTag( NAMESPACE, "value" );
221         }
222         if ( snapshotVersion.getUpdated() != null )
223         {
224             serializer.startTag( NAMESPACE, "updated" ).text( snapshotVersion.getUpdated() ).endTag( NAMESPACE, "updated" );
225         }
226         serializer.endTag( NAMESPACE, tagName );
227     } //-- void writeSnapshotVersion( SnapshotVersion, String, XmlSerializer )
228 
229     /**
230      * Method writeVersioning.
231      * 
232      * @param versioning a versioning object.
233      * @param serializer a serializer object.
234      * @param tagName a tagName object.
235      * @throws java.io.IOException java.io.IOException if any.
236      */
237     private void writeVersioning( Versioning versioning, String tagName, XmlSerializer serializer )
238         throws java.io.IOException
239     {
240         serializer.startTag( NAMESPACE, tagName );
241         if ( versioning.getLatest() != null )
242         {
243             serializer.startTag( NAMESPACE, "latest" ).text( versioning.getLatest() ).endTag( NAMESPACE, "latest" );
244         }
245         if ( versioning.getRelease() != null )
246         {
247             serializer.startTag( NAMESPACE, "release" ).text( versioning.getRelease() ).endTag( NAMESPACE, "release" );
248         }
249         if ( ( versioning.getVersions() != null ) && ( versioning.getVersions().size() > 0 ) )
250         {
251             serializer.startTag( NAMESPACE, "versions" );
252             for ( Iterator iter = versioning.getVersions().iterator(); iter.hasNext(); )
253             {
254                 String version = (String) iter.next();
255                 serializer.startTag( NAMESPACE, "version" ).text( version ).endTag( NAMESPACE, "version" );
256             }
257             serializer.endTag( NAMESPACE, "versions" );
258         }
259         if ( versioning.getLastUpdated() != null )
260         {
261             serializer.startTag( NAMESPACE, "lastUpdated" ).text( versioning.getLastUpdated() ).endTag( NAMESPACE, "lastUpdated" );
262         }
263         if ( versioning.getSnapshot() != null )
264         {
265             writeSnapshot( (Snapshot) versioning.getSnapshot(), "snapshot", serializer );
266         }
267         if ( ( versioning.getSnapshotVersions() != null ) && ( versioning.getSnapshotVersions().size() > 0 ) )
268         {
269             serializer.startTag( NAMESPACE, "snapshotVersions" );
270             for ( Iterator iter = versioning.getSnapshotVersions().iterator(); iter.hasNext(); )
271             {
272                 SnapshotVersion o = (SnapshotVersion) iter.next();
273                 writeSnapshotVersion( o, "snapshotVersion", serializer );
274             }
275             serializer.endTag( NAMESPACE, "snapshotVersions" );
276         }
277         serializer.endTag( NAMESPACE, tagName );
278     } //-- void writeVersioning( Versioning, String, XmlSerializer )
279 
280 }