View Javadoc
1   package org.apache.maven.internal.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.Reader;
23  
24  //import org.apache.maven.api.model.InputLocation;
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  }