java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 16 Jun 2014 11:11:01 +0200
changeset 44 7bd195a5fa2a
parent 32 ecc2731a5a46
child 61 1980a333904c
permissions -rw-r--r--
AbstractAlt2XmlReader: support features
franta-hg@11
     1
/**
franta-hg@11
     2
 * Alt2XML
franta-hg@11
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@11
     4
 *
franta-hg@11
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@11
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@11
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@11
     8
 * (at your option) any later version.
franta-hg@11
     9
 *
franta-hg@11
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@11
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@11
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@11
    13
 * GNU General Public License for more details.
franta-hg@11
    14
 *
franta-hg@11
    15
 * You should have received a copy of the GNU General Public License
franta-hg@11
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@11
    17
 */
franta-hg@16
    18
package cz.frantovo.alt2xml;
franta-hg@2
    19
franta-hg@2
    20
import java.io.IOException;
franta-hg@4
    21
import java.util.HashMap;
franta-hg@4
    22
import java.util.Map;
franta-hg@2
    23
import org.xml.sax.ContentHandler;
franta-hg@2
    24
import org.xml.sax.DTDHandler;
franta-hg@2
    25
import org.xml.sax.EntityResolver;
franta-hg@2
    26
import org.xml.sax.ErrorHandler;
franta-hg@2
    27
import org.xml.sax.InputSource;
franta-hg@2
    28
import org.xml.sax.SAXException;
franta-hg@2
    29
import org.xml.sax.SAXNotRecognizedException;
franta-hg@2
    30
import org.xml.sax.SAXNotSupportedException;
franta-hg@2
    31
import org.xml.sax.XMLReader;
franta-hg@2
    32
franta-hg@2
    33
/**
franta-hg@17
    34
 * Recommended base class for all alternative format readers.
franta-hg@2
    35
 *
franta-hg@17
    36
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@2
    37
 */
franta-hg@17
    38
public abstract class AbstractAlt2XmlReader implements XMLReader {
franta-hg@2
    39
franta-hg@17
    40
	protected ContentHandler contentHandler;
franta-hg@17
    41
	protected ErrorHandler errorHandler;
franta-hg@17
    42
	protected DTDHandler dtdHandler;
franta-hg@17
    43
	protected EntityResolver entityResolver;
franta-hg@17
    44
	protected Map<String, Object> properties = new HashMap<>();
franta-hg@44
    45
	protected Map<String, Boolean> features = new HashMap<>();
franta-hg@6
    46
franta-hg@6
    47
	@Override
franta-hg@6
    48
	public void parse(String systemId) throws IOException, SAXException {
franta-hg@6
    49
		parse(new InputSource(systemId));
franta-hg@6
    50
	}
franta-hg@6
    51
franta-hg@6
    52
	@Override
franta-hg@2
    53
	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@7
    54
		/**
franta-hg@15
    55
		 * TODO:
franta-hg@15
    56
		 * All XMLReaders are required to recognize
franta-hg@15
    57
		 * the http://xml.org/sax/features/namespaces
franta-hg@7
    58
		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
franta-hg@7
    59
		 */
franta-hg@44
    60
		Boolean feature = features.get(name);
franta-hg@44
    61
		return feature == null ? false : feature;
franta-hg@2
    62
	}
franta-hg@2
    63
franta-hg@2
    64
	@Override
franta-hg@2
    65
	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@44
    66
		/**
franta-hg@44
    67
		 * TODO: filtrovat – povolit jen náš jmenný prostor
franta-hg@44
    68
		 */
franta-hg@44
    69
		features.put(name, value);
franta-hg@2
    70
	}
franta-hg@2
    71
franta-hg@2
    72
	@Override
franta-hg@2
    73
	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@17
    74
		return properties.get(name);
franta-hg@2
    75
	}
franta-hg@2
    76
franta-hg@2
    77
	@Override
franta-hg@2
    78
	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
franta-hg@17
    79
		properties.put(name, value);
franta-hg@2
    80
	}
franta-hg@2
    81
franta-hg@2
    82
	@Override
franta-hg@4
    83
	public void setEntityResolver(EntityResolver entityResolver) {
franta-hg@4
    84
		this.entityResolver = entityResolver;
franta-hg@2
    85
	}
franta-hg@2
    86
franta-hg@2
    87
	@Override
franta-hg@2
    88
	public EntityResolver getEntityResolver() {
franta-hg@4
    89
		return entityResolver;
franta-hg@2
    90
	}
franta-hg@2
    91
franta-hg@2
    92
	@Override
franta-hg@4
    93
	public void setDTDHandler(DTDHandler dtdHandler) {
franta-hg@4
    94
		this.dtdHandler = dtdHandler;
franta-hg@2
    95
	}
franta-hg@2
    96
franta-hg@2
    97
	@Override
franta-hg@2
    98
	public DTDHandler getDTDHandler() {
franta-hg@4
    99
		return dtdHandler;
franta-hg@2
   100
	}
franta-hg@2
   101
franta-hg@2
   102
	@Override
franta-hg@4
   103
	public void setContentHandler(ContentHandler contentHandler) {
franta-hg@4
   104
		this.contentHandler = contentHandler;
franta-hg@2
   105
	}
franta-hg@2
   106
franta-hg@2
   107
	@Override
franta-hg@2
   108
	public ContentHandler getContentHandler() {
franta-hg@2
   109
		return contentHandler;
franta-hg@2
   110
	}
franta-hg@2
   111
franta-hg@2
   112
	@Override
franta-hg@4
   113
	public void setErrorHandler(ErrorHandler errorHandler) {
franta-hg@4
   114
		this.errorHandler = errorHandler;
franta-hg@2
   115
	}
franta-hg@2
   116
franta-hg@2
   117
	@Override
franta-hg@2
   118
	public ErrorHandler getErrorHandler() {
franta-hg@4
   119
		return errorHandler;
franta-hg@2
   120
	}
franta-hg@2
   121
}