juergen     2002/07/31 04:30:38

  Modified:    
testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor
                        TProcessors.java
  Log:
  added the possibility to use variables, that contain variables in their value, which 
are substituted too, before usage (e.g.  
-Dxdav.globalVariableUserPath="/%globalVariableServerName%/administration/security/users/%host%/%user%")
  
  Revision  Changes    Path
  1.27      +61 -8     
jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java
  
  Index: TProcessors.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TProcessors.java  29 Jul 2002 11:26:29 -0000      1.26
  +++ TProcessors.java  31 Jul 2002 11:30:38 -0000      1.27
  @@ -721,8 +721,10 @@
       
       
       /**
  -     * This method is used to replace variables in a string
  -     * @param element the element to replacement should be applied
  +     * This method is used to replace variables in a string. If a variable value 
uses other variables
  +     * those variables are subsituted too.
  +     * @param element the element containing variable definitions
  +     * @param line the input line the replacement should be applied
        * @param defaultValue if element is null, return this default
        * @return String the value of the element, with all applied replacements, if 
element is null return defaultValue
        */
  @@ -733,8 +735,39 @@
           if (element.getAttributeValue("varUsage") != null && 
!element.getAttributeValue("varUsage").equals("")){
               
               if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
  -                line = replace(line, "%varUsage%", 
knownVariables.get(element.getAttributeValue("varUsage")));
  -                line = replace(line, "%"+element.getAttributeValue("varUsage")+"%", 
knownVariables.get(element.getAttributeValue("varUsage")));
  +                String varName = "varUsage";  // default
  +                line = replace(line, "%"+varName+"%", computeVarValue(element, 
element.getAttributeValue("varUsage")));
  +                varName = element.getAttributeValue("varUsage");  // real name
  +                line = replace(line, "%"+varName+"%", computeVarValue(element, 
varName));
  +            } else {
  +                StringTokenizer varNames = new 
StringTokenizer(element.getAttributeValue("varUsage"), ",");
  +                while (varNames.hasMoreElements()) {
  +                    String varName = (String)varNames.nextElement();
  +                    line = replace(line, "%"+varName+"%", computeVarValue(element, 
varName));
  +                }
  +            }
  +        }
  +        return line;
  +    }
  +    /**
  +     * This method is used to replace variables in a string. If a variable value 
uses other variables
  +     * those variables are NOT subsituted.
  +     * @param element the element containing variable definitions
  +     * @param line the input line the replacement should be applied
  +     * @param defaultValue if element is null, return this default
  +     * @return String the value of the element, with all applied replacements, if 
element is null return defaultValue
  +     */
  +    private  String doReplaceKnownVariable(Element element, String line, String 
defaultValue){
  +        
  +        if (element == null) return defaultValue;
  +        
  +        if (element.getAttributeValue("varUsage") != null && 
!element.getAttributeValue("varUsage").equals("")){
  +            
  +            if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
  +                String varName = "varUsage";  // default
  +                line = replace(line, "%"+varName+"%", 
knownVariables.get(element.getAttributeValue("varUsage")));
  +                varName = element.getAttributeValue("varUsage");  // real name
  +                line = replace(line, "%"+varName+"%", knownVariables.get(varName));
               } else {
                   StringTokenizer varNames = new 
StringTokenizer(element.getAttributeValue("varUsage"), ",");
                   while (varNames.hasMoreElements()) {
  @@ -745,6 +778,26 @@
           }
           return line;
       }
  +    
  +    
  +    
  +    /**
  +     * This method computes for a given variable name the value. If the value 
contains
  +     * additional variable references, these are resolved to their values
  +     * @param element the element containing variable definitions
  +     * @param varName the name of the variable
  +     * @return value of the variable
  +     */
  +    public String computeVarValue(Element element, String varName){
  +        String result = knownVariables.get(varName);
  +        if (result.indexOf("%") != -1 && result.indexOf("%", result.indexOf("%")+1) 
!= -1) {
  +            result = doReplaceKnownVariable(element, result, result);
  +        }
  +        return result;
  +    }
  +    
  +    
  +    
       
       /**
        * This method is used to replace variables in a string
  
  
  

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

Reply via email to