You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/10/25 00:50:00 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util NamespaceSupport.java

andyc       00/10/24 15:49:59

  Modified:    java/src/org/apache/xerces/impl Tag: xerces_j_2
                        XMLDocumentScanner.java
  Added:       java/src/org/apache/xerces/impl Tag: xerces_j_2
                        XMLNamespaceBinder.java
               java/src/org/apache/xerces/util Tag: xerces_j_2
                        NamespaceSupport.java
  Log:
  1) Removed namespace binding code from the document scanner. Because
     of the nature of DTD validation vs. Schema validation *and* the
     way that default attribute values can affect the way that namespace
     binding works, the validator is now responsible for performing the
     namespace binding operation.
     For DTD validation, namespace binding should occur *after* the
     validation step so that default attributes can be added. However,
     for Schema validation, namespace binding should occur *before*
     the validation step.
  2) Created a namespace binder component that performs namespace
     binding. That way we can remove the validation stage in the
     pipeline completely and still retain namespace support through
     the use of the XMLNamespaceBinder component.
  3) Wrote a simple NamespaceSupport class that performs the basic
     operations of the SAX2 helper class of the same name. This
     version compares prefixes and URIs as symbols and uses a lot
     less memory than the SAX2 counterpart.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.41  +1 -120    xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java
  
  Index: XMLDocumentScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java,v
  retrieving revision 1.1.2.40
  retrieving revision 1.1.2.41
  diff -u -r1.1.2.40 -r1.1.2.41
  --- XMLDocumentScanner.java	2000/10/24 01:28:02	1.1.2.40
  +++ XMLDocumentScanner.java	2000/10/24 22:49:55	1.1.2.41
  @@ -59,7 +59,6 @@
   
   import java.io.EOFException;
   import java.io.IOException;
  -import java.util.Enumeration;
   import java.util.Stack;
   
   import org.apache.xerces.impl.XMLEntityManager;
  @@ -83,7 +82,6 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXNotSupportedException;
  -import org.xml.sax.helpers.NamespaceSupport;
   
   /**
    * This class is responsible for scanning XML document structure
  @@ -102,7 +100,7 @@
    * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
    * @author Andy Clark, IBM
    *
  - * @version $Id: XMLDocumentScanner.java,v 1.1.2.40 2000/10/24 01:28:02 andyc Exp $
  + * @version $Id: XMLDocumentScanner.java,v 1.1.2.41 2000/10/24 22:49:55 andyc Exp $
    */
   public class XMLDocumentScanner
       extends XMLScanner
  @@ -236,11 +234,6 @@
       /** Namespaces. */
       protected boolean fNamespaces;
   
  -    // namespaces
  -
  -    /** Namespace support. */
  -    protected NamespaceSupport fNamespaceSupport = new NamespaceSupport();
  -
       // dispatchers
   
       /** Active dispatcher. */
  @@ -294,12 +287,6 @@
       /** Symbol: "apos". */
       private String fAposSymbol;
   
  -    /** Symbol: "xml". */
  -    private String fXmlSymbol;
  -
  -    /** Symbol: "xmlns". */
  -    private String fXmlnsSymbol;
  -
       /** Symbol: "CDATA". */
       private String fCDATASymbol;
   
  @@ -371,7 +358,6 @@
           // initialize vars
           fEntityStack.removeAllElements();
           fEntityDepth = 0;
  -        fNamespaceSupport.reset();
   
           fElementDepth = 0;
           fCurrentElement = null;
  @@ -387,8 +373,6 @@
           fGtSymbol = fSymbolTable.addSymbol("gt");
           fQuotSymbol = fSymbolTable.addSymbol("quot");
           fAposSymbol = fSymbolTable.addSymbol("apos");
  -        fXmlSymbol = fSymbolTable.addSymbol("xml");
  -        fXmlnsSymbol = fSymbolTable.addSymbol("xmlns");
           fCDATASymbol = fSymbolTable.addSymbol("CDATA");
   
           // setup dispatcher
  @@ -918,11 +902,6 @@
   
           } while (true);
   
  -        // bind namespaces
  -        if (fNamespaces) {
  -            bindNamespaces(fElementQName, fAttributes);
  -        }
  -
           // push element stack
           fCurrentElement = fElementStack.pushElement(fElementQName);
   
  @@ -1283,89 +1262,6 @@
           }
       } // handleCharacter(char)
   
  -    /**
  -     * Binds the namespaces. This method will handle calling the
  -     * document handler to start the prefix mappings.
  -     * <p>
  -     * <strong>Note:</strong> This method makes use of the
  -     * fAttributeQName variable. Any contents of the variable will
  -     * be destroyed. Caller should copy the values out of this
  -     * temporary variable before calling this method.
  -     *
  -     * @param element    The element name.
  -     * @param attributes The attributes for the element.
  -     *
  -     * @throws SAXException Thrown if handler throws SAX exception upon
  -     *                      notification of start prefix mapping.
  -     */
  -    protected void bindNamespaces(QName element, XMLAttributes attributes)
  -        throws SAXException {
  -
  -        // add new namespace context
  -        fNamespaceSupport.pushContext();
  -
  -        // search for new namespace bindings
  -        int length = attributes.getLength();
  -        for (int i = 0; i < length; i++) {
  -            String rawname = attributes.getQName(i);
  -            if (rawname.startsWith("xmlns")) {
  -                // declare prefix in context
  -                String prefix = rawname.length() > 5
  -                              ? attributes.getLocalName(i) : "";
  -                String uri = attributes.getValue(i);
  -                fNamespaceSupport.declarePrefix(prefix, uri);
  -
  -                // call handler
  -                if (fDocumentHandler != null) {
  -                    fDocumentHandler.startPrefixMapping(prefix, uri);
  -                }
  -            }
  -        }
  -
  -        // bind the element
  -        String prefix = element.prefix != null
  -                      ? element.prefix : "";
  -        element.uri = fNamespaceSupport.getURI(prefix);
  -        if (element.prefix == null && element.uri != null) {
  -            element.prefix = fSymbolTable.addSymbol("");
  -        }
  -        if (element.prefix != null && element.uri == null) {
  -            fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,
  -                                       "ElementPrefixUnbound",
  -                                       new Object[]{element.prefix, element.rawname},
  -                                       XMLErrorReporter.SEVERITY_FATAL_ERROR);
  -        }
  -
  -        // bind the attributes
  -        for (int i = 0; i < length; i++) {
  -            attributes.getName(i, fAttributeQName);
  -            String arawname = fAttributeQName.rawname;
  -            String aprefix = fAttributeQName.prefix != null 
  -                           ? fAttributeQName.prefix : "";
  -            if (aprefix == fXmlSymbol) {
  -                fAttributeQName.uri = NamespaceSupport.XMLNS;
  -                attributes.setName(i, fAttributeQName);
  -            }
  -            else if (arawname != fXmlnsSymbol && !arawname.startsWith("xmlns:")) {
  -                if (fAttributeQName.prefix != null) {
  -                    fAttributeQName.uri = fNamespaceSupport.getURI(fAttributeQName.prefix);
  -                    if (fAttributeQName.uri == null) {
  -                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,
  -                                                   "AttributePrefixUnbound",
  -                                                   new Object[]{fAttributeQName.prefix, fAttributeQName.rawname},
  -                                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);
  -                    }
  -                }
  -                else {
  -                    // attributes with no prefix get element's uri
  -                    fAttributeQName.uri = element.uri;
  -                }
  -                attributes.setName(i, fAttributeQName);
  -            }
  -        }
  -
  -    } // bindNamespaces(QName,XMLAttributes)
  -
       /** 
        * Handles the end element. This method will make sure that
        * the end element name matches the current element and notify
  @@ -1402,21 +1298,6 @@
           // call handler
           if (fDocumentHandler != null) {
               fDocumentHandler.endElement(element);
  -        }
  -
  -        // end prefix mappings
  -        if (fNamespaces) {
  -            // call handler
  -            if (fDocumentHandler != null) {
  -                Enumeration prefixes = fNamespaceSupport.getDeclaredPrefixes();
  -                while (prefixes.hasMoreElements()) {
  -                    String prefix = (String)prefixes.nextElement();
  -                    fDocumentHandler.endPrefixMapping(prefix);
  -                }
  -            }
  -
  -            // pop context
  -            fNamespaceSupport.popContext();
           }
   
           return fElementDepth;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +665 -0    xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLNamespaceBinder.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +312 -0    xml-xerces/java/src/org/apache/xerces/util/Attic/NamespaceSupport.java