You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/01/20 02:07:24 UTC

cvs commit: xml-crimson/src/org/apache/crimson/tree AttributeSet.java XmlDocumentBuilder.java

edwingo     01/01/19 17:07:23

  Modified:    src/org/apache/crimson/parser Parser2.java
               src/org/apache/crimson/tree AttributeSet.java
                        XmlDocumentBuilder.java
  Added:       src/org/apache/crimson/parser AttributesEx.java
                        AttributesExImpl.java
  Removed:     src/org/apache/crimson/parser AttributeListEx.java
                        AttributeListImpl.java
  Log:
  Fixed handling of Attr.getSpecified() and ID attributes
  
  Revision  Changes    Path
  1.3       +18 -18    xml-crimson/src/org/apache/crimson/parser/Parser2.java
  
  Index: Parser2.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/parser/Parser2.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Parser2.java	2001/01/18 01:09:58	1.2
  +++ Parser2.java	2001/01/20 01:07:22	1.3
  @@ -1,5 +1,5 @@
   /*
  - * $Id: Parser2.java,v 1.2 2001/01/18 01:09:58 edwingo Exp $
  + * $Id: Parser2.java,v 1.3 2001/01/20 01:07:22 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -118,7 +118,7 @@
    * @author David Brownell
    * @author Rajiv Mordani
    * @author Edwin Goei
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class Parser2
   {
  @@ -126,7 +126,7 @@
       private InputEntity         in;
   
       // temporaries reused during parsing
  -    private AttributesImpl      attTmp;
  +    private AttributesExImpl    attTmp;
       private StringBuffer        strTmp;
       private char                nameTmp [];
       private NameCache           nameCache;
  @@ -370,7 +370,7 @@
           in = null;
   
           // alloc temporary data used in parsing
  -        attTmp = new AttributesImpl ();
  +        attTmp = new AttributesExImpl ();
           strTmp = new StringBuffer ();
           nameTmp = new char [20];
           nameCache = new NameCache ();
  @@ -1404,19 +1404,21 @@
                   error ("P-033", new Object [] { value });
   
               String type = (info == null) ? AttributeDecl.CDATA : info.type;
  +            String defaultValue = (info == null) ? null : info.defaultValue;
   
               if (namespaces) {
  -                processAttributeNS(attQName, type, value, false);
  +                processAttributeNS(attQName, type, value, defaultValue,
  +                                   false, false);
               } else {
                   // No namespaces case
  -                attTmp.addAttribute("", "", attQName, type, value);
  +                attTmp.addAttribute("", "", attQName, type, value,
  +                                    defaultValue, false);
               }
   
               haveAttributes = true;
           }
  -// XXX old code
  -//      if (element != null)
  -//          attTmp.setIdAttributeName (element.id);
  +        if (element != null)
  +            attTmp.setIdAttributeName (element.id);
   
           // if we had ATTLIST decls, handle required & defaulted attributes
           // before telling next layer about this element
  @@ -1512,7 +1514,8 @@
        * <code>nsAttTmp</code>.
        */
       private void processAttributeNS(String attQName, String type,
  -                                    String value, boolean isDefaulting)
  +                                    String value, String defaultValue,
  +                                    boolean isSpecified, boolean isDefaulting)
           throws SAXException
       {
           // assert(namespaces == true)
  @@ -1534,7 +1537,7 @@
               // We may need to add this attribute to appropriate lists
               if (prefixes) {
                   attTmp.addAttribute("", prefix, attQName.intern(),
  -                                    type, value);
  +                                    type, value, defaultValue, isSpecified);
               } else if (supportValidation && isValidating && !isDefaulting) {
                   // Add this namespace attribute to a different list that
                   // will be used to check for #REQUIRED attributes later.
  @@ -1549,7 +1552,7 @@
               // This isn't a namespace declaration.
               String attName[] = processName(attQName, true);
               attTmp.addAttribute(attName[0], attName[1], attName[2], type,
  -                                value);
  +                                value, defaultValue, isSpecified);
           }
       }
   
  @@ -1667,15 +1670,12 @@
                       error ("V-010", new Object [] { declAttName });
   
                   if (namespaces) {
  -                    processAttributeNS(declAttName, info.type,
  -                                       defaultValue, true);
  +                    processAttributeNS(declAttName, info.type, defaultValue,
  +                                       defaultValue, false, true);
                   } else {
                       attTmp.addAttribute("", "", declAttName, info.type,
  -                                        defaultValue);
  +                                        defaultValue, defaultValue, false);
                   }
  -// XXX old code
  -//              attributes.addAttribute (declAttName, info.type,
  -//                  info.defaultValue, info.defaultValue, false);
                   didDefault = true;
               }
           }
  
  
  
  1.1                  xml-crimson/src/org/apache/crimson/parser/AttributesEx.java
  
  Index: AttributesEx.java
  ===================================================================
  /*
   * $Id $
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Crimson" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Sun Microsystems, Inc., 
   * http://www.sun.com.  For more information on the Apache Software 
   * Foundation, please see <http://www.apache.org/>.
   */
  
  package org.apache.crimson.parser;
  
  import org.xml.sax.Attributes;
  
  
  /**
   * This interface extends the SAX Attributes interface to expose
   * information needed to support DOM Level 2 features used in document
   * editing, and detection of ID attributes which are declared for
   * an element.
   *
   * @author David Brownell
   * @version $Revision: 1.1 $
   */
  public interface AttributesEx extends Attributes
  {
      /**
       * Returns true if the attribute was specified in the document.
       * <em> This method only relates to document editing; there is no
       * difference in semantics between explicitly specifying values
       * of attributes in a DTD vs another part of the document. </em>
       *
       * @param i the index of the attribute in the list.
       */
      public boolean isSpecified (int i);
  
      /**
       * Returns the default value of the specified attribute, or null
       * if no default value is known.  Default values may be explicitly
       * specified in documents; in fact, for standalone documents, they
       * must be so specified.  If <em>isSpecified</em> is false, the
       * value returned by this method will be what <em>getValue</em>
       * returns.
       *
       * @param i the index of the attribute in the list.
       */
      public String getDefault (int i);
  
      /**
       * Returns the name of the ID attribute for the associated element,
       * if one was declared.  If such an ID value was provided, this
       * name can be inferred from methods in the base class; but if none
       * was provided, this will be the only way this name can be determined.
       */
      public String getIdAttributeName ();
  }
  
  
  
  1.1                  xml-crimson/src/org/apache/crimson/parser/AttributesExImpl.java
  
  Index: AttributesExImpl.java
  ===================================================================
  /*
   * $Id: AttributesExImpl.java,v 1.1 2001/01/20 01:07:22 edwingo Exp $
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Crimson" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Sun Microsystems, Inc., 
   * http://www.sun.com.  For more information on the Apache Software 
   * Foundation, please see <http://www.apache.org/>.
   */
  
  package org.apache.crimson.parser;
  
  import java.util.Vector;
  
  import org.xml.sax.helpers.AttributesImpl;
  
  
  /**
   * Implementation of the AttributesEx interface which provides additional
   * features to support editor-oriented DOM features: exposing attribute
   * defaulting.  Derived from old AttributeListImpl.java code.
   */
  final
  class AttributesExImpl extends AttributesImpl implements AttributesEx
  {
      // Boolean.TRUE indicates value was specified
      private Vector      specified = new Vector ();
  
      // non-null value defines default
      private Vector      defaults = new Vector ();
  
      // ID attribute name, as declared
      private String      idAttributeName;
  
      AttributesExImpl()
      {
          super();
      }
  
      /**
       * Clears the attribute list so it has no members
       */
      public void clear()
      {
          super.clear();
          specified.removeAllElements();
          defaults.removeAllElements();
          idAttributeName = null;
      }
  
      /**
       * Add an attribute to this list
       */
      public void addAttribute(String uri, String localName, String qName,
                               String type, String value, String defaultValue,
                               boolean isSpecified)
      {
          super.addAttribute(uri, localName, qName, type, value);
          defaults.addElement(defaultValue);
          specified.addElement(isSpecified ? Boolean.TRUE : null);
      }
  
      /**
       * Returns true if the value was specified by a parsed document
       * (by position; no by-name variant).
       */
      public boolean isSpecified(int i) {
          Object value = specified.elementAt(i);
          return value == Boolean.TRUE;
      }
  
      /**
       * Return the default value of an attribute in this list (by position).
       */
      public String getDefault(int i) {
          try {
              if (i < 0)
                  return null;
              return (String) defaults.elementAt(i);
          } catch (IndexOutOfBoundsException e) {
              return null;
          }
      }
  
      /**
       * Returns the name of the ID attribute.
       */
      public String getIdAttributeName() {
          return idAttributeName;
      }
  
      /**
       * Allows parser to set the name of the ID attribute.
       */
      void setIdAttributeName(String name) {
          idAttributeName = name;
      }
  }
  
  
  
  1.2       +7 -7      xml-crimson/src/org/apache/crimson/tree/AttributeSet.java
  
  Index: AttributeSet.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/AttributeSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeSet.java	2000/11/23 01:53:35	1.1
  +++ AttributeSet.java	2001/01/20 01:07:23	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: AttributeSet.java,v 1.1 2000/11/23 01:53:35 edwingo Exp $
  + * $Id: AttributeSet.java,v 1.2 2001/01/20 01:07:23 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -69,7 +69,7 @@
   import org.xml.sax.AttributeList;
   import org.xml.sax.Attributes;
   
  -import org.apache.crimson.parser.AttributeListEx;
  +import org.apache.crimson.parser.AttributesEx;
   
   
   /**
  @@ -80,7 +80,7 @@
    * document or was instead defaulted by attribute processing.
    *
    * @author David Brownell
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   final
   class AttributeSet implements NamedNodeMap, XmlWritable
  @@ -127,12 +127,12 @@
        * <b>DOM2:</b> Create DOM NamedNodeMap from SAX2 Attributes object
        */
       AttributeSet(Attributes source) throws DOMException {
  -        int                     len = source.getLength();
  -        AttributeListEx         ex = null;
  +        int len = source.getLength();
  +        AttributesEx ex = null;
   
           list = new Vector(len);
  -        if (source instanceof AttributeListEx) { // XXX fix this
  -            ex = (AttributeListEx) source;
  +        if (source instanceof AttributesEx) {
  +            ex = (AttributesEx) source;
           }
   
           for (int i = 0; i < len; i++) {
  
  
  
  1.2       +5 -6      xml-crimson/src/org/apache/crimson/tree/XmlDocumentBuilder.java
  
  Index: XmlDocumentBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/XmlDocumentBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlDocumentBuilder.java	2000/11/23 01:53:34	1.1
  +++ XmlDocumentBuilder.java	2001/01/20 01:07:23	1.2
  @@ -1,5 +1,5 @@
   /* 
  - * $Id: XmlDocumentBuilder.java,v 1.1 2000/11/23 01:53:34 edwingo Exp $
  + * $Id: XmlDocumentBuilder.java,v 1.2 2001/01/20 01:07:23 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -75,7 +75,6 @@
   import org.w3c.dom.DOMException;
   import org.w3c.dom.DOMImplementation;
   
  -import org.xml.sax.AttributeList;
   import org.xml.sax.ErrorHandler;
   import org.xml.sax.InputSource;
   import org.xml.sax.Locator;
  @@ -87,7 +86,7 @@
   import org.xml.sax.ext.LexicalHandler;
   import org.xml.sax.ext.DeclHandler;
   
  -import org.apache.crimson.parser.AttributeListEx;
  +import org.apache.crimson.parser.AttributesEx;
   
   
   /**
  @@ -128,7 +127,7 @@
    * than matching an XML structure that may not be optimized appropriately.
    *
    * @author David Brownell
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class XmlDocumentBuilder implements ContentHandler, LexicalHandler,
       DeclHandler, DTDHandler
  @@ -486,9 +485,9 @@
   	    throw new SAXParseException(getMessage("XDB-004",
                       new Object[] { ex.getMessage() }), locator, ex);
   	}
  -	if (attributes instanceof AttributeListEx) {
  +	if (attributes instanceof AttributesEx) {
   	    e.setIdAttributeName(
  -		((AttributeListEx)attributes).getIdAttributeName());
  +		((AttributesEx)attributes).getIdAttributeName());
           }
   	if (length != 0) {
   	    e.setAttributes(attSet);