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