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