neilg       2003/03/25 20:19:23

  Modified:    java/src/org/apache/xerces/parsers AbstractSAXParser.java
               java/src/org/apache/xerces/util ErrorHandlerWrapper.java
               java/src/org/apache/xerces/impl XMLScanner.java
                        XMLEntityScanner.java XMLEntityManager.java
               java/src/org/apache/xerces/impl/xs/util SimpleLocator.java
  Log:
  implementation of XNI change (addition of getEncoding to XMLLocator)
  
  Revision  Changes    Path
  1.40      +63 -4     
xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java
  
  Index: AbstractSAXParser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- AbstractSAXParser.java    10 Feb 2003 22:21:34 -0000      1.39
  +++ AbstractSAXParser.java    26 Mar 2003 04:19:22 -0000      1.40
  @@ -211,6 +211,9 @@
        */
       protected boolean fParseInProgress = false;
   
  +    // track the version of the document being parsed
  +    protected String fVersion;
  +
       // temp vars
       private final AttributesProxy fAttributesProxy = new AttributesProxy();
       private Augmentations fAugmentations = null;
  @@ -274,6 +277,7 @@
           throws XNIException {
           
           fNamespaceContext = namespaceContext;
  +
           try {
               // SAX1
               if (fDocumentHandler != null) {
  @@ -298,6 +302,27 @@
       } // startDocument(locator,encoding,augs)
   
       /**
  +     * Notifies of the presence of an XMLDecl line in the document. If
  +     * present, this method will be called immediately following the
  +     * startDocument call.
  +     * 
  +     * @param version    The XML version.
  +     * @param encoding   The IANA encoding name of the document, or null if
  +     *                   not specified.
  +     * @param standalone The standalone value, or null if not specified.
  +     * @param augs   Additional information that may include infoset augmentations
  +     *
  +     * @throws XNIException Thrown by handler to signal an error.
  +     */
  +    public void xmlDecl(String version, String encoding, String standalone, 
Augmentations augs)
  +        throws XNIException {
  +
  +        // the version need only be set once; if
  +        // document's XML 1.0|1.1, that's how it'll stay
  +        fVersion = version;
  +    } // xmlDecl(String,String,String)
  +
  +    /**
        * Notifies of the presence of the DOCTYPE line in the document.
        *
        * @param rootElement The name of the root element.
  @@ -1070,7 +1095,19 @@
               if (ex == null) {
                   // must be a parser exception; mine it for locator info and throw
                   // a SAXParseException
  -                LocatorImpl locatorImpl = new LocatorImpl();
  +                LocatorImpl locatorImpl = new LocatorImpl(){
  +                    public String getXMLVersion() {
  +                        return fVersion;
  +                    }
  +                    // since XMLParseExceptions know nothing about encoding,
  +                    // we cannot return anything meaningful in this context.
  +                    // We *could* consult the LocatorProxy, but the
  +                    // application can do this itself if it wishes to possibly
  +                    // be mislead.
  +                    public String getEncoding() {
  +                        return null;
  +                    }
  +                };
                   locatorImpl.setPublicId(e.getPublicId());
                   locatorImpl.setSystemId(e.getExpandedSystemId());
                   locatorImpl.setLineNumber(e.getLineNumber());
  @@ -1131,7 +1168,19 @@
               if (ex == null) {
                   // must be a parser exception; mine it for locator info and throw
                   // a SAXParseException
  -                LocatorImpl locatorImpl = new LocatorImpl();
  +                LocatorImpl locatorImpl = new LocatorImpl() {
  +                    public String getXMLVersion() {
  +                        return fVersion;
  +                    }
  +                    // since XMLParseExceptions know nothing about encoding,
  +                    // we cannot return anything meaningful in this context.
  +                    // We *could* consult the LocatorProxy, but the
  +                    // application can do this itself if it wishes to possibly
  +                    // be mislead.
  +                    public String getEncoding() {
  +                        return null;
  +                    }
  +                };
                   locatorImpl.setPublicId(e.getPublicId());
                   locatorImpl.setSystemId(e.getExpandedSystemId());
                   locatorImpl.setLineNumber(e.getLineNumber());
  @@ -1894,6 +1943,7 @@
   
           // reset state
           fInDTD = false;
  +        fVersion = "1.0";
   
           // features
           fNamespaces = fConfiguration.getFeature(NAMESPACES);           
  @@ -1907,7 +1957,7 @@
       // Classes
       //
   
  -    protected static class LocatorProxy
  +    protected class LocatorProxy
           implements Locator {
   
           //
  @@ -1947,6 +1997,15 @@
           /** Column number. */
           public int getColumnNumber() {
               return fLocator.getColumnNumber();
  +        }
  +
  +        // Locator2 methods
  +        public String getXMLVersion() {
  +            return fVersion;
  +        }
  +
  +        public String getEncoding() {
  +            return fLocator.getEncoding();
           }
   
       } // class LocatorProxy
  
  
  
  1.7       +3 -2      
xml-xerces/java/src/org/apache/xerces/util/ErrorHandlerWrapper.java
  
  Index: ErrorHandlerWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/util/ErrorHandlerWrapper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ErrorHandlerWrapper.java  16 Dec 2002 01:26:21 -0000      1.6
  +++ ErrorHandlerWrapper.java  26 Mar 2003 04:19:22 -0000      1.7
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001, 2002 The Apache Software Foundation.  
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -256,6 +256,7 @@
               public void setColumnNumber(int col) {}
               public int getLineNumber() { return fLineNumber; }
               public void setLineNumber(int line) {}
  +            public String getEncoding() { return null; }
           };
           return new XMLParseException(location, exception.getMessage(),
                                        exception.getException());
  
  
  
  1.27      +2 -2      xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java
  
  Index: XMLScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- XMLScanner.java   3 Mar 2003 22:17:17 -0000       1.26
  +++ XMLScanner.java   26 Mar 2003 04:19:22 -0000      1.27
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  
  
  
  1.14      +28 -2     xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java
  
  Index: XMLEntityScanner.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XMLEntityScanner.java     12 Feb 2003 17:10:33 -0000      1.13
  +++ XMLEntityScanner.java     26 Mar 2003 04:19:22 -0000      1.14
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.
  + * Copyright (c) 1999-2003 The Apache Software Foundation.
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -85,6 +85,10 @@
       private static final boolean DEBUG_ENCODINGS = false;
       private static final boolean DEBUG_BUFFER = false;
   
  +    //
  +    // Data
  +    //
  +
       private XMLEntityManager fEntityManager = null;
       protected XMLEntityManager.ScannedEntity fCurrentEntity = null;
   
  @@ -183,6 +187,7 @@
                   }
                   //fCurrentEntity.stream.reset();
                   fCurrentEntity.setReader(fCurrentEntity.stream, encoding, null);
  +                fCurrentEntity.encoding = encoding;
               } else {
                   if (DEBUG_ENCODINGS)
                       System.out.println("$$$ reusing old reader on stream");
  @@ -1437,6 +1442,27 @@
   
           return -1;
       } // getColumnNumber():int
  +    
  +    /** Returns the encoding of the current entity.  
  +     * Note that, for a given entity, this value can only be
  +     * considered final once the encoding declaration has been read (or once it
  +     * has been determined that there is no such declaration) since, no encoding
  +     * having been specified on the XMLInputSource, the parser
  +     * will make an initial "guess" which could be in error. 
  +     */
  +    public String getEncoding() {
  +        if (fCurrentEntity != null) {
  +            if (fCurrentEntity.isExternal()) {
  +                return fCurrentEntity.encoding;
  +            }
  +            else {
  +                // ask current entity to find appropriate column number
  +                return fCurrentEntity.getEncoding();
  +            }
  +        }
  +
  +        return null;
  +    } // getEncoding():String
       
       /**
        * @see org.apache.xerces.xni.XMLLocator#setColumnNumber(int)
  
  
  
  1.63      +15 -2     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.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- XMLEntityManager.java     12 Feb 2003 17:10:33 -0000      1.62
  +++ XMLEntityManager.java     26 Mar 2003 04:19:22 -0000      1.63
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.
  + * Copyright (c) 1999-2003 The Apache Software Foundation.
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -2391,6 +2391,19 @@
                   }
               }
               return -1;
  +        }
  +
  +        // return encoding of most recent external entity
  +        public String getEncoding() {
  +            // search for the first external entity on the stack
  +            int size = fEntityStack.size();
  +            for (int i=size-1; i>0 ; i--) {
  +               ScannedEntity firstExternalEntity = 
(ScannedEntity)fEntityStack.elementAt(i);
  +                if (firstExternalEntity.isExternal()) {
  +                    return firstExternalEntity.encoding;
  +                }
  +            }
  +            return null;
           }
   
           //
  
  
  
  1.3       +12 -2     
xml-xerces/java/src/org/apache/xerces/impl/xs/util/SimpleLocator.java
  
  Index: SimpleLocator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/util/SimpleLocator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleLocator.java        16 Dec 2002 01:26:20 -0000      1.2
  +++ SimpleLocator.java        26 Mar 2003 04:19:23 -0000      1.3
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2002, 2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -146,5 +146,15 @@
         * @see org.apache.xerces.xni.XMLResourceIdentifier#setPublicId(String)
         */
        public void setPublicId(String publicId) {}
  +
  +    /** Returns the encoding of the current entity.  
  +     * Since these locators are used in the construction of
  +     * XMLParseExceptions, which know nothing about encodings, there is
  +     * no point in having this object deal intelligently 
  +     * with encoding information.
  +     */
  +    public String getEncoding() {
  +        return null;
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to