mstover1    2005/02/09 13:11:55

  Modified:    src/jorphan/org/apache/jorphan/collections HashTree.java
               bin      jmeter.properties
               src/jorphan/org/apache/jorphan/util Converter.java
  Added:       test/src/org/apache/jorphan/collections
                        TestConfigurationTree.java
               src/jorphan/org/apache/jorphan/collections
                        ConfigurationTree.java
               bin/testfiles test_config.xml
  Log:
  A new configuration Tree object build using the HashTree classes.  Provides a 
simple, heirarchical config file format for easier-on-the-eyes system config 
files (replacing XML).
  
  Revision  Changes    Path
  1.1                  
jakarta-jmeter/test/src/org/apache/jorphan/collections/TestConfigurationTree.java
  
  Index: TestConfigurationTree.java
  ===================================================================
  /*
   * Created on Feb 8, 2005
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Style - Code Templates
   */
  package org.apache.jorphan.collections;
  
  import java.io.FileReader;
  
  import org.apache.jmeter.junit.JMeterTestCase;
  import org.apache.jorphan.io.TextFile;
  
  /**
   * @author mike
   * 
   * TODO To change the template for this generated type comment go to Window -
   * Preferences - Java - Code Style - Code Templates
   */
  public class TestConfigurationTree extends JMeterTestCase {
      ConfigurationTree config;
  
      /**
       * @param name
       */
      public TestConfigurationTree(String name) {
          super(name);
      }
  
      public void setUp() throws Exception {
          config = new ConfigurationTree("jmeterConfig");
          config.add("param1/value1");
          config.add("param2/value2");
          config.add("param3/value3");
          config.add("group1/param6/value6");
          config.add("group1/param7/value7");
          config.add("group1/param8/value8");
          config.add("param4/value4");
          config.add("group2/param9/value9");
          config.add("group2/param10/value10");
          config.add("school/announcement",
                  "This is a special announcement.\nToday is Thursday.");
          config.add("school/announcement/date", "Thursday");
          config.setProperty("school/announcement/title", "Way\n\tto\n\t\tgo");
          config.add("school/subjects/", new String[] { "art", "science", 
"math",
                  "english" });
          config.setValue("group1", "EON Developers");
      }
  
      public void testToString() throws Exception {
          assertEquals("EON Developers", config.getValue("group1"));
          config.setProperty("website/url", "http://mydomain.com/homepage.jsp";);
          String props = config.toString();
          TextFile tf = new TextFile(
                  findTestFile("testfiles/configurationTest.xml"));
          tf.setText(config.toString());
          ConfigurationTree newTree = ConfigurationTree.fromXML(new FileReader(
                  findTestFile("testfiles/configurationTest.xml")));
          assertEquals("EON Developers", newTree.getValue("group1"));
          assertEquals(props, newTree.toString());
          assertEquals("math", config.getPropertyNames("school/subjects")[2]);
          assertEquals("math", newTree.getPropertyNames("school/subjects")[2]);
          assertEquals("http://mydomain.com/homepage.jsp";, config
                  .remove("website/url"));
      }
  
      public void testManipulation1() throws Exception {
          config.put("db/driver", "oracle.jdbc.driver.OracleDriver");
          assertEquals("oracle.jdbc.driver.OracleDriver", config
                  .getProperty("db/driver"));
          config.add("db/url/my db's url");
          assertEquals("my db's url", config.getProperty("db/url"));
          config.setProperty("website/url", "http://mydomain.com/homepage.jsp";);
          assertEquals("http://mydomain.com/homepage.jsp";, config
                  .getProperty("website/url"));
          config.replace("db/driver", "resin_db/resin_driver");
          assertEquals("oracle.jdbc.driver.OracleDriver", config
                  .getProperty("resin_db/resin_driver"));
          assertEquals("my db's url", config.getProperty("resin_db/url"));
          config.remove("resin_db/resin_driver");
          assertNull(config.getProperty("resin_db/resin_driver"));
      }
  
      public void testBigLoad() throws Exception {
          ConfigurationTree tree = new ConfigurationTree(new FileReader(
                  "testfiles/test_config.xml"));
          assertEquals(
                  "proxy.apache.org",
                  
tree.getValue("services/org.apache.service.DocumentService/proxy"));
          assertEquals(
                  "Manager Notification",
                  tree.getPropertyNames(
                          
"services/org.apache.service.PreferenceService/preferenceSql")[6]);
          assertEquals("JMeter", tree.getValue());
          assertEquals(
                  "getBuddyList.sql",
                  tree.getProperty(
                          
"services/org.apache.service.PreferenceService/preferenceSql/Buddy List/sql"));
          assertEquals(
                  "org.apache.service.dbObjects",
                  tree.getPropertyNames(
                          
"services/org.apache.service.sql.ObjectMappingService/packages")[0]);
          assertEquals(
                  "The system could not find the resource you requested.  
Please check your request and try again.\n"
                          + "If the problem persists, report it to the system 
administrators.",
                  tree.getProperty(
                          
"services/org.apache.service.webaction.error.Redirector/exceptions/NoSuchObjectException/msg"));
      }
  }
  
  
  
  1.20      +3 -2      
jakarta-jmeter/src/jorphan/org/apache/jorphan/collections/HashTree.java
  
  Index: HashTree.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/jorphan/org/apache/jorphan/collections/HashTree.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- HashTree.java     4 Feb 2005 21:55:21 -0000       1.19
  +++ HashTree.java     9 Feb 2005 21:11:55 -0000       1.20
  @@ -859,6 +859,7 @@
           Iterator iter = treePath.iterator();
           while (iter.hasNext())
           {
  +            if(tree == null) return null;
               Object temp = iter.next();
               tree = tree.getTree(temp);
           }
  
  
  
  1.1                  
jakarta-jmeter/src/jorphan/org/apache/jorphan/collections/ConfigurationTree.java
  
  Index: ConfigurationTree.java
  ===================================================================
  /*
   * Created on Feb 8, 2005
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Style - Code Templates
   */
  package org.apache.jorphan.collections;
  
  import java.io.IOException;
  import java.io.Reader;
  import java.io.Serializable;
  import java.io.StringWriter;
  import java.io.Writer;
  import java.util.Collection;
  import java.util.Map;
  
  /**
   * @author mike
   * 
   * TODO To change the template for this generated type comment go to Window -
   * Preferences - Java - Code Style - Code Templates
   */
  public class ConfigurationTree implements Serializable, Cloneable {
      private static final long serialVersionUID = 1;
  
      private static final String VALUE = "!!VALUE_][!!";
      private static final String BLOCK = "[[!";
      private static final String END_BLOCK = "!]]";
  
      ListedHashTree propTree;
  
      public ConfigurationTree() {
          propTree = new ListedHashTree();
      }
      
      public ConfigurationTree(Reader r) throws IOException
      {
          propTree = fromXML(r).propTree;
      }
  
      public ConfigurationTree(String value) {
          propTree = new ListedHashTree();
          setValue(value);
      }
  
      public ConfigurationTree(ListedHashTree data) {
          propTree = data;
      }
  
      public ConfigurationTree(ListedHashTree data, String value) {
          propTree = data;
          setValue(value);
      }
  
      /**
       * @param keys
       */
      public void add(Collection keys) {
          propTree.add(keys);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void add(Collection treePath, Collection values) {
          propTree.add(treePath, values);
      }
  
      /**
       * @param treePath
       * @param value
       * @return
       */
      public ConfigurationTree add(Collection treePath, String value) {
          return makeSubtree((ListedHashTree) propTree.add(treePath,
                  value));
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void add(Collection treePath, String[] values) {
          propTree.add(treePath, values);
      }
  
      /**
       * @param newTree
       */
      public void add(ConfigurationTree newTree) {
          propTree.add(newTree.propTree);
      }
  
      /**
       * @param key
       * @return
       */
      public ConfigurationTree add(String key) {
          String[] keys = getPath(key);
          ListedHashTree tree = propTree;
          for (int i = 0; i < keys.length; i++) {
              tree = (ListedHashTree) tree.add(keys[i]);
          }
          return makeSubtree(tree);
      }
  
      /**
       * @param key
       * @param values
       */
      public void add(String key, Collection values) {
          propTree.add(getPath(key), values);
      }
  
      /**
       * @param key
       * @param subTree
       */
      public void add(String key, ConfigurationTree subTree) {
          propTree.getTree(getPath(key)).add(subTree.propTree);
      }
  
      /**
       * @param key
       * @param value
       * @return
       */
      public ConfigurationTree add(String key, String value) {
          return makeSubtree((ListedHashTree) propTree.add(
                  getPath(key), value));
      }
  
      /**
       * @param key
       * @param values
       */
      public void add(String key, String[] values) {
          propTree.add(getPath(key), values);
      }
  
      /**
       * @param keys
       */
      public void add(String[] keys) {
          propTree.add(keys);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void add(String[] treePath, Collection values) {
          propTree.add(treePath, values);
      }
  
      /**
       * @param treePath
       * @param value
       * @return
       */
      public ConfigurationTree add(String[] treePath, String value) {
          return makeSubtree((ListedHashTree) propTree.add(treePath,
                  value));
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void add(String[] treePath, String[] values) {
          propTree.add(treePath, values);
      }
  
      /**
       * @param treePath
       * @return
       */
      protected ConfigurationTree addTreePath(Collection treePath) {
          return makeSubtree((ListedHashTree) propTree
                  .addTreePath(treePath));
      }
  
      /**
       * 
       */
      public void clear() {
          propTree.clear();
      }
  
      /**
       * @param o
       * @return
       */
      public boolean containsKey(String o) {
          return propTree.getTree(getPath(o)) != null;
      }
  
      /**
       * @param value
       * @return
       */
      public boolean containsValue(String value) {
          return propTree.getTree(getPath(value)) != null;
      }
  
      protected String[] getPath(String key) {
          if (key != null) {
              String[] keys = key.split("/");
              return keys;
          }
          return new String[0];
      }
  
      /**
       * @param key
       * @return
       */
      public String getProperty(String key) {
          HashTree subTree = propTree.getTree(getPath(key));
          if (subTree != null) {
              if (subTree.list() == null || subTree.list().size() == 0) {
                  return null;
              } else if (subTree.list().size() == 1) {
                  return (String) subTree.getArray()[0];
              } else {
                  return null;
              }
          } else {
              return null;
          }
      }
  
      /**
       * @return
       */
      public String[] getPropertyNames() {
          return convertArray(propTree.getArray());
      }
  
      /**
       * @param vals
       * @return
       */
      private String[] convertArray(Object[] vals) {
          if (vals != null) {
              String[] props = new String[vals.length];
              for (int i = 0; i < vals.length; i++)
                  props[i] = (String) vals[i];
              return props;
          }
          return null;
      }
  
      /**
       * @param treePath
       * @return
       */
      public String[] getPropertyNames(Collection treePath) {
          return convertArray(propTree.getArray(treePath));
      }
  
      /**
       * @param key
       * @return
       */
      public String[] getPropertyNames(String key) {
          return convertArray(propTree.getArray(getPath(key)));
      }
  
      /**
       * @param treePath
       * @return
       */
      public String[] getPropertyNames(String[] treePath) {
          return convertArray(propTree.getArray(treePath));
      }
  
      /**
       * @param treePath
       * @return
       */
      public ConfigurationTree getTree(Collection treePath) {
          ListedHashTree subTree = (ListedHashTree) propTree.getTree(treePath);
          return makeSubtree(subTree);
      }
  
      /**
       * @param key
       * @return
       */
      public ConfigurationTree getTree(String key) {
          ListedHashTree subTree = (ListedHashTree) 
propTree.getTree(getPath(key));
          return makeSubtree(subTree);
      }
  
      /**
       * @param treePath
       * @return
       */
      public ConfigurationTree getTree(String[] treePath) {
          ListedHashTree subTree = (ListedHashTree) propTree.getTree(treePath);
          return makeSubtree(subTree);
      }
  
      /**
       * @param subTree
       * @return
       */
      private ConfigurationTree makeSubtree(ListedHashTree subTree) {
          if(subTree != null)
              return new ConfigurationTree(subTree);
          else
              return null;
      }
  
      /**
       * @param treePath
       * @return
       */
      protected ConfigurationTree getTreePath(Collection treePath) {
          ListedHashTree subTree = (ListedHashTree) propTree.getTree(treePath);
          return makeSubtree(subTree);
      }
  
      /**
       * @return
       */
      public boolean isEmpty() {
          return propTree.isEmpty();
      }
  
      /**
       * @return
       */
      public Collection listPropertyNames() {
          return propTree.list();
      }
  
      /**
       * @param treePath
       * @return
       */
      public Collection listPropertyNames(Collection treePath) {
          return propTree.list(treePath);
      }
  
      /**
       * @param key
       * @return
       */
      public Collection listPropertyNames(String key) {
          return propTree.list(getPath(key));
      }
  
      /**
       * @param treePath
       * @return
       */
      public Collection listPropertyNames(String[] treePath) {
          return propTree.list(treePath);
      }
  
      /**
       * @param key
       * @param value
       * @return
       */
      public String put(String key, String value) {
          propTree.add(getPath(key), value);
          return value;
      }
  
      /**
       * @param map
       */
      public void putAll(Map map) {
          propTree.putAll(map);
      }
  
      /**
       * @param key
       * @return
       */
      public String remove(String key) {
          String[] keys = key.split("/");
          String prop = null;
          HashTree tree = propTree;
          for (int i = 0; i < keys.length && tree != null; i++) {
              if ((i + 1) == keys.length) {
                  tree = (HashTree) tree.remove(keys[i]);
                  if (tree.list() != null && tree.list().size() == 1) {
                      prop = (String) tree.getArray()[0];
                  }
              } else {
                  tree = tree.getTree(keys[i]);
              }
          }
          return prop;
      }
  
      /**
       * @param currentKey
       * @param newKey
       */
      public void replace(String currentKey, String newKey) {
          String[] currentKeys = getPath(currentKey);
          String[] newKeys = getPath(newKey);
          ListedHashTree tree = propTree;
          if (currentKeys.length == newKeys.length) {
              for (int i = 0; i < currentKeys.length; i++) {
                  tree.replace(currentKeys[i], newKeys[i]);
                  tree = (ListedHashTree) tree.getTree(newKeys[i]);
              }
          }
      }
  
      /**
       * @param key
       * @return
       */
      public ConfigurationTree search(String key) {
          return makeSubtree((ListedHashTree) propTree.search(key));
      }
  
      /**
       * @param values
       */
      public void setProperty(Collection values) {
          propTree.set(values);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void setProperty(Collection treePath, Collection values) {
          propTree.set(treePath, values);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void setProperty(Collection treePath, String[] values) {
          propTree.set(treePath, values);
      }
  
      /**
       * @param key
       * @param values
       */
      public void setProperty(String key, Collection values) {
          propTree.set(getPath(key), values);
      }
  
      /**
       * @param key
       * @param t
       */
      public void setProperty(String key, ConfigurationTree t) {
          String[] keys = getPath(key);
          ListedHashTree tree = (ListedHashTree) propTree.getTree(keys);
          if (tree != null) {
              tree.clear();
              tree.add(t.propTree);
          } else {
              propTree.add(keys);
              propTree.getTree(keys).add(t.propTree);
          }
      }
  
      /**
       * @param key
       * @param value
       */
      public void setProperty(String key, String value) {
          ListedHashTree tree = (ListedHashTree) propTree.getTree(getPath(key));
          if (tree != null) {
              tree.clear();
              tree.add(value);
          } else {
              propTree.add(getPath(key), value);
          }
      }
  
      /**
       * @param key
       * @param values
       */
      public void setProperty(String key, String[] values) {
          propTree.set(getPath(key), values);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void setProperty(String[] treePath, Collection values) {
          propTree.set(treePath, values);
      }
  
      /**
       * @param treePath
       * @param values
       */
      public void setProperty(String[] treePath, String[] values) {
          propTree.set(treePath, values);
      }
  
      /**
       * @return
       */
      public int size() {
          return propTree.size();
      }
  
      /**
       * @param visitor
       */
      public void traverse(HashTreeTraverser visitor) {
          propTree.traverse(visitor);
      }
  
      /*
       * (non-Javadoc)
       * 
       * @see java.lang.Object#clone()
       */
      protected Object clone() throws CloneNotSupportedException {
          ConfigurationTree config = new ConfigurationTree();
          config.propTree = (ListedHashTree) propTree.clone();
          return config;
      }
  
      protected void getSpaces(int level, Writer buf) throws IOException {
          for (int i = 0; i < level; i++)
              buf.write("    ");
      }
  
      public String toString() {
          StringWriter buf = new StringWriter();
          try {
              toXML(buf);
          } catch (IOException e) {
              // this can't happen
          }
          return buf.toString();
      }
  
      public static ConfigurationTree fromXML(Reader buf) throws IOException {
          String[] line = readLine(buf,null);
          ConfigurationTree tree = null;
          int nameIndex = line[0].indexOf("{");
          if (nameIndex > 0) {
              tree = new ConfigurationTree(line[0].substring(0, 
nameIndex).trim());
          } else {
              tree = new ConfigurationTree();
          }
          fromXML(buf, tree,line);
          return tree;
      }
  
      /**
       * @param buf
       * @param tree
       * @throws IOException
       */
      protected static boolean fromXML(Reader buf, ConfigurationTree 
tree,String[] line)
              throws IOException {
          boolean done = false;
          try {
              while (!done && !(line = readLine(buf,line)).equals("}")) {
                  int equals = line[0].indexOf("=");
                  if (line[0].endsWith("{")) {
                      line[0] = line[0].substring(0, line[0].length() - 
1).trim();
                      equals = line[0].indexOf("=");
                      if (equals > -1) {
                          ConfigurationTree newTree = 
tree.add(line[0].substring(0,
                                  equals));
                          newTree.setValue(line[0].substring(equals + 1));
                          done = fromXML(buf, newTree,line);
                      } else {
                          done = fromXML(buf, tree.add(line[0]),line);
                      }
                  } else if (equals > -1) {
                      String key = line[0].substring(0, equals);
                      if ((equals + 1) < line[0].length())
                          tree.add(key, line[0].substring(equals + 1));
                      else
                          tree.add(key);
                  } else if (line[0].equals("}")) {
                      return false;
                  } else if(line[0].length() > 0)
                  {
                      tree.add(line[0]);
                  }
              }
          } catch (IOException e) {
              if (e.getMessage().equals("End of File")) {
                  return true;
              } else
                  throw e;
          }
          return false;
      }
  
      /**
       * @param buf
       * @throws IOException
       */
      protected static String[] readLine(Reader buf,String[] extra) throws 
IOException {
          if(extra == null)
          {
              extra = new String[2];
          }
          if(extra[1] != null && extra[1].length() > 0)
          {
              extra[0] = extra[1];
              extra[1] = null;
              return extra;
          }
          StringBuffer line = new StringBuffer();
          int c = buf.read();
          while ((c != -1) && ((char) c != '\n') && ((char) c != '\r') && 
                  ((char)c != '}') && ((char)c != '{')) {
              line.append((char) c);
              c = buf.read();
          }
          if (c == -1)
              throw new IOException("End of File");
          if(((char)c == '}'))
              extra[1] = String.valueOf((char)c);
          else if(((char)c) == '{')
          {
              line.append('{');
          }
          extra[0] = line.toString().trim();
          if(extra[0].endsWith(BLOCK))
          {
              extra[0] = extra[0].substring(0,extra[0].length()- 
BLOCK.length()) + 
                      readBlock(buf);
          }
          return extra;
      }
      
      protected static String readBlock(Reader buf) throws IOException
      {
          StringBuffer line = new StringBuffer();
          int c = buf.read();
          line.append((char)c);
          while (!line.toString().endsWith(END_BLOCK)) {
              c = buf.read();
              line.append((char) c);
          }
          return line.toString().substring(0,line.length() - 
END_BLOCK.length()).trim();
      }
  
      public void toXML(Writer buf) throws IOException {
          if (getValue() != null) {
              buf.write(getValue());
              buf.write(" {\n");
          } else
              buf.write("{\n");
          int level = 1;
          toXML(this, level, buf);
          buf.write("}");
      }
  
      protected boolean isLeaf(String key) {
          ConfigurationTree tree = getTree(key);
          String[] vals = tree.getPropertyNames();
          if (vals == null
                  || vals.length == 0
                  || (vals.length == 1 && (tree.listPropertyNames(vals[0]) == 
null || tree
                          .listPropertyNames(vals[0]).size() == 0))) {
              return true;
          }
          return false;
      }
  
      protected void toXML(ConfigurationTree tree, int level, Writer buf)
              throws IOException {
          String[] entries = tree.getPropertyNames();
          for (int i = 0; i < entries.length; i++) {
              if (!VALUE.equals(entries[i])) {
                  if (tree.listPropertyNames(entries[i]) == null
                          || tree.listPropertyNames(entries[i]).size() == 0) {
                      getSpaces(level, buf);
                      writeLeafValue(buf,entries[i],level);
                      buf.write("\n");
                  } else if (tree.isLeaf(entries[i])) {
                      getSpaces(level, buf);
                      buf.write(entries[i]);
                      buf.write("=");
                      
writeLeafValue(buf,tree.getPropertyNames(entries[i])[0],level);
                      buf.write("\n");
                  } else {
                      getSpaces(level, buf);
                      buf.write(entries[i]);
                      if (tree.getTree(entries[i]).getValue() != null) {
                          buf.write("=");
                          buf.write(tree.getTree(entries[i]).getValue());
                      }
                      buf.write(" {\n");
                      toXML(tree.getTree(entries[i]), (level + 1), buf);
                      getSpaces(level, buf);
                      buf.write("}\n");
                  }
              }
          }
      }
      
      protected void writeLeafValue(Writer buf,String entry,int level) throws 
IOException
      {
          if(entry.indexOf('\n') > -1 || entry.indexOf('\r') > -1)
          {
              buf.write(BLOCK);
              buf.write("\n");
              buf.write(entry.trim());
              buf.write("\n");
              getSpaces(level,buf);
              buf.write(END_BLOCK);
          }
          else
          {
              buf.write(entry);
          }
      }
  
      /**
       * @return Returns the value.
       */
      public String getValue() {
          return getProperty(VALUE);
      }
      
      public String getValue(String name)
      {
          ConfigurationTree tree = getTree(getPath(name));
          if(tree != null)
          {
              return tree.getValue();
          }
          return null;
      }
  
      /**
       * @param value
       *            The value to set.
       */
      public void setValue(String value) {
          setProperty(VALUE, value);
      }
      
      public void setValue(String name,String value)
      {
          ConfigurationTree tree = getTree(getPath(name));
          if(tree != null)
          {
              tree.setValue(value);
          }
          else
          {
              add(name).setValue(value);
          }
          
      }
  }
  
  
  
  1.1                  jakarta-jmeter/bin/testfiles/test_config.xml
  
  Index: test_config.xml
  ===================================================================
  JMeter {
        [EMAIL PROTECTED]@/WEB-INF
        [EMAIL PROTECTED]@
        [EMAIL PROTECTED]@
        [EMAIL PROTECTED]@
        [EMAIL PROTECTED]@
        
        services {
        
                org.apache.service.logging.LoggingManager {
                        class=org.apache.service.logging.DefaultLoggingManager
                        [EMAIL PROTECTED]@/WEB-INF/log4j.properties
                }
                
                org.apache.service.classfinder.ClassFinderService {
                        
class=org.apache.service.classfinder.DefaultClassFinderService
                        paths {
                                @webapp_path@/WEB-INF/classes
                                @webapp_path@/WEB-INF/lib/giblex.jar
                        }
                }
                
                org.apache.service.webaction.WebRequestHandler { 
                        
class=org.apache.service.webaction.WebRequestHandlerContainer
                        default_call_page=index.jsp
                        [EMAIL PROTECTED]@
                        requiresLogin {
                                add_todo
                                update_time_lock_pref
                                update_manager_notification_pref
                                add_site
                                add_commit
                                update_site
                                update_full_timesheet
                                Send Timesheet
                                get_time_report
                        }
                        loginProof=user
                        initActions {
                                set_context
                        }
                        autoActions {
                                set_request
                                clean_session
                        }
                        profileInterval=500
                }
                
                org.apache.service.webaction.error.Redirector {
                        
class=org.apache.service.webaction.error.DefaultRedirector
                        exceptions {
                                InvalidLoginException {
                                        page=/@appname@/index.jsp
                                        msg=Incorrect username/password.
                                }
                        NotLoggedInException {
                                page=/@appname@/NoPermission.jsp
                                msg=You must be logged in to use that resource.
                        }
                        NoPermissionError {
                                page=/@appname@/NoPermission.jsp
                                msg=You have no permission to use that resource.
                        }
                        InvalidCredentialsException {
                                page=/@appname@/index.jsp
                                msg=Incorrect username/password.
                        }
                        NoSuchObjectException {
                                msg=[[!
  The system could not find the resource you requested.  Please check your 
request and try again.
  If the problem persists, report it to the system administrators.
                                        !]]
                        }
                        InvalidInputException
                        InvalidActionError {
                                msg=The system requested an unknown task.
                        }
                        DEFAULT {
                                msg=An unexpected error occurred.  Please check 
your request and try again.  If the problem persists, report it to the system 
administrators.
                        }
                        InvalidContextException {
                                msg=You've confused the poor server with your 
use of the back button.  Try again from the top.
                        }
                        NullRequesterException {
                                page=/@appname@/EditRequest.jsp
                                msg=You must select or enter the name of the 
request's requester.
                        }
                        TimesheetNotLockedException {
                                msg=Your timesheet needs to be finalized and 
approved by your manager before it can be sent.
                        }
                }
                }
        
                org.apache.service.authentication.AuthenticationService {
                        
class=org.apache.service.authentication.ldap.LdapAuthenticator
                        ldap-hosts {
                                @LDAP1@
                                @LDAP2@
                                @LDAP3@
                        }
                        users {
                                mike=mstover { password=**** }
                                peter=plin { password=**** }
                        }
                }
        
                org.apache.service.template.TemplateService {
                        
class=org.apache.service.template.velocity.VelocityService
                        [EMAIL PROTECTED]@/WEB-INF/velocity.log
                        [EMAIL PROTECTED]@/WEB-INF/templates
                        file.resource.loader.cache=true
                        file.resource.loader.modificationCheckInterval=60
                        
velocimacro.library=menu.vm,jsp.vm,sql.vm,news.vm,timesheet.vm
                        components {
                                
pmService=org.apache.service.JMeterBusinessLogicService
                                userService=org.apache.service.UserGroupService
                        }
                }
                
                groovyService {
                        class=org.apache.service.template.groovy.GroovyService
                        [EMAIL PROTECTED]@/WEB-INF/groovyTemplates
                        components {
                                
pmService=org.apache.service.JMeterBusinessLogicService
                                userService=org.apache.service.UserGroupService
                                repo=org.apache.service.sql.ObjectMappingService
                        }
                }
                
                org.apache.avalon.excalibur.datasource.DataSourceComponent {
                        
class=org.apache.avalon.excalibur.datasource.J2eeDataSource
                        [EMAIL PROTECTED]@
                }
                
                org.apache.service.sql.ObjectMappingService {
                        class=org.apache.service.sql.DefaultMappingService
                        [EMAIL PROTECTED]@/WEB-INF/mappings
                        packages { org.apache.service.dbObjects }
                        profileInterval=500
                }
                
                org.apache.service.JMeterBusinessLogicService {
                        class=org.apache.service.searching.DefaultJMeterService
                }
                
                org.apache.service.PreferenceService {
                        class=org.apache.service.impl.DefaultPreferenceService
                        preferenceSql {
                                Buddy List=Contact { sql=getBuddyList.sql }
                                Group List=Contact { sql=getPreferredGroups.sql 
}
                                Note Type=Group { sql=getPreferredNoteTypes.sql 
}
                                Project Type=Group { 
sql=getPreferredProjectTypes.sql }
                                Milestones On Timesheet=Group
                                All Sites=Contact
                                Manager Notification=Contact
                                Timesheet Lock Style=Group
                                Commit Scripts=Group
                                Projects By Contact=Contact
                                Projects By Group=Contact
                                Projects=Contact
                                Programs By Contact=Contact
                                Programs By Group=Contact
                                Programs=Contact
                                Applications By Contact=Contact
                                Applications By Group=Contact
                                Applications=Contact
                                Tasks By Contact=Contact
                                Tasks By Group=Contact
                                Tasks=Contact
                                Sites By Contact=Contact
                                Sites By Group=Contact
                                Sites=Contact
                                Todos By Contact=Contact
                                Todos By Group=Contact
                                Todos=Contact
                        }
                }
                
                org.apache.service.PermissionService {
                        class=org.apache.service.impl.DefaultPermissionService
                }
                
                org.apache.service.notification.NotificationService {
                        
class=org.apache.service.notification.DefaultNotificationService
                        mail.transport.protocol=smtp
                        mail.host=smtp.apache.org
                        mail.user=jmeter
                        [EMAIL PROTECTED]
                        [EMAIL PROTECTED]
                        [EMAIL PROTECTED]
                        [EMAIL PROTECTED]@
                        mail.smtp.connectiontimeout=60000
                        mail.smtp.timeout=120000
                }
                
                org.apache.service.UserGroupService {
                        class=org.apache.service.impl.DefaultUserGroupService
                        superUsers {
                                mstover
                                plin
                                sebb
                        }
                }
                
                org.apache.service.domain_event.DomainEventService {
                        class=org.apache.service.domain_event.BasicEventService
                        [EMAIL PROTECTED]@/WEB-INF/eventDefs
                        vmFile=
                        components {
                                
pmService=org.apache.service.JMeterBusinessLogicService
                                
userGroupService=org.apache.service.UserGroupService
                                
emailService=org.apache.service.notification.NotificationService
                                
repository=org.apache.service.sql.ObjectMappingService
                        }
                        eventRetrieval=
                }
                
                org.apache.service.DocumentService {
                        class=org.apache.service.impl.DefaultDocumentService
                        [EMAIL PROTECTED]@
                        proxy=proxy.apache.org {
                                port=8080
                                username=*******
                                password=********
                        }
                }
                
                cvsCommitService {
                        class=org.apache.service.impl.JMeterCommitProcessor
                        CommitProcessor.delay=5
                }
        }
   }
  
  
  1.114     +2 -1      jakarta-jmeter/bin/jmeter.properties
  
  Index: jmeter.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/bin/jmeter.properties,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- jmeter.properties 10 Dec 2004 21:32:52 -0000      1.113
  +++ jmeter.properties 9 Feb 2005 21:11:55 -0000       1.114
  @@ -138,6 +138,7 @@
   #log_level.jmeter.protocol.java=WARN
   #log_level.jmeter.testelements.property=DEBUG
   log_level.jorphan=INFO
  +     
   
   #Log file for log messages.
   # You can specify a different log file for different categories via:
  
  
  
  1.4       +250 -357  
jakarta-jmeter/src/jorphan/org/apache/jorphan/util/Converter.java
  
  Index: Converter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/jorphan/org/apache/jorphan/util/Converter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Converter.java    4 Jan 2005 19:45:05 -0000       1.3
  +++ Converter.java    9 Feb 2005 21:11:55 -0000       1.4
  @@ -13,7 +13,7 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    * 
  -*/
  + */
   package org.apache.jorphan.util;
   
   import java.net.URLEncoder;
  @@ -30,447 +30,340 @@
   /**
    * @author Michael Stover
    */
  -public class Converter
  -{
  +public class Converter {
  +
       /**
        * Convert the given value object to an object of the given type
  +     * 
        * @param value
        * @param toType
  -     * @return
  -     * Object
  +     * @return Object
        */
  -    public static Object convert(Object value,Class toType)
  -    {
  -        if(value == null)
  -        {
  -            return null;
  -        }
  -        else if(toType.isAssignableFrom(value.getClass()))
  -        {
  +    public static Object convert(Object value, Class toType) {
  +        if (value == null) {
  +            value = "";
  +        } else if (toType.isAssignableFrom(value.getClass())) {
               return value;
  -        }
  -        else if(toType.equals(float.class) || toType.equals(Float.class))
  -        {
  +        } else if (toType.equals(float.class) || toType.equals(Float.class)) 
{
               return new Float(getFloat(value));
  -        }
  -        else if(toType.equals(double.class) || toType.equals(Double.class))
  -        {
  -            return new Double(getDouble(value));
  -        }
  -        else if(toType.equals(String.class))
  -        {
  +        } else if (toType.equals(String.class)) {
               return getString(value);
  -        }
  -        else if(toType.equals(int.class) || toType.equals(Integer.class))
  -        {
  +        } else if (toType.equals(int.class) || toType.equals(Integer.class)) 
{
               return new Integer(getInt(value));
  -        }
  -        else if(toType.equals(long.class) || toType.equals(Long.class))
  -        {
  +        } else if (toType.equals(char.class) || 
toType.equals(Character.class)) {
  +            return new Character(getChar(value));
  +        } else if (toType.equals(long.class) || toType.equals(Long.class)) {
               return new Long(getLong(value));
  -        }
  -        else if(toType.equals(boolean.class) || toType.equals(Boolean.class))
  -        {
  -            return JOrphanUtils.valueOf(getBoolean(value));
  -        }
  -        else if(toType.equals(java.util.Date.class))
  -        {
  +        } else if (toType.equals(boolean.class) || 
toType.equals(Boolean.class)) {
  +            return new Boolean(getBoolean(value));
  +        } else if (toType.equals(java.util.Date.class)) {
               return getDate(value);
  -        }
  -        else if(toType.equals(Calendar.class))
  -        {
  +        } else if (toType.equals(Calendar.class)) {
               return getCalendar(value);
  -        }
  -        else if(toType.equals(Class.class))
  -        {
  -           try
  -         {
  -            return Class.forName(value.toString());
  -         }
  -         catch(Exception e)
  -         {
  -            //don't do anything
  -         }
  +        } else if (toType.equals(Class.class)) {
  +            try {
  +                return Class.forName(value.toString());
  +            } catch (Exception e) {
  +                // don't do anything
  +            }
           }
           return value;
       }
   
       /**
  -     * Converts the given object to a calendar object.  Defaults to the 
current date if the given object can't be converted.
  +     * Converts the given object to a calendar object. Defaults to the 
current
  +     * date if the given object can't be converted.
  +     * 
        * @param date
  -     * @return
  -     * Calendar
  +     * @return Calendar
        */
  -    public static Calendar getCalendar(Object date, Calendar defaultValue)
  -    {
  +    public static Calendar getCalendar(Object date, Calendar defaultValue) {
           Calendar cal = new GregorianCalendar();
  -        if (date != null && date instanceof java.util.Date)
  -        {
  +        if (date != null && date instanceof java.util.Date) {
               cal.setTime((java.util.Date) date);
               return cal;
  -        }
  -        else if (date != null)
  -        {
  +        } else if (date != null) {
               DateFormat formatter = 
DateFormat.getDateInstance(DateFormat.SHORT);
               java.util.Date d = null;
  -            try
  -            {
  +            try {
                   d = formatter.parse((String) date.toString());
  -            }
  -            catch (ParseException e)
  -            {
  +            } catch (ParseException e) {
                   formatter = DateFormat.getDateInstance(DateFormat.MEDIUM);
  -                try
  -                {
  +                try {
                       d = formatter.parse((String) date);
  -                }
  -                catch (ParseException e1)
  -                {
  +                } catch (ParseException e1) {
                       formatter = DateFormat.getDateInstance(DateFormat.LONG);
  -                    try
  -                    {
  +                    try {
                           d = formatter.parse((String) date);
  -                    }
  -                    catch (ParseException e2)
  -                    {
  +                    } catch (ParseException e2) {
                           formatter = 
DateFormat.getDateInstance(DateFormat.FULL);
  -                        try
  -                        {
  +                        try {
                               d = formatter.parse((String) date);
  -                        }
  -                        catch (ParseException e3)
  -                        {
  +                        } catch (ParseException e3) {
                               return defaultValue;
                           }
                       }
                   }
               }
               cal.setTime(d);
  -        }
  -        else
  -        {
  -           cal = defaultValue;
  +        } else {
  +            cal = defaultValue;
           }
           return cal;
       }
   
  -    public static Calendar getCalendar(Object o)
  -    {
  +    public static Calendar getCalendar(Object o) {
           return getCalendar(o, new GregorianCalendar());
       }
  -    
  -    public static Date getDate(Object date)
  -    {
  -        return getDate(date,Calendar.getInstance().getTime());
  -    }
  -    
  -    public static String urlEncode(Object toEncode)
  -    {
  -       return URLEncoder.encode(getString(toEncode));
  +
  +    public static Date getDate(Object date) {
  +        return getDate(date, Calendar.getInstance().getTime());
       }
   
  -    public static Date getDate(Object date, Date defaultValue)
  -    {
  +    public static String urlEncode(Object toEncode) {
  +        return URLEncoder.encode(getString(toEncode));
  +    }
  +
  +    public static Date getDate(Object date, Date defaultValue) {
           Date val = null;
  -        if (date != null && date instanceof java.util.Date)
  -        {
  -            return (Date)date;
  -        }
  -        else if (date != null)
  -        {
  +        if (date != null && date instanceof java.util.Date) {
  +            return (Date) date;
  +        } else if (date != null) {
               DateFormat formatter = 
DateFormat.getDateInstance(DateFormat.SHORT);
  -            try
  -            {
  +            java.util.Date d = null;
  +            try {
                   val = formatter.parse(date.toString());
  -            }
  -            catch (ParseException e)
  -            {
  +            } catch (ParseException e) {
                   formatter = DateFormat.getDateInstance(DateFormat.MEDIUM);
  -                try
  -                {
  +                try {
                       val = formatter.parse((String) date);
  -                }
  -                catch (ParseException e1)
  -                {
  +                } catch (ParseException e1) {
                       formatter = DateFormat.getDateInstance(DateFormat.LONG);
  -                    try
  -                    {
  +                    try {
                           val = formatter.parse((String) date);
  -                    }
  -                    catch (ParseException e2)
  -                    {
  +                    } catch (ParseException e2) {
                           formatter = 
DateFormat.getDateInstance(DateFormat.FULL);
  -                        try
  -                        {
  +                        try {
                               val = formatter.parse((String) date);
  -                        }
  -                        catch (ParseException e3)
  -                        {
  +                        } catch (ParseException e3) {
                               return defaultValue;
                           }
                       }
                   }
               }
  -        }
  -        else
  -        {
  +        } else {
               return defaultValue;
           }
           return val;
       }
  -    
  -    public String formatNumber(float num,String pattern)
  -    {
  -       NumberFormat format = new DecimalFormat(pattern);
  -       return format.format((double)num);
  -    }
  -    
  -    public static double getDouble(Object o, double defaultValue)
  -    {
  -        try
  -        {
  -            if (o == null)
  -            {
  +
  +    public String formatNumber(float num, String pattern) {
  +        NumberFormat format = new DecimalFormat(pattern);
  +        return format.format((double) num);
  +    }
  +
  +    public static float getFloat(Object o, float defaultValue) {
  +        try {
  +            if (o == null) {
                   return defaultValue;
               }
  -            if (o instanceof Number)
  -            {
  -                return ((Number) o).doubleValue();
  -            }
  -            else
  -            {
  -                return Double.parseDouble(o.toString());
  +            if (o instanceof Number) {
  +                return ((Number) o).floatValue();
  +            } else {
  +                return Float.parseFloat(o.toString());
               }
  -        }
  -        catch (NumberFormatException e)
  -        {
  +        } catch (NumberFormatException e) {
               return defaultValue;
           }
       }
   
  -    public static double getDouble(Object o)
  -    {
  -        return getDouble(o, 0);
  +    public static float getFloat(Object o) {
  +        return getFloat(o, 0);
       }
   
  -        public static float getFloat(Object o, float defaultValue)
  -        {
  -            try
  -            {
  -                if (o == null)
  -                {
  -                    return defaultValue;
  -                }
  -                if (o instanceof Number)
  -                {
  -                    return ((Number) o).floatValue();
  -                }
  -                else
  -                {
  -                    return Float.parseFloat(o.toString());
  -                }
  -            }
  -            catch (NumberFormatException e)
  -            {
  +    public static boolean getBoolean(Object o) {
  +        return getBoolean(o, false);
  +    }
  +
  +    public static boolean getBoolean(Object o, boolean defaultValue) {
  +        if (o == null) {
  +            return defaultValue;
  +        } else if (o instanceof Boolean) {
  +            return ((Boolean) o).booleanValue();
  +        } else
  +            return new Boolean(o.toString()).booleanValue();
  +    }
  +
  +    /**
  +     * Convert object to integer, return defaultValue if object is not
  +     * convertible or is null.
  +     * 
  +     * @param o
  +     * @param defaultValue
  +     * @return int
  +     */
  +    public static int getInt(Object o, int defaultValue) {
  +        try {
  +            if (o == null) {
                   return defaultValue;
               }
  +            if (o instanceof Number) {
  +                return ((Number) o).intValue();
  +            } else {
  +                return Integer.parseInt(o.toString());
  +            }
  +        } catch (NumberFormatException e) {
  +            return defaultValue;
           }
  +    }
   
  -        public static float getFloat(Object o)
  -        {
  -            return getFloat(o, 0);
  -        }
  -        
  -        public static boolean getBoolean(Object o)
  -        {
  -           return getBoolean(o,false);
  -        }
  -        
  -        public static boolean getBoolean(Object o,boolean defaultValue)
  -        {
  -           if(o == null)
  -           {
  -              return defaultValue;
  -           }
  -           else if(o instanceof Boolean)
  -           {
  -              return ((Boolean)o).booleanValue();
  -           }
  -           else return Boolean.valueOf(o.toString()).booleanValue();
  -        }
  -
  -        /**
  -         * Convert object to integer, return defaultValue if object is not 
convertible or is null.
  -         * @param o
  -         * @param defaultValue
  -         * @return
  -         * int
  -         */
  -        public static int getInt(Object o, int defaultValue)
  -        {
  -            try
  -            {
  -                if (o == null)
  -                {
  -                    return defaultValue;
  -                }
  -                if (o instanceof Number)
  -                {
  -                    return ((Number) o).intValue();
  -                }
  -                else
  -                {
  -                    return Integer.parseInt(o.toString());
  -                }
  -            }
  -            catch (NumberFormatException e)
  -            {
  +    public static char getChar(Object o) {
  +        return getChar(o, ' ');
  +    }
  +
  +    public static char getChar(Object o, char defaultValue) {
  +        try {
  +            if (o == null) {
                   return defaultValue;
               }
  -        }
  -
  -        /**
  -         * Converts object to an integer, defaults to 0 if object is not 
convertible or is null.
  -         * @param o
  -         * @return
  -         * int
  -         */
  -        public static int getInt(Object o)
  -        {
  -            return getInt(o, 0);
  -        }
  -
  -        /**
  -         * Converts object to a long, return defaultValue if object is not 
convertible or is null.
  -         * @param o
  -         * @param defaultValue
  -         * @return
  -         * long
  -         */
  -        public static long getLong(Object o, long defaultValue)
  -        {
  -            try
  -            {
  -                if (o == null)
  -                {
  +            if (o instanceof Character) {
  +                return ((Character) o).charValue();
  +            } else if (o instanceof Byte) {
  +                return (char) ((Byte) o).byteValue();
  +            } else if (o instanceof Integer) {
  +                return (char) ((Integer) o).intValue();
  +            } else {
  +                String s = o.toString();
  +                if (s.length() > 0) {
  +                    return o.toString().charAt(0);
  +                } else
                       return defaultValue;
  -                }
  -                if (o instanceof Number)
  -                {
  -                    return ((Number) o).longValue();
  -                }
  -                else
  -                {
  -                    return Long.parseLong(o.toString());
  -                }
  -            }
  -            catch (NumberFormatException e)
  -            {
  -                return defaultValue;
               }
  +        } catch (Exception e) {
  +            return defaultValue;
           }
  +    }
  +
  +    /**
  +     * Converts object to an integer, defaults to 0 if object is not 
convertible
  +     * or is null.
  +     * 
  +     * @param o
  +     * @return int
  +     */
  +    public static int getInt(Object o) {
  +        return getInt(o, 0);
  +    }
   
  -        /**
  -         * Converts object to a long, defaults to 0 if object is not 
convertible or is null
  -         * @param o
  -         * @return
  -         * long
  -         */
  -        public static long getLong(Object o)
  -        {
  -            return getLong(o, 0);
  -        }
  -        
  -        public static String formatDate(Date date,String pattern)
  -        {
  -            if(date == null)
  -            {
  -                return "";
  -            }
  -            SimpleDateFormat format = new SimpleDateFormat(pattern);
  -            return format.format(date);
  -        }
  -        
  -        public static String formatDate(java.sql.Date date,String pattern)
  -        {
  -           if(date == null)
  -           {
  -               return "";
  -           }
  -           SimpleDateFormat format = new SimpleDateFormat(pattern);
  -           return format.format(date);
  -        }
  -        
  -        public static String formatDate(String date,String pattern)
  -        {
  -           return formatDate(getCalendar(date,null),pattern);
  -        }
  -        
  -        public static String formatDate(Calendar date,String pattern)
  -        {
  -           return formatCalendar(date,pattern);
  -        }
  -        
  -        public static String formatCalendar(Calendar date,String pattern)
  -             {
  -             if(date == null)
  -             {
  -                     return "";
  -             }
  -             SimpleDateFormat format = new SimpleDateFormat(pattern);
  -             return format.format(date.getTime());
  -        }
  -
  -        /**
  -         * Converts object to a String, return defaultValue if object is 
null.
  -         * @param o
  -         * @param defaultValue
  -         * @return
  -         * String
  -         */
  -        public static String getString(Object o, String defaultValue)
  -        {
  -            if (o == null)
  -            {
  +    /**
  +     * Converts object to a long, return defaultValue if object is not
  +     * convertible or is null.
  +     * 
  +     * @param o
  +     * @param defaultValue
  +     * @return long
  +     */
  +    public static long getLong(Object o, long defaultValue) {
  +        try {
  +            if (o == null) {
                   return defaultValue;
               }
  -            return o.toString();
  +            if (o instanceof Number) {
  +                return ((Number) o).longValue();
  +            } else {
  +                return Long.parseLong(o.toString());
  +            }
  +        } catch (NumberFormatException e) {
  +            return defaultValue;
  +        }
  +    }
  +
  +    /**
  +     * Converts object to a long, defaults to 0 if object is not convertible 
or
  +     * is null
  +     * 
  +     * @param o
  +     * @return long
  +     */
  +    public static long getLong(Object o) {
  +        return getLong(o, 0);
  +    }
  +
  +    public static String formatDate(Date date, String pattern) {
  +        if (date == null) {
  +            return "";
  +        }
  +        SimpleDateFormat format = new SimpleDateFormat(pattern);
  +        return format.format(date);
  +    }
  +
  +    public static String formatDate(java.sql.Date date, String pattern) {
  +        if (date == null) {
  +            return "";
  +        }
  +        SimpleDateFormat format = new SimpleDateFormat(pattern);
  +        return format.format(date);
  +    }
  +
  +    public static String formatDate(String date, String pattern) {
  +        return formatDate(getCalendar(date, null), pattern);
  +    }
  +
  +    public static String formatDate(Calendar date, String pattern) {
  +        return formatCalendar(date, pattern);
  +    }
  +
  +    public static String formatCalendar(Calendar date, String pattern) {
  +        if (date == null) {
  +            return "";
  +        }
  +        SimpleDateFormat format = new SimpleDateFormat(pattern);
  +        return format.format(date.getTime());
  +    }
  +
  +    /**
  +     * Converts object to a String, return defaultValue if object is null.
  +     * 
  +     * @param o
  +     * @param defaultValue
  +     * @return String
  +     */
  +    public static String getString(Object o, String defaultValue) {
  +        if (o == null) {
  +            return defaultValue;
           }
  -        
  -        public static String insertLineBreaks(String v,String insertion)
  -             {
  -             if(v == null){
  -                     return "";
  -             }
  -             else
  -             {
  -                     StringBuffer replacement = new StringBuffer();
  -                     StringTokenizer tokens = new 
StringTokenizer(v,"\n",true);
  -                     while(tokens.hasMoreTokens())
  -                     {
  -                             String token = tokens.nextToken();
  -                             if(token.compareTo("\n") == 0)
  -                             {
  -                                     replacement.append(insertion);
  -                             }
  -                             else
  -                             {
  -                                     replacement.append(token);
  -                             }
  -                     }
  -                     return replacement.toString();                          
  -             }
  -        }
  -
  -        /**
  -         * Converts object to a String, defaults to empty string if object 
is null.
  -         * @param o
  -         * @return
  -         * String
  -         */
  -        public static String getString(Object o)
  -        {
  -            return getString(o, "");
  +        return o.toString();
  +    }
  +
  +    public static String insertLineBreaks(String v, String insertion) {
  +        if (v == null) {
  +            return "";
  +        } else {
  +            StringBuffer replacement = new StringBuffer();
  +            StringTokenizer tokens = new StringTokenizer(v, "\n", true);
  +            while (tokens.hasMoreTokens()) {
  +                String token = tokens.nextToken();
  +                if (token.compareTo("\n") == 0) {
  +                    replacement.append(insertion);
  +                } else {
  +                    replacement.append(token);
  +                }
  +            }
  +            return replacement.toString();
           }
  +    }
  +
  +    public static String insertSpaceBreaks(String v, String insertion) {
  +        return v.trim().replaceAll("\\s+", insertion);
  +    }
   
  +    /**
  +     * Converts object to a String, defaults to empty string if object is 
null.
  +     * 
  +     * @param o
  +     * @return String
  +     */
  +    public static String getString(Object o) {
  +        return getString(o, "");
       }
  +}
  
  
  

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

Reply via email to