001    /**
002     * Copyright (c) 2000-2010 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 SAXReader getSAXReader() {
105                    return _saxReader;
106            }
107    
108            public static Document read(File file) throws DocumentException {
109                    return getSAXReader().read(file);
110            }
111    
112            public static Document read(File file, boolean validate)
113                    throws DocumentException {
114    
115                    return getSAXReader().read(file, validate);
116            }
117    
118            public static Document read(InputStream is) throws DocumentException {
119                    return getSAXReader().read(is);
120            }
121    
122            public static Document read(InputStream is, boolean validate)
123                    throws DocumentException {
124    
125                    return getSAXReader().read(is, validate);
126            }
127    
128            public static Document read(Reader reader) throws DocumentException {
129                    return getSAXReader().read(reader);
130            }
131    
132            public static Document read(Reader reader, boolean validate)
133                    throws DocumentException {
134    
135                    return getSAXReader().read(reader, validate);
136            }
137    
138            public static Document read(String xml) throws DocumentException {
139                    return getSAXReader().read(xml);
140            }
141    
142            public static Document read(String xml, boolean validate)
143                    throws DocumentException {
144    
145                    return getSAXReader().read(xml, validate);
146            }
147    
148            public static Document read(URL url) throws DocumentException {
149                    return getSAXReader().read(url);
150            }
151    
152            public static Document read(URL url, boolean validate)
153                    throws DocumentException {
154    
155                    return getSAXReader().read(url, validate);
156            }
157    
158            public static Document readURL(String url)
159                    throws DocumentException, MalformedURLException {
160    
161                    return getSAXReader().readURL(url);
162            }
163    
164            public static Document readURL(String url, boolean validate)
165                    throws DocumentException, MalformedURLException {
166    
167                    return getSAXReader().readURL(url, validate);
168            }
169    
170            public static List<Node> selectNodes(
171                    String xpathFilterExpression, List<Node> nodes) {
172    
173                    return getSAXReader().selectNodes(xpathFilterExpression, nodes);
174            }
175    
176            public static List<Node> selectNodes(
177                    String xpathFilterExpression, Node node) {
178    
179                    return getSAXReader().selectNodes(xpathFilterExpression, node);
180            }
181    
182            public static void sort(List<Node> nodes, String xpathExpression) {
183    
184                    getSAXReader().sort(nodes, xpathExpression);
185            }
186    
187            public static void sort(
188                    List<Node> nodes, String xpathExpression, boolean distinct) {
189    
190                    getSAXReader().sort(nodes, xpathExpression, distinct);
191            }
192    
193            public void setSAXReader(SAXReader saxReader) {
194                    _saxReader = saxReader;
195            }
196    
197            private static SAXReader _saxReader;
198    
199    }