You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/10/18 12:29:08 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util Util.java

morten      01/10/18 03:29:08

  Modified:    java/src/org/apache/xalan/xsltc/compiler CallTemplate.java
                        Template.java VariableBase.java WithParam.java
                        XSLTC.java
               java/src/org/apache/xalan/xsltc/compiler/util Util.java
  Log:
  Added/checked proper escaping of template/variable/parameter/attribute-set/etc.
  names. Occurances of the characters '.' and '-' are replaced by '$dot$' and
  '$dash$' respectively in method/variable names. The characters are both
  replaced by an underbar ('_') in the translet class name.
  PR:		2399
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.7       +2 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CallTemplate.java	2001/10/18 09:43:44	1.6
  +++ CallTemplate.java	2001/10/18 10:29:07	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: CallTemplate.java,v 1.6 2001/10/18 09:43:44 morten Exp $
  + * @(#)$Id: CallTemplate.java,v 1.7 2001/10/18 10:29:07 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -131,7 +131,7 @@
   
   	final String className = stylesheet.getClassName();
   	// Generate a valid Java method name
  -	String methodName = EscapeString.escape(_name.toString());
  +	String methodName = Util.escape(_name.toString());
   
   	il.append(classGen.loadTranslet());
   	il.append(methodGen.loadDOM());
  
  
  
  1.12      +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Template.java
  
  Index: Template.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Template.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Template.java	2001/10/18 09:43:44	1.11
  +++ Template.java	2001/10/18 10:29:07	1.12
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Template.java,v 1.11 2001/10/18 09:43:44 morten Exp $
  + * @(#)$Id: Template.java,v 1.12 2001/10/18 10:29:07 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -314,7 +314,7 @@
   
   	if (_compiled && isNamed()){
   
  -	    String methodName = EscapeString.escape(_name.toString());
  +	    String methodName = Util.escape(_name.toString());
   
   	    il.append(classGen.loadTranslet());
   	    il.append(methodGen.loadDOM());
  
  
  
  1.9       +2 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- VariableBase.java	2001/10/18 09:43:44	1.8
  +++ VariableBase.java	2001/10/18 10:29:07	1.9
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: VariableBase.java,v 1.8 2001/10/18 09:43:44 morten Exp $
  + * @(#)$Id: VariableBase.java,v 1.9 2001/10/18 10:29:07 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -207,7 +207,7 @@
       public void setName(QName name) {
   	_name = name;
   	_name.clearDefaultNamespace();
  -	_variable = EscapeString.escape(name.getLocalPart());
  +	_variable = Util.escape(name.getLocalPart());
       }
   
       /**
  
  
  
  1.8       +2 -2      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WithParam.java	2001/10/18 09:43:44	1.7
  +++ WithParam.java	2001/10/18 10:29:07	1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: WithParam.java,v 1.7 2001/10/18 09:43:44 morten Exp $
  + * @(#)$Id: WithParam.java,v 1.8 2001/10/18 10:29:07 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -159,7 +159,7 @@
   	final InstructionList il = methodGen.getInstructionList();
   
   	// Make name acceptable for use as field name in class
  -	String name = EscapeString.escape(_name.getLocalPart());
  +	String name = Util.escape(_name.getLocalPart());
   
   	// Load reference to the translet (method is in AbstractTranslet)
   	il.append(classGen.loadTranslet());
  
  
  
  1.26      +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
  
  Index: XSLTC.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XSLTC.java	2001/10/16 10:58:59	1.25
  +++ XSLTC.java	2001/10/18 10:29:07	1.26
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: XSLTC.java,v 1.25 2001/10/16 10:58:59 morten Exp $
  + * @(#)$Id: XSLTC.java,v 1.26 2001/10/18 10:29:07 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -452,7 +452,7 @@
       public void setClassName(String className) {
   	final String base  = Util.baseName(className);
   	final String noext = Util.noExtName(base); 
  -	final String name  = Util.toJavaName(noext);
  +	String name  = Util.toJavaName(noext);
   	if (_packageName == null)
   	    _className = name;
   	else
  
  
  
  1.2       +38 -7     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Util.java	2001/04/17 18:52:22	1.1
  +++ Util.java	2001/10/18 10:29:08	1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Util.java,v 1.1 2001/04/17 18:52:22 sboag Exp $
  + * @(#)$Id: Util.java,v 1.2 2001/10/18 10:29:08 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -136,12 +136,9 @@
       }
   
       public static void println(char ch) {
  -	/*
  -	  //	if (Parser.debug()) {
  -	  if (false) {
  -	  System.out.println(ch);
  -	  }
  -	*/
  +	if (false) {
  +	    System.out.println(ch);
  +	}
       }
   
       public static void TRACE1() {
  @@ -155,5 +152,39 @@
       public static void TRACE3() {
   	System.out.println("TRACE3");
       }
  +
  +    /**
  +     * Replace a certain character in a string with a new substring.
  +     */
  +    public static String replace(String base, char c, String str) {
  +	final int len = base.length() - 1;
  +	int pos;
  +	while ((pos = base.indexOf(c)) > -1) {
  +	    if (pos == 0) {
  +		final String after = base.substring(1);
  +		base = str + after;
  +	    }
  +	    else if (pos == len) {
  +		final String before = base.substring(0, pos);
  +		base = before + str;
  +	    }
  +	    else {
  +		final String before = base.substring(0, pos);
  +		final String after = base.substring(pos+1);
  +		base = before + str + after;
  +	    }
  +	}
  +	return base;
  +    }
  +
  +    /**
  +     * Replace occurances of '.' with '$dot$' and '-' with '$dash$'
  +     */
  +    public static String escape(String input) {
  +	input = replace(input, '.', "$dot$");
  +	input = replace(input, '-', "$dash$");
  +	return input;
  +    }
  +
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org