View Javadoc
1   package org.codehaus.plexus.util.xml;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.Reader;
22  
23  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
25  
26  /**
27   *
28   */
29  public class Xpp3DomBuilder {
30      private static final boolean DEFAULT_TRIM = true;
31  
32      public static Xpp3Dom build(Reader reader) throws XmlPullParserException, IOException {
33          return build(reader, null);
34      }
35  
36      /**
37       * @since 3.2.0
38       */
39      public static Xpp3Dom build(Reader reader, InputLocationBuilder locationBuilder)
40              throws XmlPullParserException, IOException {
41          return build(reader, DEFAULT_TRIM, locationBuilder);
42      }
43  
44      public static Xpp3Dom build(InputStream is, String encoding) throws XmlPullParserException, IOException {
45          return build(is, encoding, DEFAULT_TRIM);
46      }
47  
48      public static Xpp3Dom build(InputStream is, String encoding, boolean trim)
49              throws XmlPullParserException, IOException {
50          try (InputStream closeMe = is) {
51              return new Xpp3Dom(XmlNodePullBuilder.build(is, encoding, trim));
52          }
53      }
54  
55      public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
56          return build(reader, trim, null);
57      }
58  
59      /**
60       * @since 3.2.0
61       */
62      public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
63              throws XmlPullParserException, IOException {
64          try (Reader closeMe = reader) {
65              return new Xpp3Dom(XmlNodePullBuilder.build(reader, trim, locationBuilder));
66          }
67      }
68  
69      public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
70          return build(parser, DEFAULT_TRIM);
71      }
72  
73      public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
74          return build(parser, trim, null);
75      }
76  
77      /**
78       * @since 3.2.0
79       */
80      public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder)
81              throws XmlPullParserException, IOException {
82          return new Xpp3Dom(XmlNodePullBuilder.build(parser, trim, locationBuilder));
83      }
84  
85      /**
86       * Input location builder interface, to be implemented to choose how to store data.
87       *
88       * @since 3.2.0
89       */
90      public interface InputLocationBuilder {
91          Object toInputLocation(XmlPullParser parser);
92      }
93  }