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.report.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.report.CacheReport;
16  import org.apache.maven.buildcache.xml.report.ProjectReport;
17  import org.codehaus.plexus.util.xml.pull.MXSerializer;
18  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
19  
20  /**
21   * Class BuildCacheReportXpp3Writer.
22   * 
23   * @version $Revision$ $Date$
24   */
25  @SuppressWarnings( "all" )
26  public class BuildCacheReportXpp3Writer
27  {
28  
29        //--------------------------/
30       //- Class/Member Variables -/
31      //--------------------------/
32  
33      /**
34       * Field NAMESPACE.
35       */
36      private static final String NAMESPACE = null;
37  
38      /**
39       * Field fileComment.
40       */
41      private String fileComment = null;
42  
43  
44        //-----------/
45       //- Methods -/
46      //-----------/
47  
48      /**
49       * Method setFileComment.
50       * 
51       * @param fileComment a fileComment object.
52       */
53      public void setFileComment( String fileComment )
54      {
55          this.fileComment = fileComment;
56      } //-- void setFileComment( String )
57  
58      /**
59       * Method write.
60       * 
61       * @param writer a writer object.
62       * @param cacheReport a cacheReport object.
63       * @throws java.io.IOException java.io.IOException if any.
64       */
65      public void write( Writer writer, CacheReport cacheReport )
66          throws java.io.IOException
67      {
68          XmlSerializer serializer = new MXSerializer();
69          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
70          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
71          serializer.setOutput( writer );
72          serializer.startDocument( cacheReport.getModelEncoding(), null );
73          writeCacheReport( cacheReport, "cacheReport", serializer );
74          serializer.endDocument();
75      } //-- void write( Writer, CacheReport )
76  
77      /**
78       * Method write.
79       * 
80       * @param stream a stream object.
81       * @param cacheReport a cacheReport object.
82       * @throws java.io.IOException java.io.IOException if any.
83       */
84      public void write( OutputStream stream, CacheReport cacheReport )
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( stream, cacheReport.getModelEncoding() );
91          serializer.startDocument( cacheReport.getModelEncoding(), null );
92          writeCacheReport( cacheReport, "cacheReport", serializer );
93          serializer.endDocument();
94      } //-- void write( OutputStream, CacheReport )
95  
96      /**
97       * Method writeCacheReport.
98       * 
99       * @param cacheReport a cacheReport object.
100      * @param serializer a serializer object.
101      * @param tagName a tagName object.
102      * @throws java.io.IOException java.io.IOException if any.
103      */
104     private void writeCacheReport( CacheReport cacheReport, String tagName, XmlSerializer serializer )
105         throws java.io.IOException
106     {
107         if ( this.fileComment != null )
108         {
109         serializer.comment(this.fileComment);
110         }
111         serializer.setPrefix( "", "http://maven.apache.org/BUILD-CACHE-REPORT/1.0.0" );
112         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
113         serializer.startTag( NAMESPACE, tagName );
114         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/BUILD-CACHE-REPORT/1.0.0 https://maven.apache.org/xsd/build-cache-report-1.0.0.xsd" );
115         if ( ( cacheReport.getProjects() != null ) && ( cacheReport.getProjects().size() > 0 ) )
116         {
117             serializer.startTag( NAMESPACE, "projects" );
118             for ( Iterator iter = cacheReport.getProjects().iterator(); iter.hasNext(); )
119             {
120                 ProjectReport o = (ProjectReport) iter.next();
121                 writeProjectReport( o, "project", serializer );
122             }
123             serializer.endTag( NAMESPACE, "projects" );
124         }
125         serializer.endTag( NAMESPACE, tagName );
126     } //-- void writeCacheReport( CacheReport, String, XmlSerializer )
127 
128     /**
129      * Method writeProjectReport.
130      * 
131      * @param projectReport a projectReport object.
132      * @param serializer a serializer object.
133      * @param tagName a tagName object.
134      * @throws java.io.IOException java.io.IOException if any.
135      */
136     private void writeProjectReport( ProjectReport projectReport, String tagName, XmlSerializer serializer )
137         throws java.io.IOException
138     {
139         serializer.startTag( NAMESPACE, tagName );
140         if ( projectReport.getGroupId() != null )
141         {
142             serializer.startTag( NAMESPACE, "groupId" ).text( projectReport.getGroupId() ).endTag( NAMESPACE, "groupId" );
143         }
144         if ( projectReport.getArtifactId() != null )
145         {
146             serializer.startTag( NAMESPACE, "artifactId" ).text( projectReport.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
147         }
148         if ( projectReport.getChecksum() != null )
149         {
150             serializer.startTag( NAMESPACE, "checksum" ).text( projectReport.getChecksum() ).endTag( NAMESPACE, "checksum" );
151         }
152         if ( projectReport.isChecksumMatched() != null )
153         {
154             serializer.startTag( NAMESPACE, "checksumMatched" ).text( String.valueOf( projectReport.isChecksumMatched() ) ).endTag( NAMESPACE, "checksumMatched" );
155         }
156         if ( projectReport.isLifecycleMatched() != null )
157         {
158             serializer.startTag( NAMESPACE, "lifecycleMatched" ).text( String.valueOf( projectReport.isLifecycleMatched() ) ).endTag( NAMESPACE, "lifecycleMatched" );
159         }
160         if ( projectReport.isPluginsMatched() != null )
161         {
162             serializer.startTag( NAMESPACE, "pluginsMatched" ).text( String.valueOf( projectReport.isPluginsMatched() ) ).endTag( NAMESPACE, "pluginsMatched" );
163         }
164         if ( projectReport.getSource() != null )
165         {
166             serializer.startTag( NAMESPACE, "source" ).text( projectReport.getSource() ).endTag( NAMESPACE, "source" );
167         }
168         if ( projectReport.isSharedToRemote() != null )
169         {
170             serializer.startTag( NAMESPACE, "sharedToRemote" ).text( String.valueOf( projectReport.isSharedToRemote() ) ).endTag( NAMESPACE, "sharedToRemote" );
171         }
172         if ( projectReport.getUrl() != null )
173         {
174             serializer.startTag( NAMESPACE, "url" ).text( projectReport.getUrl() ).endTag( NAMESPACE, "url" );
175         }
176         serializer.endTag( NAMESPACE, tagName );
177     } //-- void writeProjectReport( ProjectReport, String, XmlSerializer )
178 
179 }