View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.0.1 on 2011-06-19 15:23:53,
4    any modifications will be overwritten.
5    ==============================================================
6    */
7   
8   package org.apache.maven.plugins.changes.model.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.plugins.changes.model.Action;
19  import org.apache.maven.plugins.changes.model.Author;
20  import org.apache.maven.plugins.changes.model.Body;
21  import org.apache.maven.plugins.changes.model.ChangesDocument;
22  import org.apache.maven.plugins.changes.model.DueTo;
23  import org.apache.maven.plugins.changes.model.FixedIssue;
24  import org.apache.maven.plugins.changes.model.Properties;
25  import org.apache.maven.plugins.changes.model.Release;
26  import org.codehaus.plexus.util.xml.pull.MXSerializer;
27  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
28  
29  /**
30   * Class ChangesXpp3Writer.
31   * 
32   * @version $Revision: 816603 $ $Date: 2012-05-08 12:53:30 +0000 (Tue, 08 May 2012) $
33   */
34  public class ChangesXpp3Writer
35  {
36  
37        //--------------------------/
38       //- Class/Member Variables -/
39      //--------------------------/
40  
41      /**
42       * Field NAMESPACE.
43       */
44      private static final String NAMESPACE = null;
45  
46  
47        //-----------/
48       //- Methods -/
49      //-----------/
50  
51      /**
52       * Method write.
53       * 
54       * @param writer
55       * @param changesDocument
56       * @throws java.io.IOException
57       */
58      public void write( Writer writer, ChangesDocument changesDocument )
59          throws java.io.IOException
60      {
61          XmlSerializer serializer = new MXSerializer();
62          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
63          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
64          serializer.setOutput( writer );
65          serializer.startDocument( changesDocument.getModelEncoding(), null );
66          writeChangesDocument( changesDocument, "document", serializer );
67          serializer.endDocument();
68      } //-- void write( Writer, ChangesDocument )
69  
70      /**
71       * Method writeAction.
72       * 
73       * @param action
74       * @param serializer
75       * @param tagName
76       * @throws java.io.IOException
77       */
78      private void writeAction( Action action, String tagName, XmlSerializer serializer )
79          throws java.io.IOException
80      {
81          if ( action != null )
82          {
83              serializer.startTag( NAMESPACE, tagName );
84              if ( action.getDev() != null )
85              {
86                  serializer.attribute( NAMESPACE, "dev", action.getDev() );
87              }
88              if ( action.getDueTo() != null )
89              {
90                  serializer.attribute( NAMESPACE, "due-to", action.getDueTo() );
91              }
92              if ( action.getDueToEmail() != null )
93              {
94                  serializer.attribute( NAMESPACE, "due-to-email", action.getDueToEmail() );
95              }
96              if ( action.getIssue() != null )
97              {
98                  serializer.attribute( NAMESPACE, "issue", action.getIssue() );
99              }
100             if ( action.getType() != null )
101             {
102                 serializer.attribute( NAMESPACE, "type", action.getType() );
103             }
104             if ( action.getSystem() != null )
105             {
106                 serializer.attribute( NAMESPACE, "system", action.getSystem() );
107             }
108             if ( action.getDate() != null )
109             {
110                 serializer.attribute( NAMESPACE, "date", action.getDate() );
111             }
112             serializer.text( String.valueOf( action.getAction() ));
113             if ( ( action.getFixedIssues() != null ) && ( action.getFixedIssues().size() > 0 ) )
114             {
115                 for ( Iterator iter = action.getFixedIssues().iterator(); iter.hasNext(); )
116                 {
117                     FixedIssue o = (FixedIssue) iter.next();
118                     writeFixedIssue( o, "fixes", serializer );
119                 }
120             }
121             if ( ( action.getDueTos() != null ) && ( action.getDueTos().size() > 0 ) )
122             {
123                 for ( Iterator iter = action.getDueTos().iterator(); iter.hasNext(); )
124                 {
125                     DueTo o = (DueTo) iter.next();
126                     writeDueTo( o, "dueto", serializer );
127                 }
128             }
129             serializer.endTag( NAMESPACE, tagName );
130         }
131     } //-- void writeAction( Action, String, XmlSerializer )
132 
133     /**
134      * Method writeAuthor.
135      * 
136      * @param author
137      * @param serializer
138      * @param tagName
139      * @throws java.io.IOException
140      */
141     private void writeAuthor( Author author, String tagName, XmlSerializer serializer )
142         throws java.io.IOException
143     {
144         if ( author != null )
145         {
146             serializer.startTag( NAMESPACE, tagName );
147             if ( author.getAuthorEmail() != null )
148             {
149                 serializer.attribute( NAMESPACE, "email", author.getAuthorEmail() );
150             }
151             serializer.text( String.valueOf( author.getName() ));
152             serializer.endTag( NAMESPACE, tagName );
153         }
154     } //-- void writeAuthor( Author, String, XmlSerializer )
155 
156     /**
157      * Method writeBody.
158      * 
159      * @param body
160      * @param serializer
161      * @param tagName
162      * @throws java.io.IOException
163      */
164     private void writeBody( Body body, String tagName, XmlSerializer serializer )
165         throws java.io.IOException
166     {
167         if ( body != null )
168         {
169             serializer.startTag( NAMESPACE, tagName );
170             if ( ( body.getReleases() != null ) && ( body.getReleases().size() > 0 ) )
171             {
172                 for ( Iterator iter = body.getReleases().iterator(); iter.hasNext(); )
173                 {
174                     Release o = (Release) iter.next();
175                     writeRelease( o, "release", serializer );
176                 }
177             }
178             serializer.endTag( NAMESPACE, tagName );
179         }
180     } //-- void writeBody( Body, String, XmlSerializer )
181 
182     /**
183      * Method writeChangesDocument.
184      * 
185      * @param changesDocument
186      * @param serializer
187      * @param tagName
188      * @throws java.io.IOException
189      */
190     private void writeChangesDocument( ChangesDocument changesDocument, String tagName, XmlSerializer serializer )
191         throws java.io.IOException
192     {
193         if ( changesDocument != null )
194         {
195             serializer.startTag( NAMESPACE, tagName );
196             if ( changesDocument.getProperties() != null )
197             {
198                 writeProperties( (Properties) changesDocument.getProperties(), "properties", serializer );
199             }
200             if ( changesDocument.getBody() != null )
201             {
202                 writeBody( (Body) changesDocument.getBody(), "body", serializer );
203             }
204             serializer.endTag( NAMESPACE, tagName );
205         }
206     } //-- void writeChangesDocument( ChangesDocument, String, XmlSerializer )
207 
208     /**
209      * Method writeDueTo.
210      * 
211      * @param dueTo
212      * @param serializer
213      * @param tagName
214      * @throws java.io.IOException
215      */
216     private void writeDueTo( DueTo dueTo, String tagName, XmlSerializer serializer )
217         throws java.io.IOException
218     {
219         if ( dueTo != null )
220         {
221             serializer.startTag( NAMESPACE, tagName );
222             if ( dueTo.getName() != null )
223             {
224                 serializer.attribute( NAMESPACE, "name", dueTo.getName() );
225             }
226             if ( dueTo.getEmail() != null )
227             {
228                 serializer.attribute( NAMESPACE, "email", dueTo.getEmail() );
229             }
230             serializer.endTag( NAMESPACE, tagName );
231         }
232     } //-- void writeDueTo( DueTo, String, XmlSerializer )
233 
234     /**
235      * Method writeFixedIssue.
236      * 
237      * @param fixedIssue
238      * @param serializer
239      * @param tagName
240      * @throws java.io.IOException
241      */
242     private void writeFixedIssue( FixedIssue fixedIssue, String tagName, XmlSerializer serializer )
243         throws java.io.IOException
244     {
245         if ( fixedIssue != null )
246         {
247             serializer.startTag( NAMESPACE, tagName );
248             if ( fixedIssue.getIssue() != null )
249             {
250                 serializer.attribute( NAMESPACE, "issue", fixedIssue.getIssue() );
251             }
252             serializer.endTag( NAMESPACE, tagName );
253         }
254     } //-- void writeFixedIssue( FixedIssue, String, XmlSerializer )
255 
256     /**
257      * Method writeProperties.
258      * 
259      * @param properties
260      * @param serializer
261      * @param tagName
262      * @throws java.io.IOException
263      */
264     private void writeProperties( Properties properties, String tagName, XmlSerializer serializer )
265         throws java.io.IOException
266     {
267         if ( properties != null )
268         {
269             serializer.startTag( NAMESPACE, tagName );
270             if ( properties.getTitle() != null )
271             {
272                 serializer.startTag( NAMESPACE, "title" ).text( properties.getTitle() ).endTag( NAMESPACE, "title" );
273             }
274             if ( properties.getAuthor() != null )
275             {
276                 writeAuthor( (Author) properties.getAuthor(), "author", serializer );
277             }
278             serializer.endTag( NAMESPACE, tagName );
279         }
280     } //-- void writeProperties( Properties, String, XmlSerializer )
281 
282     /**
283      * Method writeRelease.
284      * 
285      * @param release
286      * @param serializer
287      * @param tagName
288      * @throws java.io.IOException
289      */
290     private void writeRelease( Release release, String tagName, XmlSerializer serializer )
291         throws java.io.IOException
292     {
293         if ( release != null )
294         {
295             serializer.startTag( NAMESPACE, tagName );
296             if ( release.getVersion() != null )
297             {
298                 serializer.attribute( NAMESPACE, "version", release.getVersion() );
299             }
300             if ( release.getDateRelease() != null )
301             {
302                 serializer.attribute( NAMESPACE, "date", release.getDateRelease() );
303             }
304             if ( release.getDescription() != null )
305             {
306                 serializer.attribute( NAMESPACE, "description", release.getDescription() );
307             }
308             if ( ( release.getActions() != null ) && ( release.getActions().size() > 0 ) )
309             {
310                 for ( Iterator iter = release.getActions().iterator(); iter.hasNext(); )
311                 {
312                     Action o = (Action) iter.next();
313                     writeAction( o, "action", serializer );
314                 }
315             }
316             serializer.endTag( NAMESPACE, tagName );
317         }
318     } //-- void writeRelease( Release, String, XmlSerializer )
319 
320 
321 }