1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.xml;
16  
17  import java.io.File;
18  import java.io.InputStream;
19  import java.io.Reader;
20  
21  import java.net.MalformedURLException;
22  import java.net.URL;
23  
24  import java.util.List;
25  import java.util.Map;
26  
27  /**
28   * <a href="SAXReaderUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class SAXReaderUtil {
33  
34      public static Attribute createAttribute(
35          Element element, QName qName, String value) {
36  
37          return getSAXReader().createAttribute(element, qName, value);
38      }
39  
40      public static Attribute createAttribute(
41          Element element, String name, String value) {
42  
43          return getSAXReader().createAttribute(element, name, value);
44      }
45  
46      public static Document createDocument() {
47          return getSAXReader().createDocument();
48      }
49  
50      public static Document createDocument(Element rootElement) {
51          return getSAXReader().createDocument(rootElement);
52      }
53  
54      public static Document createDocument(String encoding) {
55          return getSAXReader().createDocument(encoding);
56      }
57  
58      public static Element createElement(QName qName) {
59          return getSAXReader().createElement(qName);
60      }
61  
62      public static Element createElement(String name) {
63          return getSAXReader().createElement(name);
64      }
65  
66      public static Entity createEntity(String name, String text) {
67          return getSAXReader().createEntity(name, text);
68      }
69  
70      public static Namespace createNamespace(String uri) {
71          return getSAXReader().createNamespace(uri);
72      }
73  
74      public static Namespace createNamespace(String prefix, String uri) {
75          return getSAXReader().createNamespace(prefix, uri);
76      }
77  
78      public static ProcessingInstruction createProcessingInstruction(
79          String target, Map<String, String> data) {
80  
81          return getSAXReader().createProcessingInstruction(target, data);
82      }
83  
84      public static ProcessingInstruction createProcessingInstruction(
85          String target, String data) {
86  
87          return getSAXReader().createProcessingInstruction(target, data);
88      }
89  
90      public static QName createQName(String localName) {
91          return getSAXReader().createQName(localName);
92      }
93  
94      public static QName createQName(String localName, Namespace namespace) {
95          return getSAXReader().createQName(localName, namespace);
96      }
97  
98      public static Text createText(String text) {
99          return getSAXReader().createText(text);
100     }
101 
102     public static XPath createXPath(String xpathExpression) {
103         return getSAXReader().createXPath(xpathExpression);
104     }
105 
106     public static SAXReader getSAXReader() {
107         return _saxReader;
108     }
109 
110     public static Document read(File file) throws DocumentException {
111         return getSAXReader().read(file);
112     }
113 
114     public static Document read(File file, boolean validate)
115         throws DocumentException {
116 
117         return getSAXReader().read(file, validate);
118     }
119 
120     public static Document read(InputStream is) throws DocumentException {
121         return getSAXReader().read(is);
122     }
123 
124     public static Document read(InputStream is, boolean validate)
125         throws DocumentException {
126 
127         return getSAXReader().read(is, validate);
128     }
129 
130     public static Document read(Reader reader) throws DocumentException {
131         return getSAXReader().read(reader);
132     }
133 
134     public static Document read(Reader reader, boolean validate)
135         throws DocumentException {
136 
137         return getSAXReader().read(reader, validate);
138     }
139 
140     public static Document read(String xml) throws DocumentException {
141         return getSAXReader().read(xml);
142     }
143 
144     public static Document read(String xml, boolean validate)
145         throws DocumentException {
146 
147         return getSAXReader().read(xml, validate);
148     }
149 
150     public static Document read(URL url) throws DocumentException {
151         return getSAXReader().read(url);
152     }
153 
154     public static Document read(URL url, boolean validate)
155         throws DocumentException {
156 
157         return getSAXReader().read(url, validate);
158     }
159 
160     public static Document readURL(String url)
161         throws DocumentException, MalformedURLException {
162 
163         return getSAXReader().readURL(url);
164     }
165 
166     public static Document readURL(String url, boolean validate)
167         throws DocumentException, MalformedURLException {
168 
169         return getSAXReader().readURL(url, validate);
170     }
171 
172     public static List<Node> selectNodes(
173         String xpathFilterExpression, List<Node> nodes) {
174 
175         return getSAXReader().selectNodes(xpathFilterExpression, nodes);
176     }
177 
178     public static List<Node> selectNodes(
179         String xpathFilterExpression, Node node) {
180 
181         return getSAXReader().selectNodes(xpathFilterExpression, node);
182     }
183 
184     public static void sort(List<Node> nodes, String xpathExpression) {
185 
186         getSAXReader().sort(nodes, xpathExpression);
187     }
188 
189     public static void sort(
190         List<Node> nodes, String xpathExpression, boolean distinct) {
191 
192         getSAXReader().sort(nodes, xpathExpression, distinct);
193     }
194 
195     public void setSAXReader(SAXReader saxReader) {
196         _saxReader = saxReader;
197     }
198 
199     private static SAXReader _saxReader;
200 
201 }