velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r534258 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config: CompoundConfiguration.java Configuration.java Data.java FactoryConfiguration.java ToolConfiguration.java ToolboxConfiguration.java
Date Tue, 01 May 2007 22:20:19 GMT
Author: nbubna
Date: Tue May  1 15:20:18 2007
New Revision: 534258

URL: http://svn.apache.org/viewvc?view=rev&rev=534258
Log:
add useful toString() implementations to the configuration classes

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/CompoundConfiguration.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Configuration.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Data.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolboxConfiguration.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/CompoundConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/CompoundConfiguration.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/CompoundConfiguration.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/CompoundConfiguration.java
Tue May  1 15:20:18 2007
@@ -38,6 +38,11 @@
         children.add(config);
     }
 
+    protected boolean hasChildren()
+    {
+        return !children.isEmpty();
+    }
+
     protected List<C> getChildren()
     {
         return children;
@@ -78,6 +83,29 @@
         for (C child : getChildren())
         {
             child.validate();
+        }
+    }
+
+    protected void appendChildren(StringBuilder out, String childrenName, String childDelim)
+    {
+        if (hasChildren())
+        {
+            if (hasProperties())
+            {
+                out.append(" and ");
+            }
+            else
+            {
+                out.append("with ");
+            }
+            out.append(getChildren().size());
+            out.append(' ');
+            out.append(childrenName);
+            for (C child : getChildren())
+            {
+                out.append(child);
+                out.append(childDelim);
+            }
         }
     }
 

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Configuration.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Configuration.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Configuration.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Configuration.java
Tue May  1 15:20:18 2007
@@ -70,6 +70,11 @@
         simpleProperties.put(name, value);
     }
 
+    public boolean hasProperties()
+    {
+        return !simpleProperties.isEmpty() || !convertableProperties.isEmpty();
+    }
+
     public Map<String,Object> getSimpleProperties()
     {
         return simpleProperties;
@@ -104,6 +109,25 @@
         for (Property property : getConvertableProperties())
         {
             property.validate();
+        }
+    }
+
+    protected void appendProperties(StringBuilder out)
+    {
+        if (hasProperties())
+        {
+            Map<String,Object> props = getProperties();
+            out.append("with ");
+            out.append(props.size());
+            out.append(" properties [");
+            for (String name : props.keySet())
+            {
+                out.append(name);
+                out.append(" => ");
+                out.append(props.get(name));
+                out.append("; ");
+            }
+            out.append("]");
         }
     }
 

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Data.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Data.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Data.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/Data.java Tue
May  1 15:20:18 2007
@@ -238,6 +238,17 @@
         return dc;
     }
 
+    public String toString()
+    {
+        StringBuilder out = new StringBuilder();
+        out.append("Data '");
+        out.append(key);
+        out.append('\'');
+        out.append(" -> ");
+        out.append(value);
+        return out.toString();
+    }
+
 
 
     protected static class DataConverter

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
Tue May  1 15:20:18 2007
@@ -116,6 +116,30 @@
         }
     }
 
+    public String toString()
+    {
+        StringBuilder out = new StringBuilder();
+        out.append("\nFactoryConfiguration ");
+        appendProperties(out);
+        if (!getData().isEmpty())
+        {
+            out.append(" including ");
+            out.append(getData().size());
+            out.append(" data");
+        }
+        appendChildren(out, "toolboxes: \n ", "\n ");
+        if (!getData().isEmpty())
+        {
+            for (Data datum : getData())
+            {
+                out.append(datum);
+                out.append("\n ");
+            }
+        }
+        return out.toString();
+    }
+
+
     public ToolboxFactory createFactory()
     {
         ToolboxFactory factory = new ToolboxFactory();
@@ -131,7 +155,7 @@
      * the velocity-tools-struts-2.x.jar is being used, then all VelocityTools
      * will be available.  This also means that subclasses in the larger jars
      * will override their superclasses.  So, if you are using the VelocityStruts
-     * jar, then you $link reference will be a StrutsLinkTool.  If you are using
+     * jar, then your $link reference will be a StrutsLinkTool.  If you are using
      * the VelocityView jar, it will be a standard LinkTool.
      */
     public static FactoryConfiguration getDefault()

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolConfiguration.java
Tue May  1 15:20:18 2007
@@ -159,4 +159,30 @@
         }
     }
 
+    public String toString()
+    {
+        StringBuilder out = new StringBuilder();
+        out.append("Tool '");
+        if (getClassname() == null)
+        {
+            out.append(this.key);
+        }
+        else
+        {
+            out.append(getKey());
+        }
+        out.append("' ");
+        out.append("=> ");
+        out.append(getClassname());
+        if (getRestrictTo() != null)
+        {
+            out.append(" only for '");
+            out.append(getRestrictTo());
+            out.append('\'');
+        }
+        out.append(" ");
+        appendProperties(out);
+        return out.toString();
+    }
+
 }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolboxConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolboxConfiguration.java?view=diff&rev=534258&r1=534257&r2=534258
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolboxConfiguration.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ToolboxConfiguration.java
Tue May  1 15:20:18 2007
@@ -144,4 +144,19 @@
         }
     }
 
+    public String toString()
+    {
+        StringBuilder out = new StringBuilder();
+        out.append("Toolbox '");
+        out.append(this.scope);
+        out.append("' ");
+        appendProperties(out);
+        appendChildren(out, "tools: \n  ", "\n  ");
+        if (hasChildren())
+        {
+            out.append(")");
+        }
+        return out.toString();
+    }
+
 }



Mime
View raw message