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 java.io.IOException;
22  import java.io.OutputStream;
23  import java.io.Writer;
24  import org.apache.maven.model.InputLocation;
25  import org.apache.maven.model.Model;
26  
27  public class MavenXpp3WriterEx {
28      // --------------------------/
29      // - Class/Member Variables -/
30      // --------------------------/
31  
32      /**
33       * Field fileComment.
34       */
35      private String fileComment = null;
36  
37      /**
38       * Field stringFormatter.
39       */
40      protected InputLocation.StringFormatter stringFormatter;
41  
42      // -----------/
43      // - Methods -/
44      // -----------/
45  
46      /**
47       * Method setFileComment.
48       *
49       * @param fileComment a fileComment object.
50       */
51      public void setFileComment(String fileComment) {
52          this.fileComment = fileComment;
53      } // -- void setFileComment( String )
54  
55      /**
56       * Method setStringFormatter.
57       *
58       * @param stringFormatter
59       */
60      public void setStringFormatter(InputLocation.StringFormatter stringFormatter) {
61          this.stringFormatter = stringFormatter;
62      } // -- void setStringFormatter( InputLocation.StringFormatter )
63  
64      /**
65       * Method write.
66       *
67       * @param writer a writer object.
68       * @param model a model object.
69       * @throws IOException java.io.IOException if any.
70       */
71      public void write(Writer writer, Model model) throws IOException {
72          org.apache.maven.model.v4.MavenXpp3WriterEx xw = new org.apache.maven.model.v4.MavenXpp3WriterEx();
73          xw.setFileComment(fileComment);
74          xw.setStringFormatter(
75                  stringFormatter != null
76                          ? new org.apache.maven.api.model.InputLocation.StringFormatter() {
77                              @Override
78                              public String toString(org.apache.maven.api.model.InputLocation location) {
79                                  return stringFormatter.toString(new InputLocation(location));
80                              }
81                          }
82                          : null);
83          xw.write(writer, model.getDelegate());
84      } // -- void write( Writer, Model )
85  
86      /**
87       * Method write.
88       *
89       * @param stream a stream object.
90       * @param model a model object.
91       * @throws IOException java.io.IOException if any.
92       */
93      public void write(OutputStream stream, Model model) throws IOException {
94          org.apache.maven.model.v4.MavenXpp3WriterEx xw = new org.apache.maven.model.v4.MavenXpp3WriterEx();
95          xw.setFileComment(fileComment);
96          xw.write(stream, model.getDelegate());
97      } // -- void write( OutputStream, Model )
98  }