1   package org.codehaus.plexus.util.xml;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.Reader;
22  
23  import org.apache.maven.internal.xml.XmlNodeBuilder;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
25  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26  
27  
28  
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  
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          try (InputStream closeMe = is) {
52              return new Xpp3Dom(XmlNodeBuilder.build(is, encoding, trim));
53          }
54      }
55  
56      public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
57          return build(reader, trim, null);
58      }
59  
60      
61  
62  
63      public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
64              throws XmlPullParserException, IOException {
65          try (Reader closeMe = reader) {
66              return new Xpp3Dom(XmlNodeBuilder.build(
67                      reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
68          }
69      }
70  
71      public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
72          return build(parser, DEFAULT_TRIM);
73      }
74  
75      public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
76          return build(parser, trim, null);
77      }
78  
79      
80  
81  
82      public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder)
83              throws XmlPullParserException, IOException {
84          return new Xpp3Dom(
85                  XmlNodeBuilder.build(parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
86      }
87  
88      
89  
90  
91  
92  
93      public interface InputLocationBuilder {
94          Object toInputLocation(XmlPullParser parser);
95      }
96  }