You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/03/03 21:22:41 UTC

cvs commit: xml-xalan/src/org/apache/xalan/xslt ElemApplyTemplates.java ElemAttribute.java ElemFallback.java ElemIf.java ElemLiteralResult.java ElemTemplate.java ElemTemplateElement.java ElemValueOf.java ElemWhen.java Stylesheet.java StylesheetRoot.java

sboag       00/03/03 12:22:40

  Modified:    src/org/apache/xalan/xslt ElemApplyTemplates.java
                        ElemAttribute.java ElemFallback.java ElemIf.java
                        ElemLiteralResult.java ElemTemplate.java
                        ElemTemplateElement.java ElemValueOf.java
                        ElemWhen.java Stylesheet.java StylesheetRoot.java
  Log:
  Fixed validation of null namespace attributes in isAttrOK.  Removed isAttrOK version in elemTemplateElement because it wasn't an optimization worth having.
  
  Revision  Changes    Path
  1.10      +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemApplyTemplates.java
  
  Index: ElemApplyTemplates.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemApplyTemplates.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ElemApplyTemplates.java	2000/03/02 10:23:00	1.9
  +++ ElemApplyTemplates.java	2000/03/03 20:22:33	1.10
  @@ -101,7 +101,7 @@
           m_mode = new QName( atts.getValue(i), m_stylesheet.m_namespaces);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             if(null != processor)
               processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
  
  
  
  1.11      +2 -1      xml-xalan/src/org/apache/xalan/xslt/ElemAttribute.java
  
  Index: ElemAttribute.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemAttribute.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ElemAttribute.java	2000/03/02 10:23:00	1.10
  +++ ElemAttribute.java	2000/03/03 20:22:34	1.11
  @@ -61,6 +61,7 @@
   import org.apache.xalan.xpath.*;
   import org.apache.xalan.xpath.xml.QName;
   import org.apache.xalan.xslt.res.XSLTErrorResources;
  +import org.apache.xalan.xpath.xml.XSLMessages;
   
   /**
    * <meta name="usage" content="advanced"/>
  @@ -101,7 +102,7 @@
         else if(!(isAttrOK(aname, atts, i) || 
                   processSpaceAttr(aname, atts, i)))
         {
  -		  processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
  +        processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
         }
       }
       if(null == m_name_avt)
  
  
  
  1.5       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemFallback.java
  
  Index: ElemFallback.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemFallback.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElemFallback.java	2000/03/02 10:23:02	1.4
  +++ ElemFallback.java	2000/03/03 20:22:34	1.5
  @@ -93,7 +93,7 @@
           processSpaceAttr(atts, i);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
           }
  
  
  
  1.5       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemIf.java
  
  Index: ElemIf.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemIf.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElemIf.java	2000/03/02 10:23:02	1.4
  +++ ElemIf.java	2000/03/03 20:22:34	1.5
  @@ -98,7 +98,7 @@
           processSpaceAttr(atts, i);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
           }
  
  
  
  1.19      +35 -0     xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java
  
  Index: ElemLiteralResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ElemLiteralResult.java	2000/03/02 10:23:02	1.18
  +++ ElemLiteralResult.java	2000/03/03 20:22:34	1.19
  @@ -70,6 +70,7 @@
   import java.io.*;
   import java.util.*;
   
  +
   /**
    * <meta name="usage" content="advanced"/>
    * Implement a Literal Result Element.
  @@ -159,6 +160,40 @@
   
       }
     }
  +  
  +  /**
  +   * Override superclass's isAttrOK, to flag null namespace elements 
  +   * as OK, and XSLT namespace as OK.
  +   *
  +   * @param attrName Qualified name of attribute.
  +   * @param atts The attribute list where the element comes from (not used at
  +   *      this time).
  +   * @param which The index into the attribute list (not used at this time).
  +   * @return True if this attribute should not be flagged as an error.
  +   */
  +  boolean isAttrOK(String attrName, AttributeList atts, int which)
  +  {
  +    boolean isAttrOK = attrName.equals("xmlns") ||
  +                       attrName.startsWith("xmlns:");
  +    if(!isAttrOK)
  +    {
  +      int indexOfNSSep = attrName.indexOf(':');
  +      if(indexOfNSSep >= 0)
  +      {
  +        String prefix = attrName.substring(0, indexOfNSSep);
  +        String ns = m_stylesheet.getNamespaceForPrefixFromStack(prefix);
  +        isAttrOK = (!ns.equals(XSLTEngineImpl.m_XSLNameSpaceURL));
  +      }
  +      else
  +      {
  +        isAttrOK = true; // null namespace, flag it as normally OK.
  +      }
  +    }
  +
  +    // TODO: Well, process it...
  +    return isAttrOK;
  +  }
  +
           
     /**
      * Execute a Literal Result Element.
  
  
  
  1.8       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemTemplate.java
  
  Index: ElemTemplate.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemTemplate.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElemTemplate.java	2000/03/02 10:23:03	1.7
  +++ ElemTemplate.java	2000/03/03 20:22:34	1.8
  @@ -111,7 +111,7 @@
           processSpaceAttr(atts, i);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             if(null != processor)
               processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
  
  
  
  1.27      +1 -34     xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java
  
  Index: ElemTemplateElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ElemTemplateElement.java	2000/03/02 20:39:18	1.26
  +++ ElemTemplateElement.java	2000/03/03 20:22:35	1.27
  @@ -358,39 +358,6 @@
     }
   
     /** 
  -   * See if this is a xmlns attribute, and, if so, process it.
  -   * 
  -   * @param attrName Qualified name of attribute.
  -   * @param atts The attribute list where the element comes from (not used at 
  -   *      this time).
  -   * @param which The index into the attribute list (not used at this time).
  -   * @return True if this is a namespace name.
  -   */
  -  boolean isAttrOK(int tok, String attrName, AttributeList atts, int which)
  -    throws SAXException
  -  {
  -    boolean isAttrOK = (Constants.TATTRNAME_XMLNSDEF == tok) 
  -                      || attrName.startsWith(Constants.ATTRNAME_XMLNS);
  -    
  -    if(!isAttrOK)
  -    {
  -      int indexOfNSSep = attrName.indexOf(':');
  -      if(indexOfNSSep >= 0)
  -      {
  -        String prefix = attrName.substring(0, indexOfNSSep);
  -        String ns = m_stylesheet.getNamespaceForPrefixFromStack(prefix);
  -        isAttrOK = (!ns.equals(XSLTEngineImpl.m_XSLNameSpaceURL));
  -      }
  -      else
  -      {
  -        isAttrOK = true; // default namespace, flag it as OK
  -      }
  -    }
  -    
  -    return isAttrOK;
  -  }
  -
  -  /** 
      * See if this is a xmlns attribute or in a non-XSLT.
      * 
      * @param attrName Qualified name of attribute.
  @@ -399,7 +366,7 @@
      * @param which The index into the attribute list (not used at this time).
      * @return True if this attribute should not be flagged as an error.
      */
  -  final boolean isAttrOK(String attrName, AttributeList atts, int which)
  +  boolean isAttrOK(String attrName, AttributeList atts, int which)
       throws SAXException
     {
       return m_stylesheet.isAttrOK(attrName, atts, which);
  
  
  
  1.7       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemValueOf.java
  
  Index: ElemValueOf.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemValueOf.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ElemValueOf.java	2000/03/02 10:23:04	1.6
  +++ ElemValueOf.java	2000/03/03 20:22:35	1.7
  @@ -115,7 +115,7 @@
           processSpaceAttr(atts, i);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             if(null != processor)
               processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
  
  
  
  1.5       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemWhen.java
  
  Index: ElemWhen.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemWhen.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElemWhen.java	2000/03/02 10:23:04	1.4
  +++ ElemWhen.java	2000/03/03 20:22:35	1.5
  @@ -96,7 +96,7 @@
           processSpaceAttr(atts, i);
           break;
         default:
  -        if(!isAttrOK(tok, aname, atts, i))
  +        if(!isAttrOK(aname, atts, i))
           {
             processor.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}); //name+" has an illegal attribute: "+aname);
           }
  
  
  
  1.33      +6 -5      xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Stylesheet.java	2000/03/02 10:23:07	1.32
  +++ Stylesheet.java	2000/03/03 20:22:35	1.33
  @@ -721,9 +721,9 @@
         {
           useAttr = createXPath(atts.getValue(i), nsContext);
         }
  -      else
  -      {
  -        // TODO: Error
  +      else if(!isAttrOK(aname, atts, i))
  +      { 
  +        error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {"xsl:key", aname}); //name+" has an illegal attribute: "+aname);
         }
       }
       if(null == nameAttr)
  @@ -777,7 +777,8 @@
     }
   
     /**
  -   * See if this is a xmlns attribute or in a non-XSLT namespace.
  +   * Assuming legal attributes have been processed, check if the 
  +   * given attribute is legal on an xslt element.
      *
      * @param attrName Qualified name of attribute.
      * @param atts The attribute list where the element comes from (not used at
  @@ -800,7 +801,7 @@
         }
         else
         {
  -        isAttrOK = true; // default namespace, flag it as OK
  +        isAttrOK = false; // null namespace, flag it as normally not OK.
         }
       }
   
  
  
  
  1.32      +1 -22     xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- StylesheetRoot.java	2000/03/02 10:23:07	1.31
  +++ StylesheetRoot.java	2000/03/03 20:22:36	1.32
  @@ -820,28 +820,7 @@
           // If the attribute is test, or foo:test and foo is not a
           // known namespace prefix, the attribute is invalid.
           // if foo is a known prefix, then the attribute is valid.
  -        boolean attrOK = true;
  -        try{
  -          if(isAttrOK(aname, atts, i))
  -          {
  -            // If a namespace other than xsl was specified, make sure it is defined.
  -            int indexOfNSSep = aname.indexOf(':');
  -            if(indexOfNSSep >= 0)
  -            {
  -              String prefix = aname.substring(0, indexOfNSSep);
  -              String ns = getNamespaceForPrefixFromStack(prefix);
  -              attrOK = (!ns.equals(XSLTEngineImpl.m_XSLNameSpaceURL));
  -            }
  -            else
  -              attrOK = false;
  -          }
  -        }
  -        catch(Exception e)
  -        {
  -          // Namespace not defined
  -          attrOK = false;
  -        }
  -        if (!attrOK)
  +        if (!isAttrOK(aname, atts, i))
             throw new SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE, new Object[] {name, aname}));
         }
       }