Author: nbubna
Date: Fri Jul 6 11:43:04 2007
New Revision: 553991
URL: http://svn.apache.org/viewvc?view=rev&rev=553991
Log:
fix problems found when testing alternate configuration methods
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java?view=diff&rev=553991&r1=553990&r2=553991
==============================================================================
---
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
(original)
+++
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
Fri Jul 6 11:43:04 2007
@@ -181,18 +181,19 @@
return this.parent;
}
- public C property(String name, Object value)
+ public EasyWrap<C> property(String name, Object value)
{
this.config.setProperty(name, value);
- return this.config;
+ return this;
}
- public C restrictTo(String path)
+ public EasyWrap<C> restrictTo(String path)
{
if (this.config instanceof ToolConfiguration)
{
ToolConfiguration tool = (ToolConfiguration)this.config;
tool.setRestrictTo(path);
+ return this;
}
else if (this.config instanceof ToolboxConfiguration)
{
@@ -201,6 +202,7 @@
{
tool.setRestrictTo(path);
}
+ return this;
}
throw new IllegalStateException("Wrapping unknown
"+Configuration.class.getName()+": "+getConfiguration());
}
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java?view=diff&rev=553991&r1=553990&r2=553991
==============================================================================
---
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
(original)
+++
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
Fri Jul 6 11:43:04 2007
@@ -36,7 +36,7 @@
* tools.property.locale.converter =
org.apache.velocity.tools.config.LocaleConverter
* tools.request.property.xhtml = true
* tools.request.render = org.apache.velocity.tools.view.ViewRenderTool
- * tools.request.render.parse.depth = 5
+ * tools.request.render.parseDepth = 5
* tools.request.search = com.foo.tools.MySearchTool
* tools.request.search.itemsPerPage = 10
* tools.application.math = org.apache.velocity.tools.generic.MathTool
@@ -86,26 +86,29 @@
Configuration config)
{
ExtendedProperties properties = configProps.subset("property");
- for (Iterator i = properties.getKeys(); i.hasNext(); )
+ if (properties != null)
{
- String name = (String)i.next();
- String value = properties.getString(name);
-
- ExtendedProperties propProps = properties.subset(name);
- if (propProps.isEmpty())
- {
- // then set this as a 'simple' property
- config.setProperty(name, value);
- }
- else
+ for (Iterator i = properties.getKeys(); i.hasNext(); )
{
- // add it as a convertable property
- Property property = new Property();
- property.setName(name);
- property.setValue(value);
+ String name = (String)i.next();
+ String value = properties.getString(name);
- // set the type/converter properties
- setProperties(propProps, property);
+ ExtendedProperties propProps = properties.subset(name);
+ if (propProps.size() == 1)
+ {
+ // then set this as a 'simple' property
+ config.setProperty(name, value);
+ }
+ else
+ {
+ // add it as a convertable property
+ Property property = new Property();
+ property.setName(name);
+ property.setValue(value);
+
+ // set the type/converter properties
+ setProperties(propProps, property);
+ }
}
}
}
@@ -140,8 +143,12 @@
String classname = tools.getString(key);
ToolConfiguration tool = new ToolConfiguration();
- tool.setKey(key);
tool.setClassname(classname);
+ // only manually set the key when necessary
+ if (!key.equals(tool.getDefaultKey()))
+ {
+ tool.setKey(key);
+ }
toolbox.addTool(tool);
// get tool properties prefixed by 'property'
@@ -152,7 +159,10 @@
for (Iterator j = toolProps.getKeys(); j.hasNext(); )
{
String name = (String)j.next();
- tool.setProperty(name, toolProps.getString(name));
+ if (!name.equals(tool.getKey()))
+ {
+ tool.setProperty(name, toolProps.getString(name));
+ }
}
// get special props explicitly
@@ -163,23 +173,26 @@
protected void readData(ExtendedProperties dataset)
{
- for (Iterator i = dataset.getKeys(); i.hasNext(); )
+ if (dataset != null)
{
- String key = (String)i.next();
- // if it contains a period, it can't be a context key;
- // it must be a data property. ignore it for now.
- if (key.indexOf('.') >= 0)
+ for (Iterator i = dataset.getKeys(); i.hasNext(); )
{
- continue;
+ String key = (String)i.next();
+ // if it contains a period, it can't be a context key;
+ // it must be a data property. ignore it for now.
+ if (key.indexOf('.') >= 0)
+ {
+ continue;
+ }
+
+ Data data = new Data();
+ data.setKey(key);
+ data.setValue(dataset.getString(key));
+
+ // get/set the type/converter properties
+ ExtendedProperties props = dataset.subset(key);
+ setProperties(props, data);
}
-
- Data data = new Data();
- data.setKey(key);
- data.setValue(dataset.getString(key));
-
- // get/set the type/converter properties
- ExtendedProperties props = dataset.subset(key);
- setProperties(props, data);
}
}