You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2003/09/14 06:04:00 UTC

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

mrglavas    2003/09/13 21:04:00

  Modified:    java/src/org/apache/xerces/impl XMLVersionDetector.java
  Log:
  Bug: Incorrect locator info was reported for errors in 1.1 external entities.
  The locator must be replaced in the error reporter before parsing with the current entity scanner.
  
  Revision  Changes    Path
  1.8       +68 -65    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLVersionDetector.java	27 Mar 2003 18:23:17 -0000	1.7
  +++ XMLVersionDetector.java	14 Sep 2003 04:04:00 -0000	1.8
  @@ -145,12 +145,12 @@
               fExpectedVersionString[i] = ' ';
       } // reset(XMLComponentManager)
   
  -	/**
  -	 * Reset the reference to the appropriate scanner given the version of the
  +    /**
  +     * Reset the reference to the appropriate scanner given the version of the
        * document and start document scanning.
  -	 * @param scanner - the scanner to use
  -	 * @param version - the version of the document (XML 1.1 or XML 1.0).
  -	 */
  +     * @param scanner - the scanner to use
  +     * @param version - the version of the document (XML 1.1 or XML 1.0).
  +     */
       public void startDocumentParsing(XMLEntityHandler scanner, short version){
   
           if (version == Constants.XML_VERSION_1_0){
  @@ -159,6 +159,9 @@
           else {
               fEntityManager.setScannerVersion(Constants.XML_VERSION_1_1);
           }
  +        // Make sure the locator used by the error reporter is the current entity scanner.
  +        fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  +        
           // Note: above we reset fEntityScanner in the entity manager, thus in startEntity
           // in each scanner fEntityScanner field must be reset to reflect the change.
           // 
  @@ -168,70 +171,70 @@
       }
   
   
  -	/**
  -	 * This methods scans the XML declaration to find out the version 
  +    /**
  +     * This methods scans the XML declaration to find out the version 
        * (and provisional encoding)  of the document.
        * The scanning is doing using XML 1.1 scanner.
  -	 * @param inputSource
  -	 * @return short - Constants.XML_VERSION_1_1 if document version 1.1, 
  +     * @param inputSource
  +     * @return short - Constants.XML_VERSION_1_1 if document version 1.1, 
        *                  otherwise Constants.XML_VERSION_1_0 
  -	 * @throws IOException
  -	 */
  -	public short determineDocVersion(XMLInputSource inputSource) throws IOException {
  -		fEncoding = fEntityManager.setupCurrentEntity(fXMLSymbol, inputSource, false, true);
  +     * @throws IOException
  +     */
  +    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();
  -		try {
  -			if (!scanner.skipString("<?xml")) {
  -				// definitely not a well-formed 1.1 doc!
  -				return Constants.XML_VERSION_1_0;
  -			}
  -			if (!scanner.skipSpaces()) {
  -				fixupCurrentEntity(fEntityManager, fExpectedVersionString, 5);
  -				return Constants.XML_VERSION_1_0;
  -			}
  -			if (!scanner.skipString("version")) {
  -				fixupCurrentEntity(fEntityManager, fExpectedVersionString, 6);
  -				return Constants.XML_VERSION_1_0;
  -			}
  -			scanner.skipSpaces();
  -			if (scanner.scanChar() != '=') {
  -				fixupCurrentEntity(fEntityManager, fExpectedVersionString, 13);
  -				return Constants.XML_VERSION_1_0;
  -			}
  -			scanner.skipSpaces();
  -			int quoteChar = scanner.scanChar();
  -			fExpectedVersionString[14] = (char) quoteChar;
  -			for (int versionPos = 0; versionPos < XML11_VERSION.length; versionPos++) {
  -				fExpectedVersionString[15 + versionPos] = (char) scanner.scanChar();
  -			}
  -			// REVISIT:  should we check whether this equals quoteChar? 
  -			fExpectedVersionString[18] = (char) scanner.scanChar();
  -			fixupCurrentEntity(fEntityManager, fExpectedVersionString, 19);
  -			int matched = 0;
  -			for (; matched < XML11_VERSION.length; matched++) {
  -				if (fExpectedVersionString[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;
  +        // 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, fExpectedVersionString, 5);
  +                return Constants.XML_VERSION_1_0;
  +            }
  +            if (!scanner.skipString("version")) {
  +                fixupCurrentEntity(fEntityManager, fExpectedVersionString, 6);
  +                return Constants.XML_VERSION_1_0;
  +            }
  +            scanner.skipSpaces();
  +            if (scanner.scanChar() != '=') {
  +                fixupCurrentEntity(fEntityManager, fExpectedVersionString, 13);
  +                return Constants.XML_VERSION_1_0;
  +            }
  +            scanner.skipSpaces();
  +            int quoteChar = scanner.scanChar();
  +            fExpectedVersionString[14] = (char) quoteChar;
  +            for (int versionPos = 0; versionPos < XML11_VERSION.length; versionPos++) {
  +                fExpectedVersionString[15 + versionPos] = (char) scanner.scanChar();
  +            }
  +            // REVISIT:  should we check whether this equals quoteChar? 
  +            fExpectedVersionString[18] = (char) scanner.scanChar();
  +            fixupCurrentEntity(fEntityManager, fExpectedVersionString, 19);
  +            int matched = 0;
  +            for (; matched < XML11_VERSION.length; matched++) {
  +                if (fExpectedVersionString[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.
  
  
  

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