001    /**
002     * Copyright (c) 2000-present 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 aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    
021    import java.io.File;
022    import java.io.InputStream;
023    import java.io.Reader;
024    
025    import java.net.MalformedURLException;
026    import java.net.URL;
027    
028    import java.util.List;
029    import java.util.Map;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    @ProviderType
035    public class SAXReaderUtil {
036    
037            public static Attribute createAttribute(
038                    Element element, QName qName, String value) {
039    
040                    return getSAXReader().createAttribute(element, qName, value);
041            }
042    
043            public static Attribute createAttribute(
044                    Element element, String name, String value) {
045    
046                    return getSAXReader().createAttribute(element, name, value);
047            }
048    
049            public static Document createDocument() {
050                    return getSAXReader().createDocument();
051            }
052    
053            public static Document createDocument(Element rootElement) {
054                    return getSAXReader().createDocument(rootElement);
055            }
056    
057            public static Document createDocument(String encoding) {
058                    return getSAXReader().createDocument(encoding);
059            }
060    
061            public static Element createElement(QName qName) {
062                    return getSAXReader().createElement(qName);
063            }
064    
065            public static Element createElement(String name) {
066                    return getSAXReader().createElement(name);
067            }
068    
069            public static Entity createEntity(String name, String text) {
070                    return getSAXReader().createEntity(name, text);
071            }
072    
073            public static Namespace createNamespace(String uri) {
074                    return getSAXReader().createNamespace(uri);
075            }
076    
077            public static Namespace createNamespace(String prefix, String uri) {
078                    return getSAXReader().createNamespace(prefix, uri);
079            }
080    
081            public static ProcessingInstruction createProcessingInstruction(
082                    String target, Map<String, String> data) {
083    
084                    return getSAXReader().createProcessingInstruction(target, data);
085            }
086    
087            public static ProcessingInstruction createProcessingInstruction(
088                    String target, String data) {
089    
090                    return getSAXReader().createProcessingInstruction(target, data);
091            }
092    
093            public static QName createQName(String localName) {
094                    return getSAXReader().createQName(localName);
095            }
096    
097            public static QName createQName(String localName, Namespace namespace) {
098                    return getSAXReader().createQName(localName, namespace);
099            }
100    
101            public static Text createText(String text) {
102                    return getSAXReader().createText(text);
103            }
104    
105            public static XPath createXPath(String xPathExpression) {
106                    return getSAXReader().createXPath(xPathExpression);
107            }
108    
109            public static XPath createXPath(
110                    String xPathExpression, Map<String, String> namespaceContextMap) {
111    
112                    return getSAXReader().createXPath(xPathExpression, namespaceContextMap);
113            }
114    
115            public static XPath createXPath(
116                    String xPathExpression, String prefix, String namespace) {
117    
118                    return getSAXReader().createXPath(xPathExpression, prefix, namespace);
119            }
120    
121            public static SAXReader getSAXReader() {
122                    PortalRuntimePermission.checkGetBeanProperty(SAXReaderUtil.class);
123    
124                    return _saxReader;
125            }
126    
127            public static Document read(File file) throws DocumentException {
128                    return getSAXReader().read(file);
129            }
130    
131            public static Document read(File file, boolean validate)
132                    throws DocumentException {
133    
134                    return getSAXReader().read(file, validate);
135            }
136    
137            public static Document read(InputStream is) throws DocumentException {
138                    return getSAXReader().read(is);
139            }
140    
141            public static Document read(InputStream is, boolean validate)
142                    throws DocumentException {
143    
144                    return getSAXReader().read(is, validate);
145            }
146    
147            public static Document read(Reader reader) throws DocumentException {
148                    return getSAXReader().read(reader);
149            }
150    
151            public static Document read(Reader reader, boolean validate)
152                    throws DocumentException {
153    
154                    return getSAXReader().read(reader, validate);
155            }
156    
157            public static Document read(String xml) throws DocumentException {
158                    return getSAXReader().read(xml);
159            }
160    
161            public static Document read(String xml, boolean validate)
162                    throws DocumentException {
163    
164                    return getSAXReader().read(xml, validate);
165            }
166    
167            public static Document read(String xml, XMLSchema xmlSchema)
168                    throws DocumentException {
169    
170                    return getSAXReader().read(xml, xmlSchema);
171            }
172    
173            public static Document read(URL url) throws DocumentException {
174                    return getSAXReader().read(url);
175            }
176    
177            public static Document read(URL url, boolean validate)
178                    throws DocumentException {
179    
180                    return getSAXReader().read(url, validate);
181            }
182    
183            public static Document readURL(String url)
184                    throws DocumentException, MalformedURLException {
185    
186                    return getSAXReader().readURL(url);
187            }
188    
189            public static Document readURL(String url, boolean validate)
190                    throws DocumentException, MalformedURLException {
191    
192                    return getSAXReader().readURL(url, validate);
193            }
194    
195            public static List<Node> selectNodes(
196                    String xPathFilterExpression, List<Node> nodes) {
197    
198                    return getSAXReader().selectNodes(xPathFilterExpression, nodes);
199            }
200    
201            public static List<Node> selectNodes(
202                    String xPathFilterExpression, Node node) {
203    
204                    return getSAXReader().selectNodes(xPathFilterExpression, node);
205            }
206    
207            public static void sort(List<Node> nodes, String xPathExpression) {
208                    getSAXReader().sort(nodes, xPathExpression);
209            }
210    
211            public static void sort(
212                    List<Node> nodes, String xPathExpression, boolean distinct) {
213    
214                    getSAXReader().sort(nodes, xPathExpression, distinct);
215            }
216    
217            public void setSAXReader(SAXReader saxReader) {
218                    PortalRuntimePermission.checkSetBeanProperty(getClass());
219    
220                    _saxReader = saxReader;
221            }
222    
223            private static SAXReader _saxReader;
224    
225    }