View Javadoc
1   package org.codehaus.plexus.util.xml;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.io.Reader;
25  
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  {
34      private static final boolean DEFAULT_TRIM = true;
35  
36      public static Xpp3Dom build( Reader reader )
37          throws XmlPullParserException, IOException
38      {
39          return build( reader, null );
40      }
41  
42      /**
43       * @since 3.2.0
44       */
45      public static Xpp3Dom build( Reader reader, InputLocationBuilder locationBuilder )
46          throws XmlPullParserException, IOException
47      {
48          return build( reader, DEFAULT_TRIM, locationBuilder );
49      }
50  
51      public static Xpp3Dom build( InputStream is, String encoding )
52          throws XmlPullParserException, IOException
53      {
54          return build( is, encoding, DEFAULT_TRIM );
55      }
56  
57      public static Xpp3Dom build( InputStream is, String encoding, boolean trim )
58          throws XmlPullParserException, IOException
59      {
60          return new Xpp3Dom( org.apache.maven.internal.xml.Xpp3DomBuilder.build( is, encoding, trim ) );
61      }
62  
63      public static Xpp3Dom build( Reader reader, boolean trim )
64          throws XmlPullParserException, IOException
65      {
66          return build( reader, trim, null );
67      }
68  
69      /**
70       * @since 3.2.0
71       */
72      public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder locationBuilder )
73          throws XmlPullParserException, IOException
74      {
75          return new Xpp3Dom( org.apache.maven.internal.xml.Xpp3DomBuilder.build(
76                  reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null ) );
77      }
78  
79      public static Xpp3Dom build( XmlPullParser parser )
80          throws XmlPullParserException, IOException
81      {
82          return build( parser, DEFAULT_TRIM );
83      }
84  
85      public static Xpp3Dom build( XmlPullParser parser, boolean trim )
86          throws XmlPullParserException, IOException
87      {
88          return build( parser, trim, null );
89      }
90  
91      /**
92       * @since 3.2.0
93       */
94      public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder )
95          throws XmlPullParserException, IOException
96      {
97          return new Xpp3Dom( org.apache.maven.internal.xml.Xpp3DomBuilder.build(
98                  parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null ) );
99      }
100 
101     /**
102      * Input location builder interface, to be implemented to choose how to store data.
103      *
104      * @since 3.2.0
105      */
106     public interface InputLocationBuilder
107     {
108         Object toInputLocation( XmlPullParser parser );
109     }
110 }