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.buildcache.xml.diff.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.buildcache.xml.diff.Diff;
16  import org.apache.maven.buildcache.xml.diff.Mismatch;
17  import org.apache.maven.buildcache.xml.diff.MismatchDetail;
18  import org.codehaus.plexus.util.xml.pull.MXSerializer;
19  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
20  
21  /**
22   * Class BuildCacheDiffXpp3Writer.
23   * 
24   * @version $Revision$ $Date$
25   */
26  @SuppressWarnings( "all" )
27  public class BuildCacheDiffXpp3Writer
28  {
29  
30        //--------------------------/
31       //- Class/Member Variables -/
32      //--------------------------/
33  
34      /**
35       * Field NAMESPACE.
36       */
37      private static final String NAMESPACE = null;
38  
39      /**
40       * Field fileComment.
41       */
42      private String fileComment = null;
43  
44  
45        //-----------/
46       //- Methods -/
47      //-----------/
48  
49      /**
50       * Method setFileComment.
51       * 
52       * @param fileComment a fileComment object.
53       */
54      public void setFileComment( String fileComment )
55      {
56          this.fileComment = fileComment;
57      } //-- void setFileComment( String )
58  
59      /**
60       * Method write.
61       * 
62       * @param writer a writer object.
63       * @param diff a diff object.
64       * @throws java.io.IOException java.io.IOException if any.
65       */
66      public void write( Writer writer, Diff diff )
67          throws java.io.IOException
68      {
69          XmlSerializer serializer = new MXSerializer();
70          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
71          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
72          serializer.setOutput( writer );
73          serializer.startDocument( diff.getModelEncoding(), null );
74          writeDiff( diff, "diff", serializer );
75          serializer.endDocument();
76      } //-- void write( Writer, Diff )
77  
78      /**
79       * Method write.
80       * 
81       * @param stream a stream object.
82       * @param diff a diff object.
83       * @throws java.io.IOException java.io.IOException if any.
84       */
85      public void write( OutputStream stream, Diff diff )
86          throws java.io.IOException
87      {
88          XmlSerializer serializer = new MXSerializer();
89          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
90          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
91          serializer.setOutput( stream, diff.getModelEncoding() );
92          serializer.startDocument( diff.getModelEncoding(), null );
93          writeDiff( diff, "diff", serializer );
94          serializer.endDocument();
95      } //-- void write( OutputStream, Diff )
96  
97      /**
98       * Method writeDiff.
99       * 
100      * @param diff a diff object.
101      * @param serializer a serializer object.
102      * @param tagName a tagName object.
103      * @throws java.io.IOException java.io.IOException if any.
104      */
105     private void writeDiff( Diff diff, String tagName, XmlSerializer serializer )
106         throws java.io.IOException
107     {
108         if ( this.fileComment != null )
109         {
110         serializer.comment(this.fileComment);
111         }
112         serializer.setPrefix( "", "http://maven.apache.org/BUILD-CACHE-DIFF/1.0.0" );
113         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
114         serializer.startTag( NAMESPACE, tagName );
115         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/BUILD-CACHE-DIFF/1.0.0 https://maven.apache.org/xsd/build-cache-diff-1.0.0.xsd" );
116         if ( ( diff.getMismatches() != null ) && ( diff.getMismatches().size() > 0 ) )
117         {
118             serializer.startTag( NAMESPACE, "mismatches" );
119             for ( Iterator iter = diff.getMismatches().iterator(); iter.hasNext(); )
120             {
121                 Mismatch o = (Mismatch) iter.next();
122                 writeMismatch( o, "mismatch", serializer );
123             }
124             serializer.endTag( NAMESPACE, "mismatches" );
125         }
126         serializer.endTag( NAMESPACE, tagName );
127     } //-- void writeDiff( Diff, String, XmlSerializer )
128 
129     /**
130      * Method writeMismatch.
131      * 
132      * @param mismatch a mismatch object.
133      * @param serializer a serializer object.
134      * @param tagName a tagName object.
135      * @throws java.io.IOException java.io.IOException if any.
136      */
137     private void writeMismatch( Mismatch mismatch, String tagName, XmlSerializer serializer )
138         throws java.io.IOException
139     {
140         serializer.startTag( NAMESPACE, tagName );
141         if ( mismatch.getItem() != null )
142         {
143             serializer.attribute( NAMESPACE, "item", mismatch.getItem() );
144         }
145         if ( mismatch.getCurrent() != null )
146         {
147             serializer.attribute( NAMESPACE, "current", mismatch.getCurrent() );
148         }
149         if ( mismatch.getBaseline() != null )
150         {
151             serializer.attribute( NAMESPACE, "baseline", mismatch.getBaseline() );
152         }
153         if ( mismatch.getReason() != null )
154         {
155             serializer.attribute( NAMESPACE, "reason", mismatch.getReason() );
156         }
157         if ( mismatch.getResolution() != null )
158         {
159             serializer.attribute( NAMESPACE, "resolution", mismatch.getResolution() );
160         }
161         if ( mismatch.getContext() != null )
162         {
163             serializer.attribute( NAMESPACE, "context", mismatch.getContext() );
164         }
165         if ( ( mismatch.getDetail() != null ) && ( mismatch.getDetail().size() > 0 ) )
166         {
167             serializer.startTag( NAMESPACE, "detail" );
168             for ( Iterator iter = mismatch.getDetail().iterator(); iter.hasNext(); )
169             {
170                 MismatchDetail o = (MismatchDetail) iter.next();
171                 writeMismatchDetail( o, "detail", serializer );
172             }
173             serializer.endTag( NAMESPACE, "detail" );
174         }
175         serializer.endTag( NAMESPACE, tagName );
176     } //-- void writeMismatch( Mismatch, String, XmlSerializer )
177 
178     /**
179      * Method writeMismatchDetail.
180      * 
181      * @param mismatchDetail a mismatchDetail object.
182      * @param serializer a serializer object.
183      * @param tagName a tagName object.
184      * @throws java.io.IOException java.io.IOException if any.
185      */
186     private void writeMismatchDetail( MismatchDetail mismatchDetail, String tagName, XmlSerializer serializer )
187         throws java.io.IOException
188     {
189         serializer.startTag( NAMESPACE, tagName );
190         serializer.endTag( NAMESPACE, tagName );
191     } //-- void writeMismatchDetail( MismatchDetail, String, XmlSerializer )
192 
193 }