java/alt2xml-bin/src/cz/frantovo/alt2xml/SAXTovarna.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 05 Jun 2014 22:01:58 +0200
changeset 11 aaf6648af0aa
parent 7 9107f7df660c
child 15 b890783e4043
permissions -rw-r--r--
licence
     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 cz.frantovo.alt2xml.vstup.SuperReader;
    21 import javax.xml.parsers.ParserConfigurationException;
    22 import javax.xml.parsers.SAXParser;
    23 import javax.xml.parsers.SAXParserFactory;
    24 import org.xml.sax.Parser;
    25 import org.xml.sax.SAXException;
    26 import org.xml.sax.SAXNotRecognizedException;
    27 import org.xml.sax.SAXNotSupportedException;
    28 import org.xml.sax.XMLReader;
    29 
    30 /**
    31  *
    32  * @author fiki
    33  */
    34 public class SAXTovarna extends SAXParserFactory {
    35 
    36 	@Override
    37 	public SAXParser newSAXParser() throws ParserConfigurationException, SAXException {
    38 		return new AltSAXParser(new SuperReader());
    39 	}
    40 
    41 	@Override
    42 	public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
    43 		throw new SAXNotSupportedException("Zatím není podporováno.");
    44 	}
    45 
    46 	@Override
    47 	public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
    48 		throw new SAXNotSupportedException("Zatím není podporováno.");
    49 	}
    50 
    51 	private static class AltSAXParser extends SAXParser {
    52 
    53 		private XMLReader xmlReader;
    54 
    55 		public AltSAXParser(XMLReader xmlReader) {
    56 			this.xmlReader = xmlReader;
    57 		}
    58 
    59 		@Override
    60 		@Deprecated
    61 		public Parser getParser() throws SAXException {
    62 			throw new SAXException("Není podporováno.");
    63 		}
    64 
    65 		@Override
    66 		public XMLReader getXMLReader() throws SAXException {
    67 			return xmlReader;
    68 		}
    69 
    70 		@Override
    71 		public boolean isNamespaceAware() {
    72 			return true;
    73 		}
    74 
    75 		@Override
    76 		public boolean isValidating() {
    77 			return false;
    78 		}
    79 
    80 		@Override
    81 		public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    82 			xmlReader.setProperty(name, value);
    83 		}
    84 
    85 		@Override
    86 		public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    87 			return xmlReader.getProperty(name);
    88 		}
    89 	}
    90 }