java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 07 Jun 2014 22:09:32 +0200
changeset 32 ecc2731a5a46
parent 17 java/alt2xml-lib/src/cz/frantovo/alt2xml/AbstractAlt2XmlReader.java@64358dd0999f
child 44 7bd195a5fa2a
permissions -rw-r--r--
rename: alt2xml-lib → alt2xml-lib-input
     1 /**
     2  * Alt2XML
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     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.
     9  *
    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.
    14  *
    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/>.
    17  */
    18 package cz.frantovo.alt2xml;
    19 
    20 import java.io.IOException;
    21 import java.util.HashMap;
    22 import java.util.Map;
    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;
    32 
    33 /**
    34  * Recommended base class for all alternative format readers.
    35  *
    36  * @author Ing. František Kučera (frantovo.cz)
    37  */
    38 public abstract class AbstractAlt2XmlReader implements XMLReader {
    39 
    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 
    46 	@Override
    47 	public void parse(String systemId) throws IOException, SAXException {
    48 		parse(new InputSource(systemId));
    49 	}
    50 
    51 	@Override
    52 	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    53 		/**
    54 		 * TODO:
    55 		 * All XMLReaders are required to recognize
    56 		 * the http://xml.org/sax/features/namespaces
    57 		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
    58 		 */
    59 		throw new SAXNotSupportedException("Zatím není podporováno.");
    60 	}
    61 
    62 	@Override
    63 	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
    64 		throw new SAXNotSupportedException("Zatím není podporováno.");
    65 	}
    66 
    67 	@Override
    68 	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    69 		return properties.get(name);
    70 	}
    71 
    72 	@Override
    73 	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    74 		properties.put(name, value);
    75 	}
    76 
    77 	@Override
    78 	public void setEntityResolver(EntityResolver entityResolver) {
    79 		this.entityResolver = entityResolver;
    80 	}
    81 
    82 	@Override
    83 	public EntityResolver getEntityResolver() {
    84 		return entityResolver;
    85 	}
    86 
    87 	@Override
    88 	public void setDTDHandler(DTDHandler dtdHandler) {
    89 		this.dtdHandler = dtdHandler;
    90 	}
    91 
    92 	@Override
    93 	public DTDHandler getDTDHandler() {
    94 		return dtdHandler;
    95 	}
    96 
    97 	@Override
    98 	public void setContentHandler(ContentHandler contentHandler) {
    99 		this.contentHandler = contentHandler;
   100 	}
   101 
   102 	@Override
   103 	public ContentHandler getContentHandler() {
   104 		return contentHandler;
   105 	}
   106 
   107 	@Override
   108 	public void setErrorHandler(ErrorHandler errorHandler) {
   109 		this.errorHandler = errorHandler;
   110 	}
   111 
   112 	@Override
   113 	public ErrorHandler getErrorHandler() {
   114 		return errorHandler;
   115 	}
   116 }