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 com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  
28  import java.io.File;
29  import java.io.InputStream;
30  import java.io.Reader;
31  
32  import java.net.MalformedURLException;
33  import java.net.URL;
34  
35  import java.util.List;
36  import java.util.Map;
37  
38  /**
39   * <a href="SAXReaderUtil.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class SAXReaderUtil {
45  
46      public static Attribute createAttribute(
47          Element element, QName qName, String value) {
48  
49          return getSAXReader().createAttribute(element, qName, value);
50      }
51  
52      public static Attribute createAttribute(
53          Element element, String name, String value) {
54  
55          return getSAXReader().createAttribute(element, name, value);
56      }
57  
58      public static Document createDocument() {
59          return getSAXReader().createDocument();
60      }
61  
62      public static Document createDocument(Element rootElement) {
63          return getSAXReader().createDocument(rootElement);
64      }
65  
66      public static Document createDocument(String encoding) {
67          return getSAXReader().createDocument(encoding);
68      }
69  
70      public static Element createElement(QName qName) {
71          return getSAXReader().createElement(qName);
72      }
73  
74      public static Element createElement(String name) {
75          return getSAXReader().createElement(name);
76      }
77  
78      public static Entity createEntity(String name, String text) {
79          return getSAXReader().createEntity(name, text);
80      }
81  
82      public static Namespace createNamespace(String uri) {
83          return getSAXReader().createNamespace(uri);
84      }
85  
86      public static Namespace createNamespace(String prefix, String uri) {
87          return getSAXReader().createNamespace(prefix, uri);
88      }
89  
90      public static ProcessingInstruction createProcessingInstruction(
91          String target, Map<String, String> data) {
92  
93          return getSAXReader().createProcessingInstruction(target, data);
94      }
95  
96      public static ProcessingInstruction createProcessingInstruction(
97          String target, String data) {
98  
99          return getSAXReader().createProcessingInstruction(target, data);
100     }
101 
102     public static QName createQName(String localName) {
103         return getSAXReader().createQName(localName);
104     }
105 
106     public static QName createQName(String localName, Namespace namespace) {
107         return getSAXReader().createQName(localName, namespace);
108     }
109 
110     public static Text createText(String text) {
111         return getSAXReader().createText(text);
112     }
113 
114     public static XPath createXPath(String xpathExpression) {
115         return getSAXReader().createXPath(xpathExpression);
116     }
117 
118     public static SAXReader getSAXReader() {
119         return _saxReader;
120     }
121 
122     public static Document read(File file) throws DocumentException {
123         return getSAXReader().read(file);
124     }
125 
126     public static Document read(File file, boolean validate)
127         throws DocumentException {
128 
129         return getSAXReader().read(file, validate);
130     }
131 
132     public static Document read(InputStream is) throws DocumentException {
133         return getSAXReader().read(is);
134     }
135 
136     public static Document read(InputStream is, boolean validate)
137         throws DocumentException {
138 
139         return getSAXReader().read(is, validate);
140     }
141 
142     public static Document read(Reader reader) throws DocumentException {
143         return getSAXReader().read(reader);
144     }
145 
146     public static Document read(Reader reader, boolean validate)
147         throws DocumentException {
148 
149         return getSAXReader().read(reader, validate);
150     }
151 
152     public static Document read(String xml) throws DocumentException {
153         return getSAXReader().read(xml);
154     }
155 
156     public static Document read(String xml, boolean validate)
157         throws DocumentException {
158 
159         return getSAXReader().read(xml, validate);
160     }
161 
162     public static Document read(URL url) throws DocumentException {
163         return getSAXReader().read(url);
164     }
165 
166     public static Document read(URL url, boolean validate)
167         throws DocumentException {
168 
169         return getSAXReader().read(url, validate);
170     }
171 
172     public static Document readURL(String url)
173         throws DocumentException, MalformedURLException {
174 
175         return getSAXReader().readURL(url);
176     }
177 
178     public static Document readURL(String url, boolean validate)
179         throws DocumentException, MalformedURLException {
180 
181         return getSAXReader().readURL(url, validate);
182     }
183 
184     public static List<Node> selectNodes(
185         String xpathFilterExpression, List<Node> nodes) {
186 
187         return getSAXReader().selectNodes(xpathFilterExpression, nodes);
188     }
189 
190     public static List<Node> selectNodes(
191         String xpathFilterExpression, Node node) {
192 
193         return getSAXReader().selectNodes(xpathFilterExpression, node);
194     }
195 
196     public static void sort(List<Node> nodes, String xpathExpression) {
197 
198         getSAXReader().sort(nodes, xpathExpression);
199     }
200 
201     public static void sort(
202         List<Node> nodes, String xpathExpression, boolean distinct) {
203 
204         getSAXReader().sort(nodes, xpathExpression, distinct);
205     }
206 
207     public void setSAXReader(SAXReader saxReader) {
208         _saxReader = saxReader;
209     }
210 
211     private static Log _log = LogFactoryUtil.getLog(SAXReaderUtil.class);
212 
213     private static SAXReader _saxReader;
214 
215 }