zongaro     2004/02/24 04:56:39

  Modified:    java/src/org/apache/xalan/xsltc/compiler Tag:
                        xslt20-compiled CallTemplate.java VariableBase.java
                        WithParam.java
  Log:
  Patch for Bugzilla bug reports 24988 and 25368 from Joanne Tong
  (joannet () ca ! ibm ! com) reviewed by myself.
  
  24988:
  Changes required to test whether an attribute value that is required to be
  a QName, NCName or whitespace-separated list of QNames actually meets that
  requirement.
  
  25368:
  Code was basing variable and parameter names on the local part of the name,
  rather than including the namespace URI in the name.  This resulted in
  collisions in the generated code between distinct variables that had the same
  local-name.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.14.2.1  +13 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java
  
  Index: CallTemplate.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CallTemplate.java,v
  retrieving revision 1.14
  retrieving revision 1.14.2.1
  diff -u -r1.14 -r1.14.2.1
  --- CallTemplate.java 8 Jul 2003 20:32:51 -0000       1.14
  +++ CallTemplate.java 24 Feb 2004 12:56:39 -0000      1.14.2.1
  @@ -76,6 +76,7 @@
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
   import org.apache.xalan.xsltc.compiler.util.Util;
  +import org.apache.xml.utils.XMLChar;
   
   import java.util.Vector;
   
  @@ -109,7 +110,17 @@
       }
   
       public void parseContents(Parser parser) {
  -     _name = parser.getQNameIgnoreDefaultNs(getAttribute("name"));
  +        final String name = getAttribute("name");
  +        if (name.length() > 0) {
  +            if (!XMLChar.isValidQName(name)) {
  +                ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, 
name, this);
  +                parser.reportError(Constants.ERROR, err);           
  +            }                
  +            _name = parser.getQNameIgnoreDefaultNs(name);
  +        }
  +        else {
  +            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");   
        
  +        }
        parseChildren(parser);
       }
                
  
  
  
  1.19.2.1  +14 -10    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java
  
  Index: VariableBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java,v
  retrieving revision 1.19
  retrieving revision 1.19.2.1
  diff -u -r1.19 -r1.19.2.1
  --- VariableBase.java 25 Jun 2003 17:08:31 -0000      1.19
  +++ VariableBase.java 24 Feb 2004 12:56:39 -0000      1.19.2.1
  @@ -81,11 +81,12 @@
   import org.apache.xalan.xsltc.compiler.util.NodeSetType;
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.Util;
  +import org.apache.xml.utils.XMLChar;
   
   class VariableBase extends TopLevelElement {
   
       protected QName       _name;            // The name of the variable.
  -    protected String      _variable;        // The real name of the variable.
  +    protected String      _escapedName;        // The escaped qname of the 
variable.
       protected Type        _type;            // The type of this variable.
       protected boolean     _isLocal;         // True if the variable is local.
       protected LocalVariableGen _local;      // Reference to JVM variable
  @@ -153,7 +154,7 @@
       public void mapRegister(MethodGenerator methodGen) {
           if (_local == null) {
               final InstructionList il = methodGen.getInstructionList();
  -         final String name = _name.getLocalPart(); // TODO: namespace ?
  +         final String name = getEscapedName(); // TODO: namespace ?
            final org.apache.bcel.generic.Type varType = _type.toJCType();
               _local = methodGen.addLocalVariable2(name, varType, il.getEnd());
           }
  @@ -226,11 +227,10 @@
       }
   
       /**
  -     * Returns the name of the variable or parameter as it occured in the
  -     * stylesheet.
  +     * Returns the escaped qname of the variable or parameter 
        */
  -    public String getVariable() {
  -     return _variable;
  +    public String getEscapedName() {
  +     return _escapedName;
       }
   
       /**
  @@ -238,7 +238,7 @@
        */
       public void setName(QName name) {
        _name = name;
  -     _variable = Util.escape(name.getLocalPart());
  +     _escapedName = Util.escape(name.getStringRep());
       }
   
       /**
  @@ -254,10 +254,14 @@
       public void parseContents(Parser parser) {
        // Get the 'name attribute
        String name = getAttribute("name");
  -     if (name == null) name = EMPTYSTRING;
   
  -     if (name.length() > 0)
  +        if (name.length() > 0) {
  +            if (!XMLChar.isValidQName(name)) {
  +                ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, 
name, this);
  +                parser.reportError(Constants.ERROR, err);           
  +            }   
            setName(parser.getQNameIgnoreDefaultNs(name));
  +        }
           else
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
   
  
  
  
  1.13.2.1  +30 -3     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java
  
  Index: WithParam.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/WithParam.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- WithParam.java    23 Jun 2003 18:23:15 -0000      1.13
  +++ WithParam.java    24 Feb 2004 12:56:39 -0000      1.13.2.1
  @@ -76,10 +76,17 @@
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
   import org.apache.xalan.xsltc.compiler.util.Util;
  +import org.apache.xml.utils.XMLChar;
   
   final class WithParam extends Instruction {
   
       private QName _name;
  +
  +    /**
  +     * The escaped qname of the with-param.
  +     */
  +    protected String _escapedName;
  +
       private Expression _select;
   
       // %OPT% This is set to true when the WithParam is used in a
  @@ -103,6 +110,13 @@
       }
       
       /**
  +     * Returns the escaped qname of the parameter
  +     */
  +    public String getEscapedName() {
  +     return _escapedName;
  +    }    
  +    
  +    /**
        * Return the name of this WithParam.
        */
       public QName getName() {
  @@ -110,6 +124,14 @@
       }
       
       /**
  +     * Set the name of the variable or paremeter. Escape all special chars.
  +     */
  +    public void setName(QName name) {
  +     _name = name;
  +     _escapedName = Util.escape(name.getStringRep());
  +    }    
  +    
  +    /**
        * Set the do parameter optimization flag
        */
       public void setDoParameterOptimization(boolean flag) {
  @@ -124,7 +146,12 @@
       public void parseContents(Parser parser) {
        final String name = getAttribute("name");
        if (name.length() > 0) {
  -         _name = parser.getQName(name);
  +            if (!XMLChar.isValidQName(name)) {
  +                ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name,
  +                                            this);
  +                parser.reportError(Constants.ERROR, err);
  +            }
  +         setName(parser.getQNameIgnoreDefaultNs(name));
        }
           else {
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name");
  @@ -194,7 +221,7 @@
        }
        
        // Make name acceptable for use as field name in class
  -     String name = Util.escape(_name.getLocalPart());
  +     String name = Util.escape(getEscapedName());
   
        // Load reference to the translet (method is in AbstractTranslet)
        il.append(classGen.loadTranslet());
  
  
  

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

Reply via email to