You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2004/02/24 03:57:28 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler CallTemplate.java VariableBase.java WithParam.java

zongaro     2004/02/23 18:57:28

  Modified:    java/src/org/apache/xalan/xsltc/compiler 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
  1.18      +13 -16    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CallTemplate.java	16 Feb 2004 22:24:29 -0000	1.17
  +++ CallTemplate.java	24 Feb 2004 02:57:28 -0000	1.18
  @@ -31,6 +31,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;
   
  @@ -70,7 +71,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);
       }
   		
  @@ -165,20 +176,6 @@
   	    il.append(classGen.loadTranslet());
   	    il.append(new INVOKEVIRTUAL(pop));
   	}
  -    }
  -    
  -    /**
  -     * Return the name of a Param or WithParam.
  -     */
  -    private String getParameterName(SyntaxTreeNode node) {
  -        if (node instanceof Param) {
  -            return Util.escape(((Param)node).getName().toString());
  -        }
  -        else if (node instanceof WithParam) {
  -            WithParam withParam = (WithParam)node;
  -            return Util.escape(withParam.getName().toString());
  -        }
  -        return null;
       }
       
       /**
  
  
  
  1.23      +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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- VariableBase.java	16 Feb 2004 22:25:10 -0000	1.22
  +++ VariableBase.java	24 Feb 2004 02:57:28 -0000	1.23
  @@ -34,6 +34,7 @@
   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;
   
   /**
    * @author Jacek Ambroziak
  @@ -45,7 +46,7 @@
   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
  @@ -114,7 +115,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());
           }
  @@ -200,11 +201,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;
       }
   
       /**
  @@ -212,7 +212,7 @@
        */
       public void setName(QName name) {
   	_name = name;
  -	_variable = Util.escape(name.getLocalPart());
  +	_escapedName = Util.escape(name.getStringRep());
       }
   
       /**
  @@ -228,10 +228,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.17      +29 -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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WithParam.java	16 Feb 2004 22:25:10 -0000	1.16
  +++ WithParam.java	24 Feb 2004 02:57:28 -0000	1.17
  @@ -30,6 +30,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;
   
   /**
    * @author Jacek Ambroziak
  @@ -45,6 +46,11 @@
       private QName _name;
       
       /**
  +     * The escaped qname of the with-param.
  +     */
  +    protected String _escapedName;
  +    
  +    /**
        * Parameter's default value.
        */
       private Expression _select;
  @@ -71,6 +77,13 @@
       }
       
       /**
  +     * Returns the escaped qname of the parameter
  +     */
  +    public String getEscapedName() {
  +	return _escapedName;
  +    }    
  +    
  +    /**
        * Return the name of this WithParam.
        */
       public QName getName() {
  @@ -78,6 +91,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) {
  @@ -91,7 +112,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");
  @@ -161,7 +187,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: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org