You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2007/08/21 21:18:31 UTC
svn commit: r568239 - in /velocity/tools/branches/2.x/src:
main/java/org/apache/velocity/tools/generic/FieldTool.java
test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
Author: nbubna
Date: Tue Aug 21 12:18:30 2007
New Revision: 568239
URL: http://svn.apache.org/viewvc?rev=568239&view=rev
Log:
allow direct retrieval of single fields without importing all in a class
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/FieldTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/FieldTool.java?rev=568239&r1=568238&r2=568239&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/FieldTool.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/FieldTool.java Tue Aug 21 12:18:30 2007
@@ -136,6 +136,23 @@
{
return ((MutableField)o).getValue();
}
+ // if we have no value and the name looks like a path
+ else if (o == null && name.indexOf('.') > 0)
+ {
+ // treat the name as a full fieldpath
+ try
+ {
+ return ClassUtils.getFieldValue(name);
+ }
+ catch (Exception e)
+ {
+System.out.println(""+e);e.printStackTrace();
+ if (log != null)
+ {
+ log.debug("Unable to retrieve value of field at "+name, e);
+ }
+ }
+ }
// otherwise, we should have stored the value directly
return o;
}
Modified: velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java?rev=568239&r1=568238&r2=568239&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java (original)
+++ velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java Tue Aug 21 12:18:30 2007
@@ -156,6 +156,9 @@
assertFalse(foo.equals(MUTABLE_FIELD));
// make sure the fieldtool recognized that it changed
assertEquals(MUTABLE_FIELD, fieldTool.get("MUTABLE_FIELD"));
+
+ // pass a full field path to the get() method
+ assertEquals(Long.MIN_VALUE, fieldTool.get("java.lang.Long.MIN_VALUE"));
}
public @Test void testMathTool() {