Podpora konfigurace.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 03 Jan 2012 14:39:16 +0100
changeset 4e2b2f34cdb50
parent 3 6c608fd8c019
child 5 c2496cf043c3
Podpora konfigurace.
java/alt2xml/src/cz/frantovo/alt2xml/SAXTovarna.java
java/alt2xml/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java
java/alt2xml/src/cz/frantovo/alt2xml/vstup/SuperReader.java
     1.1 --- a/java/alt2xml/src/cz/frantovo/alt2xml/SAXTovarna.java	Tue Jan 03 12:55:38 2012 +0100
     1.2 +++ b/java/alt2xml/src/cz/frantovo/alt2xml/SAXTovarna.java	Tue Jan 03 14:39:16 2012 +0100
     1.3 @@ -1,8 +1,6 @@
     1.4  package cz.frantovo.alt2xml;
     1.5  
     1.6  import cz.frantovo.alt2xml.vstup.SuperReader;
     1.7 -import java.util.logging.Level;
     1.8 -import java.util.logging.Logger;
     1.9  import javax.xml.parsers.ParserConfigurationException;
    1.10  import javax.xml.parsers.SAXParser;
    1.11  import javax.xml.parsers.SAXParserFactory;
    1.12 @@ -25,17 +23,16 @@
    1.13  
    1.14  	@Override
    1.15  	public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
    1.16 -		throw new UnsupportedOperationException("Not supported yet.");
    1.17 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    1.18  	}
    1.19  
    1.20  	@Override
    1.21  	public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
    1.22 -		throw new UnsupportedOperationException("Not supported yet.");
    1.23 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    1.24  	}
    1.25  
    1.26  	private static class MůjParser extends SAXParser {
    1.27  
    1.28 -		private static final Logger log = Logger.getLogger(MůjParser.class.getName());
    1.29  		private XMLReader xmlReader;
    1.30  
    1.31  		public MůjParser(XMLReader xmlReader) {
    1.32 @@ -44,9 +41,7 @@
    1.33  
    1.34  		@Override
    1.35  		public Parser getParser() throws SAXException {
    1.36 -			// TODO: dopsat
    1.37 -			log.log(Level.FINE, "getParser");
    1.38 -			return null;
    1.39 +			throw new SAXException("Není podporováno.");
    1.40  		}
    1.41  
    1.42  		@Override
    1.43 @@ -56,29 +51,22 @@
    1.44  
    1.45  		@Override
    1.46  		public boolean isNamespaceAware() {
    1.47 -			// TODO: dopsat
    1.48 -			log.log(Level.FINE, "isNamespaceAware");
    1.49  			return false;
    1.50  		}
    1.51  
    1.52  		@Override
    1.53  		public boolean isValidating() {
    1.54 -			// TODO: dopsat
    1.55 -			log.log(Level.FINE, "isValidating");
    1.56  			return false;
    1.57  		}
    1.58  
    1.59  		@Override
    1.60  		public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    1.61 -			// TODO: dopsat
    1.62 -			log.log(Level.FINE, "setProperty: {0} = {1}", new Object[]{name, value});
    1.63 +			xmlReader.setProperty(name, value);
    1.64  		}
    1.65  
    1.66  		@Override
    1.67  		public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    1.68 -			// TODO: dopsat
    1.69 -			log.log(Level.FINE, "getProperty: {0}", name);
    1.70 -			return null;
    1.71 +			return xmlReader.getProperty(name);
    1.72  		}
    1.73  	}
    1.74  }
    1.75 \ No newline at end of file
     2.1 --- a/java/alt2xml/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Tue Jan 03 12:55:38 2012 +0100
     2.2 +++ b/java/alt2xml/src/cz/frantovo/alt2xml/vstup/JsonSimpleContentHandler.java	Tue Jan 03 14:39:16 2012 +0100
     2.3 @@ -7,7 +7,7 @@
     2.4  import org.xml.sax.SAXException;
     2.5  
     2.6  /**
     2.7 -) *
     2.8 + *
     2.9   * @author fiki
    2.10   */
    2.11  public class JsonSimpleContentHandler implements org.json.simple.parser.ContentHandler {
     3.1 --- a/java/alt2xml/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Tue Jan 03 12:55:38 2012 +0100
     3.2 +++ b/java/alt2xml/src/cz/frantovo/alt2xml/vstup/SuperReader.java	Tue Jan 03 14:39:16 2012 +0100
     3.3 @@ -2,8 +2,8 @@
     3.4  
     3.5  import java.io.IOException;
     3.6  import java.io.InputStreamReader;
     3.7 -import java.util.logging.Level;
     3.8 -import java.util.logging.Logger;
     3.9 +import java.util.HashMap;
    3.10 +import java.util.Map;
    3.11  import org.json.simple.parser.JSONParser;
    3.12  import org.json.simple.parser.ParseException;
    3.13  import org.xml.sax.ContentHandler;
    3.14 @@ -22,84 +22,70 @@
    3.15   */
    3.16  public class SuperReader implements XMLReader {
    3.17  
    3.18 -	private static final Logger log = Logger.getLogger(SuperReader.class.getName());
    3.19  	private ContentHandler contentHandler;
    3.20 +	private ErrorHandler errorHandler;
    3.21 +	private DTDHandler dtdHandler;
    3.22 +	private EntityResolver entityResolver;
    3.23 +	private Map<String, Object> konfigurace = new HashMap<>();
    3.24  
    3.25  	@Override
    3.26  	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    3.27 -		// TODO: dopsat
    3.28 -		log.log(Level.FINE, "getFeature: {0}", name);
    3.29 -		return false;
    3.30 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    3.31  	}
    3.32  
    3.33  	@Override
    3.34  	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
    3.35 -		// TODO: dopsat
    3.36 -		log.log(Level.FINE, "setFeature: {0} = {1}", new Object[]{name, value});
    3.37 +		throw new SAXNotSupportedException("Zatím není podporováno.");
    3.38  	}
    3.39  
    3.40  	@Override
    3.41  	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
    3.42 -		// TODO: dopsat
    3.43 -		log.log(Level.FINE, "getProperty: {0}", name);
    3.44 -		return null;
    3.45 +		return konfigurace.get(name);
    3.46  	}
    3.47  
    3.48  	@Override
    3.49  	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
    3.50 -		// TODO: dopsat
    3.51 -		log.log(Level.FINE, "setProperty: {0} = {1}", new Object[]{name, value});
    3.52 +		konfigurace.put(name, value);
    3.53  	}
    3.54  
    3.55  	@Override
    3.56 -	public void setEntityResolver(EntityResolver resolver) {
    3.57 -		// TODO: dopsat
    3.58 -		log.log(Level.FINE, "setEntityResolver: {0}", resolver);
    3.59 +	public void setEntityResolver(EntityResolver entityResolver) {
    3.60 +		this.entityResolver = entityResolver;
    3.61  	}
    3.62  
    3.63  	@Override
    3.64  	public EntityResolver getEntityResolver() {
    3.65 -		// TODO: dopsat
    3.66 -		log.log(Level.FINE, "getEntityResolver");
    3.67 -		return null;
    3.68 +		return entityResolver;
    3.69  	}
    3.70  
    3.71  	@Override
    3.72 -	public void setDTDHandler(DTDHandler handler) {
    3.73 -		// TODO: dopsat
    3.74 -		log.log(Level.FINE, "setDTDHandler: {0}", handler);
    3.75 +	public void setDTDHandler(DTDHandler dtdHandler) {
    3.76 +		this.dtdHandler = dtdHandler;
    3.77  	}
    3.78  
    3.79  	@Override
    3.80  	public DTDHandler getDTDHandler() {
    3.81 -		// TODO: dopsat
    3.82 -		log.log(Level.FINE, "getDTDHandler");
    3.83 -		return null;
    3.84 +		return dtdHandler;
    3.85  	}
    3.86  
    3.87  	@Override
    3.88 -	public void setContentHandler(ContentHandler handler) {
    3.89 -		// TODO: dopsat
    3.90 -		contentHandler = handler;
    3.91 +	public void setContentHandler(ContentHandler contentHandler) {
    3.92 +		this.contentHandler = contentHandler;
    3.93  	}
    3.94  
    3.95  	@Override
    3.96  	public ContentHandler getContentHandler() {
    3.97 -		// TODO: dopsat
    3.98  		return contentHandler;
    3.99  	}
   3.100  
   3.101  	@Override
   3.102 -	public void setErrorHandler(ErrorHandler handler) {
   3.103 -		// TODO: dopsat
   3.104 -		log.log(Level.FINE, "setErrorHandler: {0}", handler);
   3.105 +	public void setErrorHandler(ErrorHandler errorHandler) {
   3.106 +		this.errorHandler = errorHandler;
   3.107  	}
   3.108  
   3.109  	@Override
   3.110  	public ErrorHandler getErrorHandler() {
   3.111 -		// TODO: dopsat
   3.112 -		log.log(Level.FINE, "getErrorHandler");
   3.113 -		return null;
   3.114 +		return errorHandler;
   3.115  	}
   3.116  
   3.117  	@Override
   3.118 @@ -107,7 +93,6 @@
   3.119  		/**
   3.120  		 * TODO: rozpornat formát vstupu a podle toho delegovat
   3.121  		 */
   3.122 -		
   3.123  		JSONParser p = new JSONParser();
   3.124  		InputStreamReader vstup = new InputStreamReader(input.getByteStream());
   3.125  		JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
   3.126 @@ -122,6 +107,6 @@
   3.127  	@Override
   3.128  	public void parse(String systemId) throws IOException, SAXException {
   3.129  		// TODO: dopsat
   3.130 -		throw new UnsupportedOperationException("Zatím není podporované.");
   3.131 +		throw new SAXException("Zatím není podporováno.");
   3.132  	}
   3.133  }