You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2003/03/27 17:27:35 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl XMLVersionDetector.java XMLEntityManager.java

elena       2003/03/27 08:27:35

  Modified:    java/src/org/apache/xerces/impl XMLVersionDetector.java
                        XMLEntityManager.java
  Log:
  Fix the EOFException in the case of parsing an empty file.
  
  Revision  Changes    Path
  1.6       +56 -41    xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java
  
  Index: XMLVersionDetector.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLVersionDetector.java	3 Mar 2003 22:17:17 -0000	1.5
  +++ XMLVersionDetector.java	27 Mar 2003 16:27:34 -0000	1.6
  @@ -57,8 +57,10 @@
   
   package org.apache.xerces.impl;
   
  +import java.io.EOFException;
   import java.io.IOException;
   
  +import org.apache.xerces.impl.msg.XMLMessageFormatter;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.xni.XMLString;
   import org.apache.xerces.xni.parser.XMLComponentManager;
  @@ -174,48 +176,61 @@
        *                  otherwise Constants.XML_VERSION_1_0 
   	 * @throws IOException
   	 */
  -    public short determineDocVersion(XMLInputSource inputSource) throws IOException {
  -        fEncoding = fEntityManager.setupCurrentEntity(fXMLSymbol, inputSource, false, true);
  +	public short determineDocVersion(XMLInputSource inputSource) throws IOException {
  +		fEncoding = fEntityManager.setupCurrentEntity(fXMLSymbol, inputSource, false, true);
   
  -        // must assume 1.1 at this stage so that whitespace
  -        // handling is correct in the XML decl...
  -        fEntityManager.setScannerVersion(Constants.XML_VERSION_1_1);
  -        XMLEntityScanner scanner = fEntityManager.getEntityScanner();
  -        if(!scanner.skipString("<?xml"))  {
  -            // definitely not a well-formed 1.1 doc!
  -            return Constants.XML_VERSION_1_0;
  -        }
  -        if(!scanner.skipSpaces()) {
  -            fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 5);
  -            return Constants.XML_VERSION_1_0;
  -        }
  -        if(!scanner.skipString("version"))  {
  -            fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 6);
  -            return Constants.XML_VERSION_1_0;
  -        }
  -        scanner.skipSpaces();
  -        if(scanner.scanChar() != '=') {
  -            fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 13);
  -            return Constants.XML_VERSION_1_0;
  -        }
  -        scanner.skipSpaces();
  -        int quoteChar = scanner.scanChar();
  -        EXPECTED_VERSION_STRING[14] = (char)quoteChar;
  -        for (int versionPos=0; versionPos<XML11_VERSION.length; versionPos++) {
  -            EXPECTED_VERSION_STRING[15+versionPos] = (char)scanner.scanChar();
  -        } 
  -        // REVISIT:  should we check whether this equals quoteChar? 
  -        EXPECTED_VERSION_STRING[18] = (char)scanner.scanChar();
  -        fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 19);
  -        int matched = 0;
  -        for(; matched<XML11_VERSION.length; matched++) {
  -            if(EXPECTED_VERSION_STRING[15+matched] != XML11_VERSION[matched]) break;
  -        }
  -        if(matched == XML11_VERSION.length)
  -            return Constants.XML_VERSION_1_1;
  -        return Constants.XML_VERSION_1_0;
  +		// must assume 1.1 at this stage so that whitespace
  +		// handling is correct in the XML decl...
  +		fEntityManager.setScannerVersion(Constants.XML_VERSION_1_1);
  +		XMLEntityScanner scanner = fEntityManager.getEntityScanner();
  +		try {
  +			if (!scanner.skipString("<?xml")) {
  +				// definitely not a well-formed 1.1 doc!
  +				return Constants.XML_VERSION_1_0;
  +			}
  +			if (!scanner.skipSpaces()) {
  +				fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 5);
  +				return Constants.XML_VERSION_1_0;
  +			}
  +			if (!scanner.skipString("version")) {
  +				fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 6);
  +				return Constants.XML_VERSION_1_0;
  +			}
  +			scanner.skipSpaces();
  +			if (scanner.scanChar() != '=') {
  +				fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 13);
  +				return Constants.XML_VERSION_1_0;
  +			}
  +			scanner.skipSpaces();
  +			int quoteChar = scanner.scanChar();
  +			EXPECTED_VERSION_STRING[14] = (char) quoteChar;
  +			for (int versionPos = 0; versionPos < XML11_VERSION.length; versionPos++) {
  +				EXPECTED_VERSION_STRING[15 + versionPos] = (char) scanner.scanChar();
  +			}
  +			// REVISIT:  should we check whether this equals quoteChar? 
  +			EXPECTED_VERSION_STRING[18] = (char) scanner.scanChar();
  +			fixupCurrentEntity(fEntityManager, EXPECTED_VERSION_STRING, 19);
  +			int matched = 0;
  +			for (; matched < XML11_VERSION.length; matched++) {
  +				if (EXPECTED_VERSION_STRING[15 + matched] != XML11_VERSION[matched])
  +					break;
  +			}
  +			if (matched == XML11_VERSION.length)
  +				return Constants.XML_VERSION_1_1;
  +			return Constants.XML_VERSION_1_0;
  +			// premature end of file
  +		}
  +		catch (EOFException e) {
  +			fErrorReporter.reportError(
  +				XMLMessageFormatter.XML_DOMAIN,
  +				"PrematureEOF",
  +				null,
  +				XMLErrorReporter.SEVERITY_FATAL_ERROR);
  +			return Constants.XML_VERSION_1_0;
  +			
  +		}
   
  -    }
  +	}
   
       // This method prepends "length" chars from the char array,
       // from offset 0, to the manager's fCurrentEntity.ch.
  
  
  
  1.64      +2 -1      xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- XMLEntityManager.java	26 Mar 2003 04:19:22 -0000	1.63
  +++ XMLEntityManager.java	27 Mar 2003 16:27:34 -0000	1.64
  @@ -1266,6 +1266,7 @@
                   fEntities.put(key, value);
               }
           }
  +        fEntityHandler = null;
   
       } // reset(XMLComponentManager)
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org