You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/11/12 16:12:58 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/texen/util PropertiesUtil.java StringUtil.java

jvanzyl     00/11/12 07:12:58

  Modified:    src/java/org/apache/velocity/texen/util StringUtil.java
  Added:       src/java/org/apache/velocity/texen/util PropertiesUtil.java
  Log:
  - little utilility for pulling in properties from a template. using this
    in torque so that a template can use db specific properties without
    having to resort to loading the db specific properties inside the data
    model classes of torque.
  
  Revision  Changes    Path
  1.4       +36 -0     jakarta-velocity/src/java/org/apache/velocity/texen/util/StringUtil.java
  
  Index: StringUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/texen/util/StringUtil.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringUtil.java	2000/11/06 04:50:39	1.3
  +++ StringUtil.java	2000/11/12 15:12:58	1.4
  @@ -134,4 +134,40 @@
           
           return true;
       }
  +
  +    /**
  +      * Replaces all instances of oldString with newString in line.
  +      * Taken from the Jive forum package.
  +      */
  +    public static final String sub(String line, String oldString,String newString)
  +    {
  +        int i = 0;
  +        if ((i = line.indexOf(oldString, i)) >= 0)
  +        {
  +            char [] line2 = line.toCharArray();
  +            char [] newString2 = newString.toCharArray();
  +            int oLength = oldString.length();
  +            StringBuffer buf = new StringBuffer(line2.length);
  +            buf.append(line2, 0, i).append(newString2);
  +            i += oLength;
  +            int j = i;
  +            while ((i = line.indexOf(oldString, i)) > 0)
  +            {
  +                buf.append(line2, j, i - j).append(newString2);
  +                i += oLength;
  +                j = i;
  +            }
  +            buf.append(line2, j, line2.length - j);
  +            return buf.toString();
  +        }
  +        return line;
  +    }
  +
  +    public String select(boolean state, String trueString, String falseString)
  +    {
  +        if (state)
  +            return trueString;
  +        else
  +            return falseString;
  +    }            
   }
  
  
  
  1.1                  jakarta-velocity/src/java/org/apache/velocity/texen/util/PropertiesUtil.java
  
  Index: PropertiesUtil.java
  ===================================================================
  package org.apache.velocity.texen.util;
  
  
  // JDK Classes
  import java.io.*;
  import java.util.*;
  
  /**
   * A property utility class for the texen text/code generator
   * Usually this class is only used from a Velocity context.
   *
   * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
   */
  public class PropertiesUtil extends BaseUtil
  {
      public Properties load(String propertiesFile)
      {
          Properties properties = new Properties();
          
          try
          {
              properties.load(new FileInputStream(propertiesFile));
              return properties;
          }
          catch (Exception e)
          {
              e.printStackTrace();
              return null;
          }
      }
  }