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