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.InputStream;
25 import java.io.Reader;
26
27 import org.apache.maven.model.InputSource;
28 import org.apache.maven.model.Model;
29 import org.apache.maven.model.v4.MavenStaxReader;
30 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
31
32 /**
33 * @deprecated Use MavenStaxReader instead
34 */
35 @Deprecated
36 public class MavenXpp3Reader {
37 private MavenStaxReader delegate;
38
39 public MavenXpp3Reader() {
40 this(null, false);
41 }
42
43 public MavenXpp3Reader(ContentTransformer contentTransformer) {
44 this(contentTransformer, false);
45 }
46
47 protected MavenXpp3Reader(ContentTransformer contentTransformer, boolean addLocationInformation) {
48 delegate =
49 contentTransformer != null ? new MavenStaxReader(contentTransformer::transform) : new MavenStaxReader();
50 delegate.setAddLocationInformation(addLocationInformation);
51 }
52
53 /**
54 * Returns the state of the "add default entities" flag.
55 *
56 * @return boolean
57 */
58 public boolean getAddDefaultEntities() {
59 return delegate.getAddDefaultEntities();
60 } // -- boolean getAddDefaultEntities()
61
62 /**
63 * Sets the state of the "add default entities" flag.
64 *
65 * @param addDefaultEntities a addDefaultEntities object.
66 */
67 public void setAddDefaultEntities(boolean addDefaultEntities) {
68 delegate.setAddLocationInformation(addDefaultEntities);
69 } // -- void setAddDefaultEntities( boolean )
70
71 protected Model read(Reader reader, boolean strict, InputSource source) throws IOException, XmlPullParserException {
72 try {
73 org.apache.maven.api.model.Model model =
74 delegate.read(reader, strict, source != null ? source.toApiSource() : null);
75 return new Model(model);
76 } catch (XMLStreamException e) {
77 throw new XmlPullParserException(e.getMessage(), null, e);
78 }
79 }
80
81 /**
82 *
83 * @param reader a reader object.
84 * @param strict a strict object.
85 * @throws IOException IOException if any.
86 * @throws XmlPullParserException XmlPullParserException if
87 * any.
88 * @return Model
89 */
90 public Model read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
91 return read(reader, strict, null);
92 } // -- Model read( Reader, boolean )
93
94 /**
95 *
96 * @param reader a reader object.
97 * @throws IOException IOException if any.
98 * @throws XmlPullParserException XmlPullParserException if
99 * any.
100 * @return Model
101 */
102 public Model read(Reader reader) throws IOException, XmlPullParserException {
103 return read(reader, true);
104 } // -- Model read( Reader )
105
106 protected Model read(InputStream is, boolean strict, InputSource source)
107 throws IOException, XmlPullParserException {
108 try {
109 org.apache.maven.api.model.Model model =
110 delegate.read(is, strict, source != null ? source.toApiSource() : null);
111 return new Model(model);
112 } catch (XMLStreamException e) {
113 throw new XmlPullParserException(e.getMessage(), null, e);
114 }
115 }
116
117 /**
118 * Method read.
119 *
120 * @param in a in object.
121 * @param strict a strict object.
122 * @throws IOException IOException if any.
123 * @throws XmlPullParserException XmlPullParserException if
124 * any.
125 * @return Model
126 */
127 public Model read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
128 return read(in, strict, null);
129 } // -- Model read( InputStream, boolean )
130
131 /**
132 * Method read.
133 *
134 * @param in a in object.
135 * @throws IOException IOException if any.
136 * @throws XmlPullParserException XmlPullParserException if
137 * any.
138 * @return Model
139 */
140 public Model read(InputStream in) throws IOException, XmlPullParserException {
141 return read(in, true);
142 } // -- Model read( InputStream )
143
144 public interface ContentTransformer {
145 /**
146 * Interpolate the value read from the xpp3 document
147 * @param source The source value
148 * @param fieldName A description of the field being interpolated. The implementation may use this to
149 * log stuff.
150 * @return The interpolated value.
151 */
152 String transform(String source, String fieldName);
153 }
154 }