incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/util StringUtils.java
Date Mon, 23 Jun 2003 16:32:40 GMT
rana_b      2003/06/23 09:32:39

  Modified:    src/java/org/apache/ftpserver/util StringUtils.java
  Log:
  added new utility methods
  
  Revision  Changes    Path
  1.2       +83 -2     incubator-ftpserver/src/java/org/apache/ftpserver/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/util/StringUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringUtils.java	31 Mar 2003 06:50:36 -0000	1.1
  +++ StringUtils.java	23 Jun 2003 16:32:39 -0000	1.2
  @@ -56,7 +56,7 @@
    */
   package org.apache.ftpserver.util;
   
  -
  +import java.util.Map;
   
   /**
    * String utility methods.
  @@ -85,7 +85,88 @@
           return sb.toString();
       }
   
  +    /**
  +     * Replace string
  +     */ 
  +    public static String replaceString(String source, Object[] args) {
  +        int startIndex = 0;
  +        int openIndex = source.indexOf('{', startIndex);
  +        if (openIndex == -1) {
  +            return source;
  +        }
  +        
  +        int closeIndex = source.indexOf('}', startIndex);
  +        if( (closeIndex == -1) || (openIndex > closeIndex) ) {
  +            return source;
  +        }
  +        
  +        StringBuffer sb = new StringBuffer();
  +        sb.append(source.substring(startIndex, openIndex));
  +        while(true) {
  +            String intStr = source.substring(openIndex+1, closeIndex);
  +            int index = Integer.parseInt(intStr);
  +            sb.append(args[index]);
  +            
  +            startIndex = closeIndex + 1;
  +            openIndex = source.indexOf('{', startIndex);
  +            if (openIndex == -1) {
  +                sb.append(source.substring(startIndex));
  +                break;
  +            }
  +            
  +            closeIndex = source.indexOf('}', startIndex);
  +            if( (closeIndex == -1) || (openIndex > closeIndex) ) {
  +               sb.append(source.substring(startIndex));
  +               break;
  +            }
  +            sb.append(source.substring(startIndex, openIndex));
  +        }
  +        return sb.toString();
  +    }
  +    
   
  +    /**
  +     * Replace string
  +     */ 
  +    public static String replaceString(String source, Map args) {
  +        int startIndex = 0;
  +        int openIndex = source.indexOf('{', startIndex);
  +        if (openIndex == -1) {
  +            return source;
  +        }
  +        
  +        int closeIndex = source.indexOf('}', startIndex);
  +        if( (closeIndex == -1) || (openIndex > closeIndex) ) {
  +            return source;
  +        }
  +        
  +        StringBuffer sb = new StringBuffer();
  +        sb.append(source.substring(startIndex, openIndex));
  +        while(true) {
  +            String key = source.substring(openIndex+1, closeIndex);
  +            Object val = args.get(key);
  +            if(val != null) {
  +                sb.append(val);
  +            }
  +            
  +            startIndex = closeIndex + 1;
  +            openIndex = source.indexOf('{', startIndex);
  +            if (openIndex == -1) {
  +                sb.append(source.substring(startIndex));
  +                break;
  +            }
  +            
  +            closeIndex = source.indexOf('}', startIndex);
  +            if( (closeIndex == -1) || (openIndex > closeIndex) ) {
  +               sb.append(source.substring(startIndex));
  +               break;
  +            }
  +            sb.append(source.substring(startIndex, openIndex));
  +        }
  +        return sb.toString();
  +    }
  +    
  +    
       /**
        * This method is used to insert HTML block dynamically
        *
  
  
  

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


Mime
View raw message