Author: wglass
Date: Sun Jan 29 21:17:35 2006
New Revision: 373441

URL: http://svn.apache.org/viewcvs?rev=373441&view=rev
Log:
trim spaces from all properties. VELOCITY-274

Modified:
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/texen/ant/TexenTask.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/StringUtils.java
    
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MiscTestCase.java

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
 Sun Jan 29 21:17:35 2006
@@ -21,6 +21,7 @@
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
 import org.apache.velocity.app.event.RuntimeServicesAware;
 import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.util.StringUtils;
 
 /**
  * Base class for escaping references.  To use it, override the following 
methods:
@@ -114,8 +115,8 @@
         /**
          * Get the regular expression pattern.
          */
-        matchRegExp = rs.getConfiguration().getString(getMatchAttribute());
-        if ((matchRegExp != null) && (matchRegExp.trim().length() == 0))
+        matchRegExp = 
StringUtils.nullTrim(rs.getConfiguration().getString(getMatchAttribute()));
+        if ((matchRegExp != null) && (matchRegExp.length() == 0))
         {
             matchRegExp = null;
         }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
 Sun Jan 29 21:17:35 2006
@@ -16,9 +16,10 @@
  * limitations under the License.
  */
 
-import org.apache.velocity.app.event.RuntimeServicesAware;
 import org.apache.velocity.app.event.IncludeEventHandler;
+import org.apache.velocity.app.event.RuntimeServicesAware;
 import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.util.StringUtils;
 
 /**
  * Simple event handler that checks to see if an included page is available.
@@ -82,7 +83,7 @@
     public void setRuntimeServices(RuntimeServices rs) throws Exception
     {
          this.rs = rs;
-         notfound = rs.getString(PROPERTY_NOT_FOUND, DEFAULT_NOT_FOUND).trim();
+         notfound = StringUtils.nullTrim(rs.getString(PROPERTY_NOT_FOUND, 
DEFAULT_NOT_FOUND));
      }
 
 }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
 Sun Jan 29 21:17:35 2006
@@ -30,16 +30,16 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.app.event.EventCartridge;
 import org.apache.velocity.app.event.EventHandler;
-import org.apache.velocity.app.event.RuntimeServicesAware;
 import org.apache.velocity.app.event.IncludeEventHandler;
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
 import org.apache.velocity.app.event.NullSetEventHandler;
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.app.event.RuntimeServicesAware;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.runtime.directive.Directive;
-import org.apache.velocity.runtime.log.LogManager;
 import org.apache.velocity.runtime.log.Log;
+import org.apache.velocity.runtime.log.LogManager;
 import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.node.SimpleNode;
@@ -47,6 +47,7 @@
 import org.apache.velocity.runtime.resource.ResourceManager;
 import org.apache.velocity.util.ClassUtils;
 import org.apache.velocity.util.SimplePool;
+import org.apache.velocity.util.StringUtils;
 import org.apache.velocity.util.introspection.Introspector;
 import org.apache.velocity.util.introspection.Uberspect;
 import org.apache.velocity.util.introspection.UberspectLoggable;
@@ -451,7 +452,15 @@
      */
     public Object getProperty(String key)
     {
-        return configuration.getProperty(key);
+        Object o = configuration.getProperty(key);
+        if (o instanceof String)
+        {
+            return StringUtils.nullTrim((String) o);
+        }
+        else
+        {
+            return o;
+        }
     }
 
     /**
@@ -1167,7 +1176,7 @@
      */
     public String getString(String key)
     {
-        return configuration.getString(key);
+        return StringUtils.nullTrim(configuration.getString(key));
     }
 
     /**

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
 Sun Jan 29 21:17:35 2006
@@ -56,7 +56,7 @@
 
             // if we have a file property, use it to create a FileTarget
             String file = 
(String)rsvc.getProperty(RuntimeConstants.RUNTIME_LOG);
-            if (file != null && file.trim().length() > 0)
+            if (file != null && file.length() > 0)
             {
                 initTarget(file);
             }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
 Sun Jan 29 21:17:35 2006
@@ -75,7 +75,7 @@
             // if we have a file property, then create a separate
             // rolling file log for velocity messages only
             String file = rsvc.getString(RuntimeConstants.RUNTIME_LOG);
-            if (file != null && file.trim().length() > 0)
+            if (file != null && file.length() > 0)
             {
                 initAppender(file);
             }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
 Sun Jan 29 21:17:35 2006
@@ -30,6 +30,7 @@
 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
 import org.apache.velocity.runtime.resource.loader.ResourceLoaderFactory;
 import org.apache.velocity.util.ClassUtils;
+import org.apache.velocity.util.StringUtils;
 
 /**
  * Class to manage the text resource for the Velocity
@@ -120,7 +121,7 @@
              */
             ExtendedProperties configuration = 
                 (ExtendedProperties) sourceInitializerList.get(i);
-            String loaderClass = configuration.getString("class");
+            String loaderClass = 
StringUtils.nullTrim(configuration.getString("class"));
             ResourceLoader loaderInstance = 
                 (ResourceLoader) configuration.get("instance");
 
@@ -216,7 +217,8 @@
 
         Vector resourceLoaderNames = 
             
rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
-
+        StringUtils.trimStrings(resourceLoaderNames);
+        
         for (int i = 0; i < resourceLoaderNames.size(); i++)
         {
             /*

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
 Sun Jan 29 21:17:35 2006
@@ -31,6 +31,7 @@
 import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.runtime.resource.Resource;
 import org.apache.velocity.util.ExceptionUtils;
+import org.apache.velocity.util.StringUtils;
 
 /**
  * <P>This is a simple template file loader that loads templates
@@ -131,11 +132,11 @@
 
      public void init(ExtendedProperties configuration)
      {
-         dataSourceName  = configuration.getString("resource.datasource");
-         tableName       = configuration.getString("resource.table");
-         keyColumn       = configuration.getString("resource.keycolumn");
-         templateColumn  = configuration.getString("resource.templatecolumn");
-         timestampColumn = configuration.getString("resource.timestampcolumn");
+         dataSourceName  = 
StringUtils.nullTrim(configuration.getString("resource.datasource"));
+         tableName       = 
StringUtils.nullTrim(configuration.getString("resource.table"));
+         keyColumn       = 
StringUtils.nullTrim(configuration.getString("resource.keycolumn"));
+         templateColumn  = 
StringUtils.nullTrim(configuration.getString("resource.templatecolumn"));
+         timestampColumn = 
StringUtils.nullTrim(configuration.getString("resource.timestampcolumn"));
          
          if (dataSource != null) 
          {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
 Sun Jan 29 21:17:35 2006
@@ -65,6 +65,8 @@
         
         paths.addAll( configuration.getVector("path") );
 
+        // trim spaces from all paths
+        StringUtils.trimStrings(paths);
         if (log.isInfoEnabled())
         {
             // this section lets tell people what paths we will be using

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
 Sun Jan 29 21:17:35 2006
@@ -86,7 +86,8 @@
         // and Hashtable classes. Classes are implicitly
         // synchronized even if we don't need it.
         Vector paths = configuration.getVector("path");
-
+        StringUtils.trimStrings(paths);
+        
         /*
          *  support the old version but deprecate with a log message
          */
@@ -94,6 +95,7 @@
         if( paths == null || paths.size() == 0)
         {
             paths = configuration.getVector("resource.path");
+            StringUtils.trimStrings(paths);
 
             if (paths != null && paths.size() > 0)
             {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/texen/ant/TexenTask.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/texen/ant/TexenTask.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/texen/ant/TexenTask.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/texen/ant/TexenTask.java
 Sun Jan 29 21:17:35 2006
@@ -332,7 +332,7 @@
                 for (Iterator j = source.getKeys(); j.hasNext(); )
                 {
                     String name = (String) j.next();
-                    String value = source.getString(name);
+                    String value = 
StringUtils.nullTrim(source.getString(name));
                     contextProperties.setProperty(name,value);
                 }
             }
@@ -501,7 +501,7 @@
                 while (i.hasNext())
                 {
                     String property = (String) i.next();
-                    String value = contextProperties.getString(property);
+                    String value = 
StringUtils.nullTrim(contextProperties.getString(property));
 
                     // Now lets quickly check to see if what
                     // we have is numeric and try to put it

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/StringUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/StringUtils.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/StringUtils.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/StringUtils.java
 Sun Jan 29 21:17:35 2006
@@ -599,4 +599,37 @@
         }            
         return true;
     }
+    
+    /**
+     * Trim all strings in a List.  Changes the strings in the existing list.
+     * @param list
+     * @return
+     */
+    public static List trimStrings(List list)
+    {
+        if (list == null)
+            return null;
+        
+        int sz = list.size();
+        for (int i = 0; i < sz; i++)
+            list.set(i,nullTrim((String) list.get(i)));
+        return list;
+    }
+    
+    /**
+     * Trim the string, but pass a null through.
+     * @param s
+     * @return
+     */
+    public static String nullTrim(String s)
+    {
+        if (s == null)
+        {
+            return null;
+        }
+        else
+        {
+            return s.trim();
+        }
+    }
 }

Modified: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MiscTestCase.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MiscTestCase.java?rev=373441&r1=373440&r2=373441&view=diff
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MiscTestCase.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MiscTestCase.java
 Sun Jan 29 21:17:35 2006
@@ -16,6 +16,9 @@
  * limitations under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -65,6 +68,30 @@
         res = StringUtils.chop( arg, 2, eol );
         assertTrue( "Test 4", res.equals("Hell"));
 
+        arg = null;
+        res = StringUtils.nullTrim(arg);
+        assertNull(arg);
+        
+        arg = " test ";
+        res = StringUtils.nullTrim(arg);
+        assertEquals("test",res);
+
+        arg = "test";
+        res = StringUtils.nullTrim(arg);
+        assertEquals("test",res);
+        
+        List list = null;
+        assertNull(StringUtils.trimStrings(list));
+        
+        list = new ArrayList();
+        assertEquals(new ArrayList(),StringUtils.trimStrings(list));
+        
+        list.add("test");
+        list.add(" abc");
+        StringUtils.trimStrings(list);
+        assertEquals("test",list.get(0));
+        assertEquals("abc",list.get(1));
+        
     }
 
 }



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

Reply via email to