1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.xml;
24  
25  import java.io.File;
26  import java.io.InputStream;
27  import java.io.Reader;
28  
29  import java.net.MalformedURLException;
30  import java.net.URL;
31  
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * <a href="SAXReaderUtil.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class SAXReaderUtil {
42  
43      public static Attribute createAttribute(
44          Element element, QName qName, String value) {
45  
46          return getSAXReader().createAttribute(element, qName, value);
47      }
48  
49      public static Attribute createAttribute(
50          Element element, String name, String value) {
51  
52          return getSAXReader().createAttribute(element, name, value);
53      }
54  
55      public static Document createDocument() {
56          return getSAXReader().createDocument();
57      }
58  
59      public static Document createDocument(Element rootElement) {
60          return getSAXReader().createDocument(rootElement);
61      }
62  
63      public static Document createDocument(String encoding) {
64          return getSAXReader().createDocument(encoding);
65      }
66  
67      public static Element createElement(QName qName) {
68          return getSAXReader().createElement(qName);
69      }
70  
71      public static Element createElement(String name) {
72          return getSAXReader().createElement(name);
73      }
74  
75      public static Entity createEntity(String name, String text) {
76          return getSAXReader().createEntity(name, text);
77      }
78  
79      public static Namespace createNamespace(String uri) {
80          return getSAXReader().createNamespace(uri);
81      }
82  
83      public static Namespace createNamespace(String prefix, String uri) {
84          return getSAXReader().createNamespace(prefix, uri);
85      }
86  
87      public static ProcessingInstruction createProcessingInstruction(
88          String target, Map<String, String> data) {
89  
90          return getSAXReader().createProcessingInstruction(target, data);
91      }
92  
93      public static ProcessingInstruction createProcessingInstruction(
94          String target, String data) {
95  
96          return getSAXReader().createProcessingInstruction(target, data);
97      }
98  
99      public static QName createQName(String localName) {
100         return getSAXReader().createQName(localName);
101     }
102 
103     public static QName createQName(String localName, Namespace namespace) {
104         return getSAXReader().createQName(localName, namespace);
105     }
106 
107     public static Text createText(String text) {
108         return getSAXReader().createText(text);
109     }
110 
111     public static XPath createXPath(String xpathExpression) {
112         return getSAXReader().createXPath(xpathExpression);
113     }
114 
115     public static SAXReader getSAXReader() {
116         return _saxReader;
117     }
118 
119     public static Document read(File file) throws DocumentException {
120         return getSAXReader().read(file);
121     }
122 
123     public static Document read(File file, boolean validate)
124         throws DocumentException {
125 
126         return getSAXReader().read(file, validate);
127     }
128 
129     public static Document read(InputStream is) throws DocumentException {
130         return getSAXReader().read(is);
131     }
132 
133     public static Document read(InputStream is, boolean validate)
134         throws DocumentException {
135 
136         return getSAXReader().read(is, validate);
137     }
138 
139     public static Document read(Reader reader) throws DocumentException {
140         return getSAXReader().read(reader);
141     }
142 
143     public static Document read(Reader reader, boolean validate)
144         throws DocumentException {
145 
146         return getSAXReader().read(reader, validate);
147     }
148 
149     public static Document read(String xml) throws DocumentException {
150         return getSAXReader().read(xml);
151     }
152 
153     public static Document read(String xml, boolean validate)
154         throws DocumentException {
155 
156         return getSAXReader().read(xml, validate);
157     }
158 
159     public static Document read(URL url) throws DocumentException {
160         return getSAXReader().read(url);
161     }
162 
163     public static Document read(URL url, boolean validate)
164         throws DocumentException {
165 
166         return getSAXReader().read(url, validate);
167     }
168 
169     public static Document readURL(String url)
170         throws DocumentException, MalformedURLException {
171 
172         return getSAXReader().readURL(url);
173     }
174 
175     public static Document readURL(String url, boolean validate)
176         throws DocumentException, MalformedURLException {
177 
178         return getSAXReader().readURL(url, validate);
179     }
180 
181     public static List<Node> selectNodes(
182         String xpathFilterExpression, List<Node> nodes) {
183 
184         return getSAXReader().selectNodes(xpathFilterExpression, nodes);
185     }
186 
187     public static List<Node> selectNodes(
188         String xpathFilterExpression, Node node) {
189 
190         return getSAXReader().selectNodes(xpathFilterExpression, node);
191     }
192 
193     public static void sort(List<Node> nodes, String xpathExpression) {
194 
195         getSAXReader().sort(nodes, xpathExpression);
196     }
197 
198     public static void sort(
199         List<Node> nodes, String xpathExpression, boolean distinct) {
200 
201         getSAXReader().sort(nodes, xpathExpression, distinct);
202     }
203 
204     public void setSAXReader(SAXReader saxReader) {
205         _saxReader = saxReader;
206     }
207 
208     private static SAXReader _saxReader;
209 
210 }