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