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