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