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.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      public Settings read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
68          try {
69              return new Settings(delegate.read(reader, strict, null));
70          } catch (XMLStreamException e) {
71              throw new XmlPullParserException(e.getMessage(), null, e);
72          }
73      }
74  
75      public Settings read(Reader reader) throws IOException, XmlPullParserException {
76          try {
77              return new Settings(delegate.read(reader));
78          } catch (XMLStreamException e) {
79              throw new XmlPullParserException(e.getMessage(), null, e);
80          }
81      }
82  
83      public Settings read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
84          try {
85              return new Settings(delegate.read(in, strict, null));
86          } catch (XMLStreamException e) {
87              throw new XmlPullParserException(e.getMessage(), null, e);
88          }
89      }
90  
91      public Settings read(InputStream in) throws IOException, XmlPullParserException {
92          try {
93              return new Settings(delegate.read(in));
94          } catch (XMLStreamException e) {
95              throw new XmlPullParserException(e.getMessage(), null, e);
96          }
97      }
98  
99      public Settings read(XMLStreamReader parser, boolean strict) throws IOException, XmlPullParserException {
100         try {
101             return new Settings(delegate.read(parser, strict, null));
102         } catch (XMLStreamException e) {
103             throw new XmlPullParserException(e.getMessage(), null, e);
104         }
105     }
106 
107     public interface ContentTransformer {
108         /**
109          * Interpolate the value read from the xpp3 document
110          * @param source The source value
111          * @param fieldName A description of the field being interpolated. The implementation may use this to
112          *                           log stuff.
113          * @return The interpolated value.
114          */
115         String transform(String source, String fieldName);
116     }
117 }