001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.xml;
016    
017    import java.io.File;
018    import java.io.InputStream;
019    import java.io.Reader;
020    
021    import java.net.MalformedURLException;
022    import java.net.URL;
023    
024    import java.util.List;
025    import java.util.Map;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class SAXReaderUtil {
031    
032            public static Attribute createAttribute(
033                    Element element, QName qName, String value) {
034    
035                    return getSAXReader().createAttribute(element, qName, value);
036            }
037    
038            public static Attribute createAttribute(
039                    Element element, String name, String value) {
040    
041                    return getSAXReader().createAttribute(element, name, value);
042            }
043    
044            public static Document createDocument() {
045                    return getSAXReader().createDocument();
046            }
047    
048            public static Document createDocument(Element rootElement) {
049                    return getSAXReader().createDocument(rootElement);
050            }
051    
052            public static Document createDocument(String encoding) {
053                    return getSAXReader().createDocument(encoding);
054            }
055    
056            public static Element createElement(QName qName) {
057                    return getSAXReader().createElement(qName);
058            }
059    
060            public static Element createElement(String name) {
061                    return getSAXReader().createElement(name);
062            }
063    
064            public static Entity createEntity(String name, String text) {
065                    return getSAXReader().createEntity(name, text);
066            }
067    
068            public static Namespace createNamespace(String uri) {
069                    return getSAXReader().createNamespace(uri);
070            }
071    
072            public static Namespace createNamespace(String prefix, String uri) {
073                    return getSAXReader().createNamespace(prefix, uri);
074            }
075    
076            public static ProcessingInstruction createProcessingInstruction(
077                    String target, Map<String, String> data) {
078    
079                    return getSAXReader().createProcessingInstruction(target, data);
080            }
081    
082            public static ProcessingInstruction createProcessingInstruction(
083                    String target, String data) {
084    
085                    return getSAXReader().createProcessingInstruction(target, data);
086            }
087    
088            public static QName createQName(String localName) {
089                    return getSAXReader().createQName(localName);
090            }
091    
092            public static QName createQName(String localName, Namespace namespace) {
093                    return getSAXReader().createQName(localName, namespace);
094            }
095    
096            public static Text createText(String text) {
097                    return getSAXReader().createText(text);
098            }
099    
100            public static XPath createXPath(String xPathExpression) {
101                    return getSAXReader().createXPath(xPathExpression);
102            }
103    
104            public static XPath createXPath(
105                    String xPathExpression, Map<String, String> namespaceContextMap) {
106    
107                    return getSAXReader().createXPath(xPathExpression, namespaceContextMap);
108            }
109    
110            public static XPath createXPath(
111                    String xPathExpression, String prefix, String namespace) {
112    
113                    return getSAXReader().createXPath(xPathExpression, prefix, namespace);
114            }
115    
116            public static SAXReader getSAXReader() {
117                    return _saxReader;
118            }
119    
120            public static Document read(File file) throws DocumentException {
121                    return getSAXReader().read(file);
122            }
123    
124            public static Document read(File file, boolean validate)
125                    throws DocumentException {
126    
127                    return getSAXReader().read(file, validate);
128            }
129    
130            public static Document read(InputStream is) throws DocumentException {
131                    return getSAXReader().read(is);
132            }
133    
134            public static Document read(InputStream is, boolean validate)
135                    throws DocumentException {
136    
137                    return getSAXReader().read(is, validate);
138            }
139    
140            public static Document read(Reader reader) throws DocumentException {
141                    return getSAXReader().read(reader);
142            }
143    
144            public static Document read(Reader reader, boolean validate)
145                    throws DocumentException {
146    
147                    return getSAXReader().read(reader, validate);
148            }
149    
150            public static Document read(String xml) throws DocumentException {
151                    return getSAXReader().read(xml);
152            }
153    
154            public static Document read(String xml, boolean validate)
155                    throws DocumentException {
156    
157                    return getSAXReader().read(xml, validate);
158            }
159    
160            public static Document read(URL url) throws DocumentException {
161                    return getSAXReader().read(url);
162            }
163    
164            public static Document read(URL url, boolean validate)
165                    throws DocumentException {
166    
167                    return getSAXReader().read(url, validate);
168            }
169    
170            public static Document readURL(String url)
171                    throws DocumentException, MalformedURLException {
172    
173                    return getSAXReader().readURL(url);
174            }
175    
176            public static Document readURL(String url, boolean validate)
177                    throws DocumentException, MalformedURLException {
178    
179                    return getSAXReader().readURL(url, validate);
180            }
181    
182            public static List<Node> selectNodes(
183                    String xPathFilterExpression, List<Node> nodes) {
184    
185                    return getSAXReader().selectNodes(xPathFilterExpression, nodes);
186            }
187    
188            public static List<Node> selectNodes(
189                    String xPathFilterExpression, Node node) {
190    
191                    return getSAXReader().selectNodes(xPathFilterExpression, node);
192            }
193    
194            public static void sort(List<Node> nodes, String xPathExpression) {
195    
196                    getSAXReader().sort(nodes, xPathExpression);
197            }
198    
199            public static void sort(
200                    List<Node> nodes, String xPathExpression, boolean distinct) {
201    
202                    getSAXReader().sort(nodes, xPathExpression, distinct);
203            }
204    
205            public void setSAXReader(SAXReader saxReader) {
206                    _saxReader = saxReader;
207            }
208    
209            private static SAXReader _saxReader;
210    
211    }