View Javadoc
1   package org.apache.maven.model.io.xpp3;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  import java.io.OutputStream;
24  import java.io.Writer;
25  
26  import org.apache.maven.model.InputLocation;
27  import org.apache.maven.model.Model;
28  
29  public class MavenXpp3WriterEx
30  {
31      //--------------------------/
32      //- Class/Member Variables -/
33      //--------------------------/
34  
35      /**
36       * Field fileComment.
37       */
38      private String fileComment = null;
39  
40      /**
41       * Field stringFormatter.
42       */
43      protected InputLocation.StringFormatter stringFormatter;
44  
45  
46      //-----------/
47      //- Methods -/
48      //-----------/
49  
50      /**
51       * Method setFileComment.
52       *
53       * @param fileComment a fileComment object.
54       */
55      public void setFileComment( String fileComment )
56      {
57          this.fileComment = fileComment;
58      } //-- void setFileComment( String )
59  
60      /**
61       * Method setStringFormatter.
62       *
63       * @param stringFormatter
64       */
65      public void setStringFormatter( InputLocation.StringFormatter stringFormatter )
66      {
67          this.stringFormatter = stringFormatter;
68      } //-- void setStringFormatter( InputLocation.StringFormatter )
69  
70      /**
71       * Method write.
72       *
73       * @param writer a writer object.
74       * @param model a model object.
75       * @throws IOException java.io.IOException if any.
76       */
77      public void write( Writer writer, Model model )
78              throws IOException
79      {
80          org.apache.maven.model.v4.MavenXpp3WriterEx xw = new org.apache.maven.model.v4.MavenXpp3WriterEx();
81          xw.setFileComment( fileComment );
82          xw.setStringFormatter( stringFormatter != null ? new org.apache.maven.api.model.InputLocation.StringFormatter()
83          {
84              @Override
85              public String toString( org.apache.maven.api.model.InputLocation location )
86              {
87                  return stringFormatter.toString( new InputLocation( location ) );
88              }
89          } : null );
90          xw.write( writer, model.getDelegate() );
91      } //-- void write( Writer, Model )
92  
93      /**
94       * Method write.
95       *
96       * @param stream a stream object.
97       * @param model a model object.
98       * @throws IOException java.io.IOException if any.
99       */
100     public void write( OutputStream stream, Model model )
101             throws IOException
102     {
103         org.apache.maven.model.v4.MavenXpp3WriterEx xw = new org.apache.maven.model.v4.MavenXpp3WriterEx();
104         xw.setFileComment( fileComment );
105         xw.write( stream, model.getDelegate() );
106     } //-- void write( OutputStream, Model )
107 
108 }