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