Re: [digester] two very simple plugins patches

2003-11-19 Thread robert burrell donkin
committed. many thanks simon.

not only does a test prevent shameful expressions when the code that  
everyone thought to be easy turns out to have a bug in - but it also  
means that anyone introducing a change that breaks this feature will be  
forced to fix it. i heart unit tests :)

- robert

On 19 Nov 2003, at 03:19, Simon Kitching wrote:

On Wed, 2003-11-19 at 11:35, robert burrell donkin wrote:
hi simon

i've committed both patches.

would you be willing to knock up a test case for the second?
You're keeping me honest here :-)

Test case attached.

test-leading- 
slash.patch--- 
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


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


Re: [digester] two very simple plugins patches

2003-11-18 Thread robert burrell donkin
hi simon

i've committed both patches.

would you be willing to knock up a test case for the second?

- robert

On 17 Nov 2003, at 09:43, Simon Kitching wrote:

Hi,

The first attached patch is just a fix for a minor javadoc problem
introduced in an earlier patch.


The second patch is perhaps more controversial: it allows a leading
slash on patterns for the PluginRules class.
ie /root/item is treated just like root/item.

This is useful because plugin classes usually do something like this:
  digester.add(basePattern + /mychildtag);
If the base pattern is , then the pattern ends up with a leading
slash, which is not good.
This patch definitely does *not* alter the behaviour of any code  
outside
plugins (though I think it would be nice for all the Rules classes to
allow leading slashes anyway).

Regards,

Simon
plugins-javadoc.patchplugins- 
slash.patch--- 
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


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


Re: [digester] two very simple plugins patches

2003-11-18 Thread Simon Kitching
On Wed, 2003-11-19 at 11:35, robert burrell donkin wrote:
 hi simon
 
 i've committed both patches.
 
 would you be willing to knock up a test case for the second?

You're keeping me honest here :-)

Test case attached.


Index: org/apache/commons/digester/plugins/TestInline.java
===
RCS file: /home/cvspublic/jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestInline.java,v
retrieving revision 1.3
diff -u -r1.3 TestInline.java
--- org/apache/commons/digester/plugins/TestInline.java	9 Oct 2003 21:09:49 -	1.3
+++ org/apache/commons/digester/plugins/TestInline.java	19 Nov 2003 03:18:22 -
@@ -142,4 +142,51 @@
 assertEquals(L1, label2.getId());
 assertEquals(2, label2.getLabel());
 }
+
+public void testLeadingSlash() throws Exception {
+// Tests that PluginRules handles patterns with a leading slash.
+// 
+// This test doesn't really belong in this class. If a separate test 
+// case class is created for PluginRules, then this method should be
+// moved there.
+
+Digester digester = new Digester();
+PluginRules rc = new PluginRules();
+digester.setRules(rc);
+
+PluginCreateRule pcr = new PluginCreateRule(Widget.class);
+digester.addRule(/root/widget, pcr);
+digester.addSetNext(/root/widget, addChild);
+
+Container root = new Container();
+digester.push(root);
+
+try {
+digester.parse(
+TestAll.getInputStream(this, test1.xml));
+}
+catch(Exception e) {
+throw e;
+}
+
+Object child;
+List children = root.getChildren();
+assertTrue(children != null);
+assertEquals(2, children.size());
+
+child = children.get(0);
+assertTrue(child != null);
+assertEquals(TextLabel.class, child.getClass());
+TextLabel label1 = (TextLabel) child;
+assertEquals(anonymous, label1.getId());
+assertEquals(1, label1.getLabel());
+
+child = children.get(1);
+assertTrue(child != null);
+assertEquals(TextLabel.class, child.getClass());
+TextLabel label2 = (TextLabel) child;
+assertEquals(L1, label2.getId());
+assertEquals(2, label2.getLabel());
+}
+
 }

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

[digester] two very simple plugins patches

2003-11-17 Thread Simon Kitching
Hi,

The first attached patch is just a fix for a minor javadoc problem
introduced in an earlier patch.



The second patch is perhaps more controversial: it allows a leading
slash on patterns for the PluginRules class.

ie /root/item is treated just like root/item.

This is useful because plugin classes usually do something like this:
  digester.add(basePattern + /mychildtag);

If the base pattern is , then the pattern ends up with a leading
slash, which is not good.

This patch definitely does *not* alter the behaviour of any code outside
plugins (though I think it would be nice for all the Rules classes to
allow leading slashes anyway).

Regards,

Simon
Index: src/java/org/apache/commons/digester/plugins/PluginCreateRule.java
===
RCS file: /home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginCreateRule.java,v
retrieving revision 1.8
diff -u -r1.8 PluginCreateRule.java
--- src/java/org/apache/commons/digester/plugins/PluginCreateRule.java	16 Nov 2003 22:37:35 -	1.8
+++ src/java/org/apache/commons/digester/plugins/PluginCreateRule.java	16 Nov 2003 22:47:53 -
@@ -301,8 +301,8 @@
  * associated with the specified pattern. Check all configuration data is
  * valid and remember the pattern for later.
  * 
- * @param pattern is the digester match pattern that is associated with
- * this rule instance, eg root/widget.
+ * @param matchPattern is the digester match pattern that is associated 
+ * with this rule instance, eg root/widget.
  * @exception PluginConfigurationException
  */
 public void postRegisterInit(String matchPattern)
Index: src/java/org/apache/commons/digester/plugins/PluginRules.java
===
RCS file: /home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v
retrieving revision 1.6
diff -u -r1.6 PluginRules.java
--- src/java/org/apache/commons/digester/plugins/PluginRules.java	16 Nov 2003 22:37:35 -	1.6
+++ src/java/org/apache/commons/digester/plugins/PluginRules.java	16 Nov 2003 22:46:29 -
@@ -236,6 +236,12 @@
to rule of type [ + rule.getClass().getName() + ]);
 }
 
+// allow patterns with a leading slash character
+if (pattern.startsWith(/))
+{
+pattern = pattern.substring(1);
+}
+
 decoratedRules.add(pattern, rule);
 
 if (rule instanceof InitializableRule) {

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