3 * Copyright © 2014 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package cz.frantovo.alt2xml;
20 import java.io.IOException;
21 import java.util.HashMap;
23 import org.xml.sax.ContentHandler;
24 import org.xml.sax.DTDHandler;
25 import org.xml.sax.EntityResolver;
26 import org.xml.sax.ErrorHandler;
27 import org.xml.sax.InputSource;
28 import org.xml.sax.SAXException;
29 import org.xml.sax.SAXNotRecognizedException;
30 import org.xml.sax.SAXNotSupportedException;
31 import org.xml.sax.XMLReader;
34 * Recommended base class for all alternative format readers.
36 * @author Ing. František Kučera (frantovo.cz)
38 public abstract class AbstractAlt2XmlReader implements XMLReader {
40 protected ContentHandler contentHandler;
41 protected ErrorHandler errorHandler;
42 protected DTDHandler dtdHandler;
43 protected EntityResolver entityResolver;
44 protected Map<String, Object> properties = new HashMap<>();
45 protected Map<String, Boolean> features = new HashMap<>();
48 public void parse(String systemId) throws IOException, SAXException {
49 parse(new InputSource(systemId));
53 public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
56 * All XMLReaders are required to recognize
57 * the http://xml.org/sax/features/namespaces
58 * and the http://xml.org/sax/features/namespace-prefixes feature names.
60 Boolean feature = features.get(name);
61 return feature == null ? false : feature;
65 public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
67 * TODO: filtrovat – povolit jen náš jmenný prostor
69 features.put(name, value);
73 public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
74 return properties.get(name);
78 public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
79 properties.put(name, value);
83 public void setEntityResolver(EntityResolver entityResolver) {
84 this.entityResolver = entityResolver;
88 public EntityResolver getEntityResolver() {
89 return entityResolver;
93 public void setDTDHandler(DTDHandler dtdHandler) {
94 this.dtdHandler = dtdHandler;
98 public DTDHandler getDTDHandler() {
103 public void setContentHandler(ContentHandler contentHandler) {
104 this.contentHandler = contentHandler;
108 public ContentHandler getContentHandler() {
109 return contentHandler;
113 public void setErrorHandler(ErrorHandler errorHandler) {
114 this.errorHandler = errorHandler;
118 public ErrorHandler getErrorHandler() {