elena       2002/11/01 17:02:24

  Modified:    java/src/org/apache/xerces/dom AttrNSImpl.java
                        CoreDOMImplementationImpl.java
                        CoreDocumentImpl.java DOMImplementationImpl.java
                        ElementImpl.java ElementNSImpl.java
  Log:
  DOM Implementation now checks if qualifiedName is malformed/invalid per Namespace in 
XML specification.
  (createElementNS/createAttributeNS/createDoctype)
  
  Revision  Changes    Path
  1.32      +38 -47    xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java
  
  Index: AttrNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- AttrNSImpl.java   16 Aug 2002 19:28:37 -0000      1.31
  +++ AttrNSImpl.java   2 Nov 2002 01:02:23 -0000       1.32
  @@ -58,6 +58,7 @@
   package org.apache.xerces.dom;
   
   import org.w3c.dom.DOMException;
  +import org.apache.xerces.xni.NamespaceContext;
   
   /**
    * AttrNSImpl inherits from AttrImpl and adds namespace support. 
  @@ -108,53 +109,43 @@
           setName(namespaceURI, qualifiedName);
       }
   
  -    private void setName(String namespaceURI, String qualifiedName)
  -        throws DOMException
  -    {
  -        int index = qualifiedName.indexOf(':');
  -        String prefix;
  -        // DOM Level 3: namespace URI is never empty string.
  -        this.namespaceURI = (namespaceURI !=null &&
  -                             namespaceURI.length() == 0) ? null : namespaceURI;
  -        
  +    private void setName(String namespaceURI, String qname){
           
  -        if (index < 0) {
  -            prefix = null;
  -            localName = qualifiedName;
  -            if (ownerDocument().errorChecking) {
  -                if ( qualifiedName.equals("xmlns") &&
  -                (namespaceURI == null || !namespaceURI.equals(xmlnsURI)) ||
  -                     (namespaceURI !=null && namespaceURI.equals(xmlnsURI) && 
!qualifiedName.equals("xmlns"))) {
  -                String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                }
  -            }
  -        }
  -        else {
  -            prefix = qualifiedName.substring(0, index); 
  -            localName = qualifiedName.substring(index+1);
  -        
  -            if (ownerDocument().errorChecking) {
  -                if (this.namespaceURI == null
  -                    || (localName.length() == 0)
  -                    || (localName.indexOf(':') >= 0)) {
  -                    String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                } else if (prefix.equals("xml")) {
  -                    if (!namespaceURI.equals(xmlURI)) {
  -                        String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                    }
  -                } else if (prefix.equals("xmlns") && !namespaceURI.equals(xmlnsURI) 
||
  -                           (!prefix.equals("xmlns") && namespaceURI != null && 
  -                            namespaceURI.equals(xmlnsURI))) {
  -                        String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                } else if (index == 0) {
  -                    String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                }
  -            }
  +        String prefix;
  +             // DOM Level 3: namespace URI is never empty string.
  +        this.namespaceURI = namespaceURI;
  +        if (namespaceURI !=null) {
  +             this.namespaceURI = (namespaceURI.length() == 0)? null
  +                                 : namespaceURI.intern();
  +
  +             }
  +             int colon1 = qname.indexOf(':');
  +             int colon2 = qname.lastIndexOf(':');
  +             ownerDocument().checkNamespaceWF(qname, colon1, colon2);
  +             if (colon1 < 0) {
  +                     // there is no prefix
  +                     localName = qname;
  +                     ownerDocument().checkQName(null, localName);
  +                     if (ownerDocument().errorChecking) {
  +                             if (qname.equals("xmlns")
  +                                     && (namespaceURI == null
  +                                             || namespaceURI != 
NamespaceContext.XMLNS_URI)
  +                                     || (namespaceURI == NamespaceContext.XMLNS_URI
  +                                             && !qname.equals("xmlns"))) {
  +                                     String msg =
  +                                             DOMMessageFormatter.formatMessage(
  +                                                     DOMMessageFormatter.DOM_DOMAIN,
  +                                                     "NAMESPACE_ERR",
  +                                                     null);
  +                                     throw new 
DOMException(DOMException.NAMESPACE_ERR, msg);
  +                             }
  +                     }
  +             }
  +             else {
  +                     prefix = qname.substring(0, colon1);
  +                     localName = qname.substring(colon2+1);
  +                     ownerDocument().checkQName(prefix, localName);
  +            ownerDocument().checkDOMNSErr(prefix, namespaceURI);
           }
       } 
   
  
  
  
  1.18      +275 -234  
xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java
  
  Index: CoreDOMImplementationImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CoreDOMImplementationImpl.java    10 Sep 2002 14:04:52 -0000      1.17
  +++ CoreDOMImplementationImpl.java    2 Nov 2002 01:02:23 -0000       1.18
  @@ -54,30 +54,23 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.xerces.dom;
  -
   import org.w3c.dom.DOMException;
   import org.w3c.dom.DOMImplementation;
   import org.w3c.dom.Document;
   import org.w3c.dom.DocumentType;
   import org.w3c.dom.Element;
  -
  -
   // DOM L3 LS
   import org.w3c.dom.ls.DOMImplementationLS;
   import org.w3c.dom.ls.DOMBuilder;
   import org.w3c.dom.ls.DOMWriter;
   import org.w3c.dom.ls.DOMInputSource;
  -
  -
   import org.apache.xerces.parsers.DOMBuilderImpl;
  +import org.apache.xerces.util.XMLChar;
   import org.apache.xml.serialize.DOMWriterImpl;
  -
   // DOM Revalidation
   import org.apache.xerces.impl.RevalidationHandler;
   import org.apache.xerces.util.ObjectFactory;
  -
   /**
    * The DOMImplementation class is description of a particular
    * implementation of the Document Object Model. As such its data is
  @@ -93,241 +86,289 @@
    * @version $Id$
    * @since PR-DOM-Level-1-19980818.
    */
  -public class CoreDOMImplementationImpl  
  -implements DOMImplementation, DOMImplementationLS {
  -
  -    //
  -    // Data
  -    //
  -
  -
  -    RevalidationHandler fDOMRevalidator = null;
  -
  -    boolean free = true;
  -
  -    // static
  -
  -    /** Dom implementation singleton. */
  -    static CoreDOMImplementationImpl singleton = new CoreDOMImplementationImpl();
  +public class CoreDOMImplementationImpl
  +     implements DOMImplementation, DOMImplementationLS {
  +     //
  +     // Data
  +     //
  +     RevalidationHandler fDOMRevalidator = null;
  +     boolean free = true;
  +     // static
  +     /** Dom implementation singleton. */
  +     static CoreDOMImplementationImpl singleton =
  +             new CoreDOMImplementationImpl();
  +     //
  +     // Public methods
  +     //
  +     /** NON-DOM: Obtain and return the single shared object */
  +     public static DOMImplementation getDOMImplementation() {
  +             return singleton;
  +     }
  +     //
  +     // DOMImplementation methods
  +     //
  +     /** 
  +      * Test if the DOM implementation supports a specific "feature" --
  +      * currently meaning language and level thereof.
  +      * 
  +      * @param feature      The package name of the feature to test.
  +      * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
  +      * At this writing, org.apache.xerces.dom supports only XML.
  +      *
  +      * @param version      The version number of the feature being tested.
  +      * This is interpreted as "Version of the DOM API supported for the
  +      * specified Feature", and in Level 1 should be "1.0"
  +      *
  +      * @returns    true iff this implementation is compatable with the
  +      * specified feature and version.
  +      */
  +     public boolean hasFeature(String feature, String version) {
  +             // Currently, we support only XML Level 1 version 1.0
  +             boolean anyVersion = version == null || version.length() == 0;
  +             return (
  +                     feature.equalsIgnoreCase("Core")
  +                             && (anyVersion || version.equals("1.0") || 
version.equals("2.0")))
  +                     || (feature.equalsIgnoreCase("XML")
  +                             && (anyVersion || version.equals("1.0") || 
version.equals("2.0")))
  +                     || (feature.equalsIgnoreCase("LS-Load")
  +                             && (anyVersion || version.equals("3.0")));
  +     } // hasFeature(String,String):boolean
       
  -
  -    //
  -    // Public methods
  -    //
  -
  -    /** NON-DOM: Obtain and return the single shared object */
  -    public static DOMImplementation getDOMImplementation() {
  -        return singleton;
  -    }  
  -
  -
  -    //
  -    // DOMImplementation methods
  -    //
  -
  -    /** 
  -     * Test if the DOM implementation supports a specific "feature" --
  -     * currently meaning language and level thereof.
  -     * 
  -     * @param feature      The package name of the feature to test.
  -     * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
  -     * At this writing, org.apache.xerces.dom supports only XML.
  -     *
  -     * @param version      The version number of the feature being tested.
  -     * This is interpreted as "Version of the DOM API supported for the
  -     * specified Feature", and in Level 1 should be "1.0"
  -     *
  -     * @returns    true iff this implementation is compatable with the
  -     * specified feature and version.
  -     */
  -    public boolean hasFeature(String feature, String version) {
  -
  -        // Currently, we support only XML Level 1 version 1.0
  -        boolean anyVersion = version == null || version.length() == 0;
  -        return 
  -        (feature.equalsIgnoreCase("Core") 
  -         && (anyVersion
  -             || version.equals("1.0")
  -             || version.equals("2.0")))
  -        || (feature.equalsIgnoreCase("XML") 
  -            && (anyVersion
  -                || version.equals("1.0")
  -                || version.equals("2.0")))
  -        || (feature.equalsIgnoreCase("LS-Load")
  -            && (anyVersion 
  -                || version.equals("3.0")));
  -            
  -    } // hasFeature(String,String):boolean
  -
  -
  -    /**
  -     * Introduced in DOM Level 2. <p>
  -     * 
  -     * Creates an empty DocumentType node.
  -     *
  -     * @param qualifiedName The qualified name of the document type to be created. 
  -     * @param publicID The document type public identifier.
  -     * @param systemID The document type system identifier.
  -     * @since WD-DOM-Level-2-19990923
  -     */
  -    public DocumentType       createDocumentType(String qualifiedName, 
  -                                                 String publicID, 
  -                                                 String systemID)
  -    {
  -        if (!CoreDocumentImpl.isXMLName(qualifiedName)) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"INVALID_CHARACTER_ERR", null);
  -            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  -        }
  -        int index = qualifiedName.indexOf(':');
  -        int lastIndex = qualifiedName.lastIndexOf(':');
  +    
  +     /**
  +      * Introduced in DOM Level 2. <p>
  +      * 
  +      * Creates an empty DocumentType node.
  +      *
  +      * @param qualifiedName The qualified name of the document type to be created. 
  +      * @param publicID The document type public identifier.
  +      * @param systemID The document type system identifier.
  +      * @since WD-DOM-Level-2-19990923
  +      */
  +     public DocumentType createDocumentType( String qualifiedName, 
  +                                    String publicID, String systemID) {
  +             // REVISIT: this might allow creation of invalid name for DOCTYPE
  +             //          xmlns prefix.
  +             //          also there is no way for a user to turn off error checking.
  +             checkQName(qualifiedName);
  +             return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
  +     }
  +    
  +    final void checkQName(String qname){
  +        int index = qname.indexOf(':');
  +        int lastIndex = qname.lastIndexOf(':');
  +        int length = qname.length();
  +        
           // it is an error for NCName to have more than one ':'
  -        if (index == 0 || index == qualifiedName.length() - 1 || lastIndex!=index) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  +        // check if it is valid QName [Namespace in XML production 6]
  +        if (index == 0 || index == length - 1 || lastIndex != index) {
  +            String msg =
  +                DOMMessageFormatter.formatMessage(
  +                    DOMMessageFormatter.DOM_DOMAIN,
  +                    "NAMESPACE_ERR",
  +                    null);
               throw new DOMException(DOMException.NAMESPACE_ERR, msg);
           }
  -        return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
  -    }
  -    /**
  -     * Introduced in DOM Level 2. <p>
  -     * 
  -     * Creates an XML Document object of the specified type with its document
  -     * element.
  -     *
  -     * @param namespaceURI     The namespace URI of the document
  -     *                         element to create, or null. 
  -     * @param qualifiedName    The qualified name of the document
  -     *                         element to create. 
  -     * @param doctype          The type of document to be created or null.<p>
  -     *
  -     *                         When doctype is not null, its
  -     *                         Node.ownerDocument attribute is set to
  -     *                         the document being created.
  -     * @return Document        A new Document object.
  -     * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
  -     *                         already been used with a different document.
  -     * @since WD-DOM-Level-2-19990923
  -     */
  -    public Document           createDocument(String namespaceURI, 
  -                                             String qualifiedName, 
  -                                             DocumentType doctype)
  -    throws DOMException
  -    {
  -        if (doctype != null && doctype.getOwnerDocument() != null) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"WRONG_DOCUMENT_ERR", null);
  -            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
  -        }
  -        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
  -        Element e = doc.createElementNS( namespaceURI, qualifiedName);
  -        doc.appendChild(e);
  -        return doc;
  -    }
  -
  -
  -
  -    /**
  -     * DOM Level 3 WD - Experimental.
  -     * This method makes available a <code>DOMImplementation</code>'s 
  -     * specialized interface (see ).
  -     * @param feature The name of the feature requested (case-insensitive).
  -     * @return Returns an alternate <code>DOMImplementation</code> which 
  -     *   implements the specialized APIs of the specified feature, if any, 
  -     *   or <code>null</code> if there is no alternate 
  -     *   <code>DOMImplementation</code> object which implements interfaces 
  -     *   associated with that feature. Any alternate 
  -     *   <code>DOMImplementation</code> returned by this method must 
  -     *   delegate to the primary core <code>DOMImplementation</code> and not 
  -     *   return results inconsistent with the primary 
  -     *   <code>DOMImplementation</code>
  -     */
  -    public DOMImplementation getInterface(String feature){
  -        String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", 
null);
  -        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        
  -    }
  -
  -    // DOM L3 LS
  -    /**
  -     * DOM Level 3 WD - Experimental.
  -     */
  -    public DOMBuilder createDOMBuilder(short mode, 
  -                                       String schemaType)
  -                                       throws DOMException{        
  -        if (mode == DOMImplementationLS.MODE_ASYNCHRONOUS) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", 
null);
  -            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        
  -        }
  -        if (schemaType !=null && schemaType.equals("http://www.w3.org/TR/REC-xml";)) 
{
  -            return new DOMBuilderImpl("org.apache.xerces.parsers.DTDConfiguration", 
schemaType);
  -        } else {
  -            // create default parser configuration validating against XMLSchemas
  -            return new 
DOMBuilderImpl("org.apache.xerces.parsers.StandardParserConfiguration", schemaType);
  -        }
  -    }
  -    /**
  -     * DOM Level 3 WD - Experimental.
  -     */                
  -    public DOMWriter createDOMWriter() {
  -        return new DOMWriterImpl(true);
  -    }
  -    /**
  -     * DOM Level 3 WD - Experimental.
  -     */
  -    public DOMInputSource createDOMInputSource() {
  -        return new DOMInputSourceImpl();
  -    }
  -
  -
  -
  -    //
  -    // Protected methods
  -    //
  -    /** NON-DOM */
  -    synchronized RevalidationHandler getValidator (String schemaType){
  -        // REVISIT: implement a pool of validators to avoid long
  -        //          waiting for several threads
  -        //          implement retrieving grammar based on schemaType
  -        if (fDOMRevalidator == null) {
  -            try {            
  -                // use context class loader.  If it returns
  -                // null, class.forName gets used.
  -                fDOMRevalidator = (RevalidationHandler)  
  -                    
(ObjectFactory.newInstance("org.apache.xerces.impl.xs.XMLSchemaValidator", 
ObjectFactory.findClassLoader(), true));
  -            } catch (Exception e){
  +        int start = 0;
  +        // Namespace in XML production [6]
  +        if (index > 0) {
  +            // check that prefix is NCName
  +            if (!XMLChar.isNCNameStart(qname.charAt(start))) {
  +                String msg =
  +                    DOMMessageFormatter.formatMessage(
  +                        DOMMessageFormatter.DOM_DOMAIN,
  +                        "INVALID_CHARACTER_ERR",
  +                        null);
  +                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
               }
  -        }
  -        while (!isFree()) {
  -            try { 
  -                wait();
  -            }
  -            catch (InterruptedException e){
  -
  -                try {            
  -                    return (RevalidationHandler)  
  -                        
(ObjectFactory.newInstance("org.apache.xerces.impl.xs.XMLSchemaValidator", 
ObjectFactory.findClassLoader(), true));
  -
  -                } catch (Exception exception){
  -                    return null;
  +            for (int i = 1; i < index; i++) {
  +                if (!XMLChar.isNCName(qname.charAt(i))) {
  +                    String msg =
  +                        DOMMessageFormatter.formatMessage(
  +                            DOMMessageFormatter.DOM_DOMAIN,
  +                            "INVALID_CHARACTER_ERR",
  +                            null);
  +                    throw new DOMException(
  +                        DOMException.INVALID_CHARACTER_ERR,
  +                        msg);
                   }
  -                
               }
  +            start = index + 1;
           }
  -        free = false;
  -        return fDOMRevalidator;        
  -    }
  -    
  -    /** NON-DOM */
  -    synchronized void releaseValidator(String schemaType){
  -        // REVISIT: implement releasing grammar base on the schema type
  -        notifyAll();
  -        free = true;
   
  +        // check local part 
  +        if (!XMLChar.isNCNameStart(qname.charAt(start))) {
  +            // REVISIT: add qname parameter to the message
  +            String msg =
  +                DOMMessageFormatter.formatMessage(
  +                    DOMMessageFormatter.DOM_DOMAIN,
  +                    "INVALID_CHARACTER_ERR",
  +                    null);
  +            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  +        }
  +        for (int i = start + 1; i < length; i++) {
  +            if (!XMLChar.isNCName(qname.charAt(i))) {
  +                String msg =
  +                    DOMMessageFormatter.formatMessage(
  +                        DOMMessageFormatter.DOM_DOMAIN,
  +                        "INVALID_CHARACTER_ERR",
  +                        null);
  +                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  +            }
  +        }           
       }
  -    
  -    /** NON-DOM */
  -    final synchronized boolean isFree(){
  -        return free;
  -    }
  -
  -
   
   
  +     /**
  +      * Introduced in DOM Level 2. <p>
  +      * 
  +      * Creates an XML Document object of the specified type with its document
  +      * element.
  +      *
  +      * @param namespaceURI     The namespace URI of the document
  +      *                         element to create, or null. 
  +      * @param qualifiedName    The qualified name of the document
  +      *                         element to create. 
  +      * @param doctype          The type of document to be created or null.<p>
  +      *
  +      *                         When doctype is not null, its
  +      *                         Node.ownerDocument attribute is set to
  +      *                         the document being created.
  +      * @return Document        A new Document object.
  +      * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
  +      *                         already been used with a different document.
  +      * @since WD-DOM-Level-2-19990923
  +      */
  +     public Document createDocument(
  +             String namespaceURI,
  +             String qualifiedName,
  +             DocumentType doctype)
  +             throws DOMException {
  +             if (doctype != null && doctype.getOwnerDocument() != null) {
  +                     String msg =
  +                             DOMMessageFormatter.formatMessage(
  +                                     DOMMessageFormatter.DOM_DOMAIN,
  +                                     "WRONG_DOCUMENT_ERR",
  +                                     null);
  +                     throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
  +             }
  +             CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
  +             Element e = doc.createElementNS(namespaceURI, qualifiedName);
  +             doc.appendChild(e);
  +             return doc;
  +     }
  +     /**
  +      * DOM Level 3 WD - Experimental.
  +      * This method makes available a <code>DOMImplementation</code>'s 
  +      * specialized interface (see ).
  +      * @param feature The name of the feature requested (case-insensitive).
  +      * @return Returns an alternate <code>DOMImplementation</code> which 
  +      *   implements the specialized APIs of the specified feature, if any, 
  +      *   or <code>null</code> if there is no alternate 
  +      *   <code>DOMImplementation</code> object which implements interfaces 
  +      *   associated with that feature. Any alternate 
  +      *   <code>DOMImplementation</code> returned by this method must 
  +      *   delegate to the primary core <code>DOMImplementation</code> and not 
  +      *   return results inconsistent with the primary 
  +      *   <code>DOMImplementation</code>
  +      */
  +     public DOMImplementation getInterface(String feature) {
  +             String msg =
  +                     DOMMessageFormatter.formatMessage(
  +                             DOMMessageFormatter.DOM_DOMAIN,
  +                             "NOT_SUPPORTED_ERR",
  +                             null);
  +             throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
  +     }
  +     // DOM L3 LS
  +     /**
  +      * DOM Level 3 WD - Experimental.
  +      */
  +     public DOMBuilder createDOMBuilder(short mode, String schemaType)
  +             throws DOMException {
  +             if (mode == DOMImplementationLS.MODE_ASYNCHRONOUS) {
  +                     String msg =
  +                             DOMMessageFormatter.formatMessage(
  +                                     DOMMessageFormatter.DOM_DOMAIN,
  +                                     "NOT_SUPPORTED_ERR",
  +                                     null);
  +                     throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
  +             }
  +             if (schemaType != null
  +                     && schemaType.equals("http://www.w3.org/TR/REC-xml";)) {
  +                     return new DOMBuilderImpl(
  +                             "org.apache.xerces.parsers.DTDConfiguration",
  +                             schemaType);
  +             }
  +             else {
  +                     // create default parser configuration validating against 
XMLSchemas
  +                     return new DOMBuilderImpl(
  +                             
"org.apache.xerces.parsers.StandardParserConfiguration",
  +                             schemaType);
  +             }
  +     }
  +     /**
  +      * DOM Level 3 WD - Experimental.
  +      */
  +     public DOMWriter createDOMWriter() {
  +             return new DOMWriterImpl(true);
  +     }
  +     /**
  +      * DOM Level 3 WD - Experimental.
  +      */
  +     public DOMInputSource createDOMInputSource() {
  +             return new DOMInputSourceImpl();
  +     }
  +     //
  +     // Protected methods
  +     //
  +     /** NON-DOM */
  +     synchronized RevalidationHandler getValidator(String schemaType) {
  +             // REVISIT: implement a pool of validators to avoid long
  +             //          waiting for several threads
  +             //          implement retrieving grammar based on schemaType
  +             if (fDOMRevalidator == null) {
  +                     try {
  +                             // use context class loader.  If it returns
  +                             // null, class.forName gets used.
  +                             fDOMRevalidator =
  +                                     (RevalidationHandler) (ObjectFactory
  +                                             .newInstance(
  +                                                     
"org.apache.xerces.impl.xs.XMLSchemaValidator",
  +                                                     
ObjectFactory.findClassLoader(),
  +                                                     true));
  +                     }
  +                     catch (Exception e) {}
  +             }
  +             while (!isFree()) {
  +                     try {
  +                             wait();
  +                     }
  +                     catch (InterruptedException e) {
  +                             try {
  +                                     return (RevalidationHandler)
  +                                             (ObjectFactory
  +                                                     .newInstance(
  +                                                             
"org.apache.xerces.impl.xs.XMLSchemaValidator",
  +                                                             
ObjectFactory.findClassLoader(),
  +                                                             true));
  +                             }
  +                             catch (Exception exception) {
  +                                     return null;
  +                             }
  +                     }
  +             }
  +             free = false;
  +             return fDOMRevalidator;
  +     }
  +     /** NON-DOM */
  +     synchronized void releaseValidator(String schemaType) {
  +             // REVISIT: implement releasing grammar base on the schema type
  +             notifyAll();
  +             free = true;
  +     }
  +     /** NON-DOM */
  +     final synchronized boolean isFree() {
  +             return free;
  +     }
   } // class DOMImplementationImpl
  
  
  
  1.34      +115 -5    xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
  
  Index: CoreDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- CoreDocumentImpl.java     24 Sep 2002 15:13:09 -0000      1.33
  +++ CoreDocumentImpl.java     2 Nov 2002 01:02:23 -0000       1.34
  @@ -98,6 +98,7 @@
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.util.DOMErrorHandlerWrapper;
   import org.apache.xerces.util.ShadowedSymbolTable;
  +import org.apache.xerces.xni.NamespaceContext;
   import org.apache.xerces.xni.parser.XMLErrorHandler;
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLParserConfiguration;
  @@ -1985,10 +1986,6 @@
       public Attr createAttributeNS(String namespaceURI, String qualifiedName)
           throws DOMException
       {
  -        if (errorChecking && !isXMLName(qualifiedName)) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"INVALID_CHARACTER_ERR", null);
  -            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  -        }
           return new AttrNSImpl(this, namespaceURI, qualifiedName);
       }
   
  @@ -2066,6 +2063,7 @@
   
       } // isXMLName(String):boolean
   
  +   
       //
       // Protected methods
       //
  @@ -2333,7 +2331,119 @@
               fConfiguration.setProperty(DOMValidationConfiguration.GRAMMAR_POOL, 
grammarPool);
           }
       }
  +    
  +    protected final void checkNamespaceWF( String qname, int colon1,
  +                                                          int colon2) {
  +                                                        
  +             if (!errorChecking) {
  +                     return;
  +             }
  +             // it is an error for NCName to have more than one ':'
  +             // check if it is valid QName [Namespace in XML production 6]
  +             if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
  +                     String msg =
  +                             DOMMessageFormatter.formatMessage(
  +                                     DOMMessageFormatter.DOM_DOMAIN,
  +                                     "NAMESPACE_ERR",
  +                                     null);
  +                     throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  +             }
  +     }
  +     protected final void checkDOMNSErr(String prefix,
  +                                              String namespace) {
  +            
  +             if (errorChecking) {
  +                     if (namespace == null) {
  +                             String msg =
  +                                     DOMMessageFormatter.formatMessage(
  +                                             DOMMessageFormatter.DOM_DOMAIN,
  +                                             "NAMESPACE_ERR",
  +                                             null);
  +                             throw new DOMException(DOMException.NAMESPACE_ERR, 
msg);
  +                     }
  +                     else if (
  +                             prefix.equals("xml")
  +                                     && namespace != NamespaceContext.XML_URI) {
  +                             String msg =
  +                                     DOMMessageFormatter.formatMessage(
  +                                             DOMMessageFormatter.DOM_DOMAIN,
  +                                             "NAMESPACE_ERR",
  +                                             null);
  +                             throw new DOMException(DOMException.NAMESPACE_ERR, 
msg);
  +                     }
  +                     else if (
  +                             prefix.equals("xmlns")
  +                                     && namespace != NamespaceContext.XMLNS_URI
  +                                     || (!prefix.equals("xmlns")
  +                                             && namespace == 
NamespaceContext.XMLNS_URI)) {
  +                             String msg =
  +                                     DOMMessageFormatter.formatMessage(
  +                                             DOMMessageFormatter.DOM_DOMAIN,
  +                                             "NAMESPACE_ERR",
  +                                             null);
  +                             throw new DOMException(DOMException.NAMESPACE_ERR, 
msg);
  +                     }
  +             }
  +     }
  +
  +    /**
  +     * 
     * @param n
     * @param data
     */
  +     protected final void checkQName(String prefix, 
  +                                       String local){
  +        if (!errorChecking) {
  +            return;
  +        }
  +        int length;
  +        if (prefix != null) {
  +            length=prefix.length();
  +                     // check that prefix is NCName
  +            if (!XMLChar.isNCNameStart(prefix.charAt(0))) {
  +                String msg =
  +                    DOMMessageFormatter.formatMessage(
  +                        DOMMessageFormatter.DOM_DOMAIN,
  +                        "INVALID_CHARACTER_ERR",
  +                        null);
  +                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  +            }
  +            for (int i = 1; i < length; i++) {
  +                if (!XMLChar.isNCName(prefix.charAt(i))) {
  +                    String msg =
  +                        DOMMessageFormatter.formatMessage(
  +                            DOMMessageFormatter.DOM_DOMAIN,
  +                            "INVALID_CHARACTER_ERR",
  +                            null);
  +                    throw new DOMException(
  +                        DOMException.INVALID_CHARACTER_ERR,
  +                        msg);
  +                }
  +            }            
  +
  +             } 
  +        length = local.length();
  +        // check local part 
  +        if (!XMLChar.isNCNameStart(local.charAt(0))) {
  +            // REVISIT: add qname parameter to the message
  +            String msg =
  +                DOMMessageFormatter.formatMessage(
  +                    DOMMessageFormatter.DOM_DOMAIN,
  +                    "INVALID_CHARACTER_ERR",
  +                    null);
  +            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  +        }
  +        for (int i = 1; i < length; i++) {
  +            if (!XMLChar.isNCName(local.charAt(i))) {
  +                String msg =
  +                    DOMMessageFormatter.formatMessage(
  +                        DOMMessageFormatter.DOM_DOMAIN,
  +                        "INVALID_CHARACTER_ERR",
  +                        null);
  +                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  +            }
  +        }           
  +    }
   
  +    
  +    
       /**
        * NON-DOM: kept for backward compatibility
        * Store user data related to a given node
  
  
  
  1.25      +2 -28     
xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java
  
  Index: DOMImplementationImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DOMImplementationImpl.java        24 Jul 2002 19:08:41 -0000      1.24
  +++ DOMImplementationImpl.java        2 Nov 2002 01:02:23 -0000       1.25
  @@ -148,33 +148,7 @@
       } // hasFeature(String,String):boolean
   
       
  -    /**
  -     * Introduced in DOM Level 2. <p>
  -     * 
  -     * Creates an empty DocumentType node.
  -     *
  -     * @param qualifiedName The qualified name of the document type to be created. 
  -     * @param publicID The document type public identifier.
  -     * @param systemID The document type system identifier.
  -     * @since WD-DOM-Level-2-19990923
  -     */
  -    public DocumentType       createDocumentType(String qualifiedName, 
  -                                                 String publicID, 
  -                                                 String systemID)
  -    {
  -     if (!CoreDocumentImpl.isXMLName(qualifiedName)) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"INVALID_CHARACTER_ERR", null);
  -             throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
  -        }
  -        int index = qualifiedName.indexOf(':');
  -        int lastIndex = qualifiedName.lastIndexOf(':');
  -        // it is an error for NCName to have more than one ':'
  -        if (index == 0 || index == qualifiedName.length() - 1 || lastIndex!=index) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -             throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -         }
  -     return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
  -    }
  +
       /**
        * Introduced in DOM Level 2. <p>
        * 
  
  
  
  1.52      +44 -36    xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java
  
  Index: ElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- ElementImpl.java  30 Jul 2002 22:09:29 -0000      1.51
  +++ ElementImpl.java  2 Nov 2002 01:02:23 -0000       1.52
  @@ -623,41 +623,49 @@
        *                          namespaceURI is null or an empty string.
        * @since WD-DOM-Level-2-19990923
        */
  -    public void setAttributeNS(String namespaceURI, String qualifiedName, String 
value) {
  -
  -     if (ownerDocument.errorChecking && isReadOnly()) {
  -            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  -            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
  -        }
  -
  -        if (needsSyncData()) {
  -            synchronizeData();
  -        }
  -
  -        int index = qualifiedName.indexOf(':');
  -        String prefix, localName;
  -        if (index < 0) {
  -            prefix = null;
  -            localName = qualifiedName;
  -        } 
  -        else {
  -            prefix = qualifiedName.substring(0, index); 
  -            localName = qualifiedName.substring(index+1);
  -        }
  -     Attr newAttr = getAttributeNodeNS(namespaceURI, localName);
  -        if (newAttr == null) {
  -            newAttr =
  -                getOwnerDocument().createAttributeNS(namespaceURI, qualifiedName);
  -
  -            if (attributes == null) {
  -                attributes = new AttributeMap(this, null);
  -            }
  -         newAttr.setNodeValue(value);
  -            attributes.setNamedItemNS(newAttr);
  -     }
  -     else {
  -         newAttr.setNodeValue(value);
  -     }
  +     public void setAttributeNS(String namespaceURI,String qualifiedName,
  +                                       String value) {
  +             if (ownerDocument.errorChecking && isReadOnly()) {
  +                     String msg =
  +                             DOMMessageFormatter.formatMessage(
  +                                     DOMMessageFormatter.DOM_DOMAIN,
  +                                     "NO_MODIFICATION_ALLOWED_ERR",
  +                                     null);
  +                     throw new DOMException(
  +                             DOMException.NO_MODIFICATION_ALLOWED_ERR,
  +                             msg);
  +             }
  +             if (needsSyncData()) {
  +                     synchronizeData();
  +             }
  +             int index = qualifiedName.indexOf(':');
  +             String prefix, localName;
  +             if (index < 0) {
  +                     prefix = null;
  +                     localName = qualifiedName;
  +             }
  +             else {
  +                     prefix = qualifiedName.substring(0, index);
  +                     localName = qualifiedName.substring(index + 1);
  +             }
  +             Attr newAttr = getAttributeNodeNS(namespaceURI, localName);
  +             if (newAttr == null) {
  +            // REVISIT: this is not efficient, we are creating twice the same
  +            //          strings for prefix and localName.
  +                     newAttr = getOwnerDocument().createAttributeNS(
  +                                     namespaceURI,
  +                                     qualifiedName);
  +                     if (attributes == null) {
  +                             attributes = new AttributeMap(this, null);
  +                     }
  +                     newAttr.setNodeValue(value);
  +                     attributes.setNamedItemNS(newAttr);
  +             }
  +             else {
  +            // change prefix and value
  +            ((AttrNSImpl)newAttr).name= prefix+":"+localName;
  +                     newAttr.setNodeValue(value);
  +             }
   
       } // setAttributeNS(String,String,String)
       
  
  
  
  1.28      +37 -38    xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
  
  Index: ElementNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ElementNSImpl.java        9 Aug 2002 15:18:14 -0000       1.27
  +++ ElementNSImpl.java        2 Nov 2002 01:02:23 -0000       1.28
  @@ -61,6 +61,7 @@
   import org.w3c.dom.Attr;
   
   import org.apache.xerces.util.URI;
  +import org.apache.xerces.xni.NamespaceContext;
   
   
   
  @@ -109,43 +110,41 @@
           setName(namespaceURI, qualifiedName);
       }
   
  -    private void setName(String namespaceURI, String qualifiedName)
  -        throws DOMException
  -    {
  -        int index = qualifiedName.indexOf(':');
  -        String prefix;
  -
  -        // DOM Level 3: namespace URI is never empty string.
  -        this.namespaceURI = (namespaceURI !=null &&
  -                             namespaceURI.length() == 0) ? null : namespaceURI;
  -
  -        if (index < 0) {
  -            prefix = null;
  -            localName = qualifiedName;
  -        } 
  -        else {
  -            prefix = qualifiedName.substring(0, index); 
  -            localName = qualifiedName.substring(index+1);
  -        
  -            if (ownerDocument.errorChecking) {
  -                if (this.namespaceURI == null
  -                        || (localName.length() == 0)
  -                        || (localName.indexOf(':') >= 0)) {
  -                    String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                }
  -                else if (prefix.equals("xml")) {
  -                    if (!namespaceURI.equals(xmlURI)) {
  -                        String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                    }
  -                } else if (index == 0) {
  -                    String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", 
null);
  -                    throw new DOMException(DOMException.NAMESPACE_ERR, msg);
  -                }
  -            }
  -        }
  -    }
  +     private void setName(String namespaceURI, String qname) {
  +             String prefix;
  +             // DOM Level 3: namespace URI is never empty string.
  +             this.namespaceURI = namespaceURI;
  +             if (namespaceURI != null) {
  +                     this.namespaceURI =
  +                             (namespaceURI.length() == 0) ? null : 
namespaceURI.intern();
  +             }
  +             int colon1 = qname.indexOf(':');
  +             int colon2 = qname.lastIndexOf(':');
  +             ownerDocument().checkNamespaceWF(qname, colon1, colon2);
  +             if (colon1 < 0) {
  +                     // there is no prefix
  +                     localName = qname;
  +                     ownerDocument().checkQName(null, localName);
  +                     if (qname.equals("xmlns")
  +                             && (namespaceURI == null
  +                                     || namespaceURI != NamespaceContext.XMLNS_URI)
  +                             || (namespaceURI == NamespaceContext.XMLNS_URI
  +                                     && !qname.equals("xmlns"))) {
  +                             String msg =
  +                                     DOMMessageFormatter.formatMessage(
  +                                             DOMMessageFormatter.DOM_DOMAIN,
  +                                             "NAMESPACE_ERR",
  +                                             null);
  +                             throw new DOMException(DOMException.NAMESPACE_ERR, 
msg);
  +                     }
  +             }
  +             else {
  +                     prefix = qname.substring(0, colon1);
  +                     localName = qname.substring(colon2 + 1);
  +                     ownerDocument().checkQName(prefix, localName);
  +                     ownerDocument().checkDOMNSErr(prefix, namespaceURI);
  +             }
  +     }
   
       // when local name is known
       protected ElementNSImpl(CoreDocumentImpl ownerDocument, 
  
  
  

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

Reply via email to