View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.xml;
20  
21  import javax.xml.stream.XMLInputFactory;
22  import javax.xml.stream.XMLStreamException;
23  import javax.xml.stream.XMLStreamReader;
24  
25  import java.io.InputStream;
26  import java.io.Reader;
27  
28  import org.apache.maven.api.xml.XmlNode;
29  import org.apache.maven.api.xml.XmlService;
30  
31  /**
32   * All methods in this class attempt to fully parse the XML.
33   * The caller is responsible for closing {@code InputStream} and {@code Reader} arguments.
34   *
35   * @deprecated use {@code org.apache.maven.api.xml.XmlService} instead
36   */
37  @Deprecated
38  public class XmlNodeStaxBuilder {
39      private static final boolean DEFAULT_TRIM = true;
40  
41      public static XmlNode build(InputStream stream, InputLocationBuilderStax locationBuilder)
42              throws XMLStreamException {
43          XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(stream);
44          return build(parser, DEFAULT_TRIM, locationBuilder);
45      }
46  
47      public static XmlNode build(Reader reader, InputLocationBuilderStax locationBuilder) throws XMLStreamException {
48          XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(reader);
49          return build(parser, DEFAULT_TRIM, locationBuilder);
50      }
51  
52      public static XmlNode build(XMLStreamReader parser) throws XMLStreamException {
53          return build(parser, DEFAULT_TRIM, null);
54      }
55  
56      public static XmlNode build(XMLStreamReader parser, InputLocationBuilderStax locationBuilder)
57              throws XMLStreamException {
58          return build(parser, DEFAULT_TRIM, locationBuilder);
59      }
60  
61      public static XmlNode build(XMLStreamReader parser, boolean trim, InputLocationBuilderStax locationBuilder)
62              throws XMLStreamException {
63          return XmlService.read(parser, locationBuilder != null ? locationBuilder::toInputLocation : null);
64      }
65  
66      @Deprecated
67      public interface InputLocationBuilderStax {
68          Object toInputLocation(XMLStreamReader parser);
69      }
70  }