use AltInputSource instead of just systemId in canRead() and findReader()
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 08 Jun 2014 09:53:51 +0200
changeset 36ad36a104623f
parent 35 106c5d280835
child 37 03f940508c72
use AltInputSource instead of just systemId in canRead() and findReader()
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AltInputSource.java
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ReaderFinder.java
java/alt2xml-lib-input/src/cz/frantovo/alt2xml/SuperReader.java
     1.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java	Sun Jun 08 00:01:29 2014 +0200
     1.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlReaderFactory.java	Sun Jun 08 09:53:51 2014 +0200
     1.3 @@ -27,10 +27,10 @@
     1.4  public interface Alt2XmlReaderFactory {
     1.5  
     1.6  	/**
     1.7 -	 * @param systemId system ID of the document to be read
     1.8 +	 * @param inputSource  source of the document to be read
     1.9  	 * @return whether this alternative format is supported
    1.10  	 */
    1.11 -	public boolean canRead(String systemId);
    1.12 +	public boolean canRead(AltInputSource inputSource);
    1.13  
    1.14  	public XMLReader getReader() throws SAXException;
    1.15  }
     2.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java	Sun Jun 08 00:01:29 2014 +0200
     2.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/Alt2XmlRegexReaderFactory.java	Sun Jun 08 09:53:51 2014 +0200
     2.3 @@ -30,7 +30,7 @@
     2.4  	protected abstract Pattern getSystemIdPattern();
     2.5  
     2.6  	@Override
     2.7 -	public boolean canRead(String systemId) {
     2.8 -		return getSystemIdPattern().matcher(systemId).matches();
     2.9 +	public boolean canRead(AltInputSource inputSource) {
    2.10 +		return getSystemIdPattern().matcher(inputSource.getSystemId()).matches();
    2.11  	}
    2.12  }
     3.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AltInputSource.java	Sun Jun 08 00:01:29 2014 +0200
     3.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/AltInputSource.java	Sun Jun 08 09:53:51 2014 +0200
     3.3 @@ -124,4 +124,9 @@
     3.4  	public String getSystemId() {
     3.5  		return originalSource.getSystemId();
     3.6  	}
     3.7 +
     3.8 +	@Override
     3.9 +	public String toString() {
    3.10 +		return "AltInputSource: systemId=" + getSystemId() + " publicId=" + getPublicId();
    3.11 +	}
    3.12  }
     4.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java	Sun Jun 08 00:01:29 2014 +0200
     4.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java	Sun Jun 08 09:53:51 2014 +0200
     4.3 @@ -86,7 +86,7 @@
     4.4  	private class FallbackReaderFactory implements Alt2XmlReaderFactory {
     4.5  
     4.6  		@Override
     4.7 -		public boolean canRead(String systemId) {
     4.8 +		public boolean canRead(AltInputSource inputSource) {
     4.9  			return true;
    4.10  		}
    4.11  
    4.12 @@ -102,13 +102,13 @@
    4.13  	}
    4.14  
    4.15  	@Override
    4.16 -	public XMLReader findReader(String systemId) throws SAXException {
    4.17 +	public XMLReader findReader(AltInputSource inputSource) throws SAXException {
    4.18  		for (Alt2XmlReaderFactory f : readerFactories) {
    4.19 -			if (f.canRead(systemId)) {
    4.20 +			if (f.canRead(inputSource)) {
    4.21  				return f.getReader();
    4.22  			}
    4.23  		}
    4.24 -		throw new SAXException("Iterated over " + readerFactories.size() + " and was unable to find XMLReader for SystemId: " + systemId);
    4.25 +		throw new SAXException("Iterated over " + readerFactories.size() + " and was unable to find XMLReader for SystemId: " + inputSource);
    4.26  	}
    4.27  
    4.28  	@Override
    4.29 @@ -131,7 +131,7 @@
    4.30  
    4.31  	private static class AltSAXParser extends SAXParser {
    4.32  
    4.33 -		private XMLReader xmlReader;
    4.34 +		private final XMLReader xmlReader;
    4.35  
    4.36  		public AltSAXParser(XMLReader xmlReader) {
    4.37  			this.xmlReader = xmlReader;
     5.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ReaderFinder.java	Sun Jun 08 00:01:29 2014 +0200
     5.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ReaderFinder.java	Sun Jun 08 09:53:51 2014 +0200
     5.3 @@ -11,10 +11,10 @@
     5.4  
     5.5  	/**
     5.6  	 *
     5.7 -	 * @param systemId systemId of the document which should be parsed
     5.8 +	 * @param inputSource source of the document which should be parsed
     5.9  	 * @return XMLReader appropriate for this document
    5.10  	 * @throws org.xml.sax.SAXException if we have no reader for given systemId
    5.11  	 */
    5.12 -	public XMLReader findReader(String systemId) throws SAXException;
    5.13 +	public XMLReader findReader(AltInputSource inputSource) throws SAXException;
    5.14  
    5.15  }
     6.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/SuperReader.java	Sun Jun 08 00:01:29 2014 +0200
     6.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/SuperReader.java	Sun Jun 08 09:53:51 2014 +0200
     6.3 @@ -52,9 +52,9 @@
     6.4  	@Override
     6.5  	public void parse(InputSource input) throws IOException, SAXException {
     6.6  
     6.7 -		input = new AltInputSource(entityResolver, input);
     6.8 +		AltInputSource altInput = new AltInputSource(entityResolver, input);
     6.9  
    6.10 -		XMLReader reader = readerFinder.findReader(input.getSystemId());
    6.11 +		XMLReader reader = readerFinder.findReader(altInput);
    6.12  
    6.13  		reader.setContentHandler(contentHandler);
    6.14  		reader.setDTDHandler(dtdHandler);
    6.15 @@ -69,7 +69,7 @@
    6.16  			reader.setFeature(e.getKey(), e.getValue());
    6.17  		}
    6.18  
    6.19 -		reader.parse(input);
    6.20 +		reader.parse(altInput);
    6.21  	}
    6.22  
    6.23  	@Override