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   */
19  package org.apache.maven.model.io.xpp3;
20  
21  import javax.xml.stream.XMLStreamException;
22  
23  import java.io.IOException;
24  import java.io.OutputStream;
25  import java.io.Writer;
26  
27  import org.apache.maven.model.InputLocation;
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.v4.MavenStaxWriter;
30  
31  /**
32   * @deprecated Use MavenStaxWriter instead
33   */
34  @Deprecated
35  public class MavenXpp3Writer {
36      // --------------------------/
37      // - Class/Member Variables -/
38      // --------------------------/
39  
40      private final MavenStaxWriter delegate = new MavenStaxWriter();
41  
42      // -----------/
43      // - Methods -/
44      // -----------/
45  
46      public MavenXpp3Writer() {
47          this(false);
48      }
49  
50      protected MavenXpp3Writer(boolean addLocationInformation) {
51          delegate.setAddLocationInformation(addLocationInformation);
52      }
53  
54      /**
55       * Method setFileComment.
56       *
57       * @param fileComment a fileComment object.
58       */
59      public void setFileComment(String fileComment) {
60          delegate.setFileComment(fileComment);
61      } // -- void setFileComment( String )
62  
63      /**
64       * Method setStringFormatter.
65       *
66       * @param stringFormatter
67       */
68      public void setStringFormatter(InputLocation.StringFormatter stringFormatter) {
69          delegate.setStringFormatter(
70                  stringFormatter != null
71                          ? new org.apache.maven.api.model.InputLocation.StringFormatter() {
72                              @Override
73                              public String toString(org.apache.maven.api.model.InputLocation location) {
74                                  return stringFormatter.toString(new InputLocation(location));
75                              }
76                          }
77                          : null);
78      } // -- void setStringFormatter( InputLocation.StringFormatter )
79  
80      /**
81       * Method write.
82       *
83       * @param writer a writer object.
84       * @param model a model object.
85       * @throws IOException java.io.IOException if any.
86       */
87      public void write(Writer writer, Model model) throws IOException {
88          try {
89              delegate.write(writer, model.getDelegate());
90          } catch (XMLStreamException e) {
91              throw new IOException(e);
92          }
93      } // -- void write( Writer, Model )
94  
95      /**
96       * Method write.
97       *
98       * @param stream a stream object.
99       * @param model a model object.
100      * @throws IOException java.io.IOException if any.
101      */
102     public void write(OutputStream stream, Model model) throws IOException {
103         try {
104             delegate.write(stream, model.getDelegate());
105         } catch (XMLStreamException e) {
106             throw new IOException(e);
107         }
108     } // -- void write( OutputStream, Model )
109 }