1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class SAXReaderUtil {
41  
42      public static Attribute createAttribute(
43          Element element, QName qName, String value) {
44  
45          return getSAXReader().createAttribute(element, qName, value);
46      }
47  
48      public static Attribute createAttribute(
49          Element element, String name, String value) {
50  
51          return getSAXReader().createAttribute(element, name, value);
52      }
53  
54      public static Document createDocument() {
55          return getSAXReader().createDocument();
56      }
57  
58      public static Document createDocument(Element rootElement) {
59          return getSAXReader().createDocument(rootElement);
60      }
61  
62      public static Document createDocument(String encoding) {
63          return getSAXReader().createDocument(encoding);
64      }
65  
66      public static Element createElement(QName qName) {
67          return getSAXReader().createElement(qName);
68      }
69  
70      public static Element createElement(String name) {
71          return getSAXReader().createElement(name);
72      }
73  
74      public static Entity createEntity(String name, String text) {
75          return getSAXReader().createEntity(name, text);
76      }
77  
78      public static Namespace createNamespace(String uri) {
79          return getSAXReader().createNamespace(uri);
80      }
81  
82      public static Namespace createNamespace(String prefix, String uri) {
83          return getSAXReader().createNamespace(prefix, uri);
84      }
85  
86      public static ProcessingInstruction createProcessingInstruction(
87          String target, Map<String, String> data) {
88  
89          return getSAXReader().createProcessingInstruction(target, data);
90      }
91  
92      public static ProcessingInstruction createProcessingInstruction(
93          String target, String data) {
94  
95          return getSAXReader().createProcessingInstruction(target, data);
96      }
97  
98      public static QName createQName(String localName) {
99          return getSAXReader().createQName(localName);
100     }
101 
102     public static QName createQName(String localName, Namespace namespace) {
103         return getSAXReader().createQName(localName, namespace);
104     }
105 
106     public static Text createText(String text) {
107         return getSAXReader().createText(text);
108     }
109 
110     public static XPath createXPath(String xpathExpression) {
111         return getSAXReader().createXPath(xpathExpression);
112     }
113 
114     public static SAXReader getSAXReader() {
115         return _saxReader;
116     }
117 
118     public static Document read(File file) throws DocumentException {
119         return getSAXReader().read(file);
120     }
121 
122     public static Document read(File file, boolean validate)
123         throws DocumentException {
124 
125         return getSAXReader().read(file, validate);
126     }
127 
128     public static Document read(InputStream is) throws DocumentException {
129         return getSAXReader().read(is);
130     }
131 
132     public static Document read(InputStream is, boolean validate)
133         throws DocumentException {
134 
135         return getSAXReader().read(is, validate);
136     }
137 
138     public static Document read(Reader reader) throws DocumentException {
139         return getSAXReader().read(reader);
140     }
141 
142     public static Document read(Reader reader, boolean validate)
143         throws DocumentException {
144 
145         return getSAXReader().read(reader, validate);
146     }
147 
148     public static Document read(String xml) throws DocumentException {
149         return getSAXReader().read(xml);
150     }
151 
152     public static Document read(String xml, boolean validate)
153         throws DocumentException {
154 
155         return getSAXReader().read(xml, validate);
156     }
157 
158     public static Document read(URL url) throws DocumentException {
159         return getSAXReader().read(url);
160     }
161 
162     public static Document read(URL url, boolean validate)
163         throws DocumentException {
164 
165         return getSAXReader().read(url, validate);
166     }
167 
168     public static Document readURL(String url)
169         throws DocumentException, MalformedURLException {
170 
171         return getSAXReader().readURL(url);
172     }
173 
174     public static Document readURL(String url, boolean validate)
175         throws DocumentException, MalformedURLException {
176 
177         return getSAXReader().readURL(url, validate);
178     }
179 
180     public static List<Node> selectNodes(
181         String xpathFilterExpression, List<Node> nodes) {
182 
183         return getSAXReader().selectNodes(xpathFilterExpression, nodes);
184     }
185 
186     public static List<Node> selectNodes(
187         String xpathFilterExpression, Node node) {
188 
189         return getSAXReader().selectNodes(xpathFilterExpression, node);
190     }
191 
192     public static void sort(List<Node> nodes, String xpathExpression) {
193 
194         getSAXReader().sort(nodes, xpathExpression);
195     }
196 
197     public static void sort(
198         List<Node> nodes, String xpathExpression, boolean distinct) {
199 
200         getSAXReader().sort(nodes, xpathExpression, distinct);
201     }
202 
203     public void setSAXReader(SAXReader saxReader) {
204         _saxReader = saxReader;
205     }
206 
207     private static SAXReader _saxReader;
208 
209 }