1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.xml;
20
21 import java.io.Reader;
22 import org.codehaus.plexus.util.xml.pull.MXParser;
23 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
24 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
25
26 public class DomBuilder {
27
28 public static Xpp3Dom build(Reader reader) throws MavenXmlException {
29 return build(reader, true);
30 }
31
32 public static Xpp3Dom build(Reader reader, boolean trim) throws MavenXmlException {
33 try {
34 MXParser parser = new MXParser();
35 parser.setInput(reader);
36 return build(parser, trim);
37 } catch (XmlPullParserException e) {
38 throw new MavenXmlException("Unable to build DOM", e);
39 }
40 }
41
42 public static Xpp3Dom build(XmlPullParser parser) {
43 return build(parser, true, null);
44 }
45
46 public static Xpp3Dom build(XmlPullParser parser, boolean trim) {
47 return build(parser, trim, null);
48 }
49
50 public static Xpp3Dom build(XmlPullParser parser, boolean trim, LocationBuilder locationBuilder) {
51 try {
52 Xpp3DomBuilder.InputLocationBuilder ilb =
53 locationBuilder != null ? (p -> locationBuilder.getLocation()) : null;
54 return Xpp3DomBuilder.build(parser, trim, ilb);
55 } catch (Exception e) {
56 throw new MavenXmlException("Unable to build DOM", e);
57 }
58 }
59
60 public static class LocationBuilder {
61
62 private final Object location;
63
64 public LocationBuilder(Object location) {
65 this.location = location;
66 }
67
68 public Object getLocation() {
69 return location;
70 }
71 }
72 }