java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 07 Jun 2014 15:03:52 +0200
changeset 21 ac4e617f44e7
parent 19 a58dce1054af
child 22 23a12c58b57c
permissions -rw-r--r--
vylepšený alt2xml-in-properties a SuperReader
     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.net.URI;
    22 import java.util.HashMap;
    23 import java.util.Map;
    24 import org.xml.sax.ContentHandler;
    25 import org.xml.sax.DTDHandler;
    26 import org.xml.sax.EntityResolver;
    27 import org.xml.sax.ErrorHandler;
    28 import org.xml.sax.InputSource;
    29 import org.xml.sax.SAXException;
    30 import org.xml.sax.SAXNotRecognizedException;
    31 import org.xml.sax.SAXNotSupportedException;
    32 import org.xml.sax.XMLReader;
    33 
    34 /**
    35  *
    36  * @author Ing. František Kučera (frantovo.cz)
    37  */
    38 public class SuperReader implements XMLReader {
    39 
    40 	private ContentHandler contentHandler;
    41 	private ErrorHandler errorHandler;
    42 	private DTDHandler dtdHandler;
    43 	private EntityResolver entityResolver;
    44 	private Map<String, Object> properties = new HashMap<>();
    45 	private final ReaderFinder readerFinder;
    46 
    47 	public SuperReader(ReaderFinder readerFinder) {
    48 		this.readerFinder = readerFinder;
    49 	}
    50 
    51 	@Override
    52 	public void parse(InputSource input) throws IOException, SAXException {
    53 
    54 		System.err.println("SystemId: " + input.getSystemId());
    55 		
    56 		XMLReader reader = readerFinder.findReader(input.getSystemId());
    57 		reader.parse(input);
    58 	}
    59 
    60 	@Override
    61 	public void parse(String systemId) throws IOException, SAXException {
    62 		parse(new InputSource(systemId));
    63 	}
    64 
    65 	@Override
    66 	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    67 		/**
    68 		 * TODO:
    69 		 * All XMLReaders are required to recognize
    70 		 * the http://xml.org/sax/features/namespaces
    71 		 * and the http://xml.org/sax/features/namespace-prefixes feature names.
    72 		 */
    73 		throw new SAXNotSupportedException("Zatím není podporováno.");
    74 	}
    75 
    76 	@Override
    77 	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
    78 		throw new SAXNotSupportedException("Zatím není podporováno.");
    79 	}
    80 
    81 	@Override
    82 	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    83 		return properties.get(name);
    84 	}
    85 
    86 	@Override
    87 	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    88 		properties.put(name, value);
    89 	}
    90 
    91 	@Override
    92 	public void setEntityResolver(EntityResolver entityResolver) {
    93 		this.entityResolver = entityResolver;
    94 	}
    95 
    96 	@Override
    97 	public EntityResolver getEntityResolver() {
    98 		return entityResolver;
    99 	}
   100 
   101 	@Override
   102 	public void setDTDHandler(DTDHandler dtdHandler) {
   103 		this.dtdHandler = dtdHandler;
   104 	}
   105 
   106 	@Override
   107 	public DTDHandler getDTDHandler() {
   108 		return dtdHandler;
   109 	}
   110 
   111 	@Override
   112 	public void setContentHandler(ContentHandler contentHandler) {
   113 		this.contentHandler = contentHandler;
   114 	}
   115 
   116 	@Override
   117 	public ContentHandler getContentHandler() {
   118 		return contentHandler;
   119 	}
   120 
   121 	@Override
   122 	public void setErrorHandler(ErrorHandler errorHandler) {
   123 		this.errorHandler = errorHandler;
   124 	}
   125 
   126 	@Override
   127 	public ErrorHandler getErrorHandler() {
   128 		return errorHandler;
   129 	}
   130 }