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.codehaus.plexus.util.xml;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.io.Reader;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
25  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26  
27  /**
28   * @version $Id$
29   */
30  public class Xpp3DomBuilder {
31      private static final boolean DEFAULT_TRIM = true;
32  
33      public static Xpp3Dom build(Reader reader) throws XmlPullParserException, IOException {
34          return build(reader, null);
35      }
36  
37      /**
38       * @since 3.2.0
39       */
40      public static Xpp3Dom build(Reader reader, InputLocationBuilder locationBuilder)
41              throws XmlPullParserException, IOException {
42          return build(reader, DEFAULT_TRIM, locationBuilder);
43      }
44  
45      public static Xpp3Dom build(InputStream is, String encoding) throws XmlPullParserException, IOException {
46          return build(is, encoding, DEFAULT_TRIM);
47      }
48  
49      public static Xpp3Dom build(InputStream is, String encoding, boolean trim)
50              throws XmlPullParserException, IOException {
51          return new Xpp3Dom(org.apache.maven.internal.xml.Xpp3DomBuilder.build(is, encoding, trim));
52      }
53  
54      public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
55          return build(reader, trim, null);
56      }
57  
58      /**
59       * @since 3.2.0
60       */
61      public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
62              throws XmlPullParserException, IOException {
63          return new Xpp3Dom(org.apache.maven.internal.xml.Xpp3DomBuilder.build(
64                  reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
65      }
66  
67      public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
68          return build(parser, DEFAULT_TRIM);
69      }
70  
71      public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
72          return build(parser, trim, null);
73      }
74  
75      /**
76       * @since 3.2.0
77       */
78      public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder)
79              throws XmlPullParserException, IOException {
80          return new Xpp3Dom(org.apache.maven.internal.xml.Xpp3DomBuilder.build(
81                  parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
82      }
83  
84      /**
85       * Input location builder interface, to be implemented to choose how to store data.
86       *
87       * @since 3.2.0
88       */
89      public interface InputLocationBuilder {
90          Object toInputLocation(XmlPullParser parser);
91      }
92  }