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