1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
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 try (InputStream closeMe = is) {
54 return new Xpp3Dom(XmlNodeBuilder.build(is, encoding, trim));
55 }
56 }
57
58 public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
59 return build(reader, trim, null);
60 }
61
62
63
64
65 public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
66 throws XmlPullParserException, IOException {
67 try (Reader closeMe = reader) {
68 return new Xpp3Dom(XmlNodeBuilder.build(
69 reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
70 }
71 }
72
73 public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
74 return build(parser, DEFAULT_TRIM);
75 }
76
77 public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
78 return build(parser, trim, null);
79 }
80
81
82
83
84 public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder)
85 throws XmlPullParserException, IOException {
86 return new Xpp3Dom(
87 XmlNodeBuilder.build(parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null));
88 }
89
90
91
92
93
94
95 public interface InputLocationBuilder {
96 Object toInputLocation(XmlPullParser parser);
97 }
98 }