You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2003/08/02 22:43:10 UTC
cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet ServletToolboxRuleSet.java
nbubna 2003/08/02 13:43:10
Modified: src/java/org/apache/velocity/tools/view/servlet
ServletToolboxRuleSet.java
Log:
refactor to add boolean config rule for XHTML mode
Revision Changes Path
1.2 +50 -15 jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/ServletToolboxRuleSet.java
Index: ServletToolboxRuleSet.java
===================================================================
RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/ServletToolboxRuleSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletToolboxRuleSet.java 22 Jul 2003 18:32:29 -0000 1.1
+++ ServletToolboxRuleSet.java 2 Aug 2003 20:43:10 -0000 1.2
@@ -84,6 +84,7 @@
public void addRuleInstances(Digester digester)
{
digester.addRule("toolbox/create-session", new CreateSessionRule());
+ digester.addRule("toolbox/xhtml", new XhtmlRule());
super.addRuleInstances(digester);
}
@@ -107,30 +108,64 @@
}
+ /****************************** Custom Rules *****************************/
+
/**
- * Rule that sets <code>setCreateSession()</code> for the top object
- * on the stack, which must be a
- * <code>org.apache.velocity.tools.ServletToolboxManager</code>.
+ * Abstract rule for configuring boolean options on the parent
+ * object/element of the matching element.
*/
- protected final class CreateSessionRule extends Rule {
-
- public CreateSessionRule() {
- super();
- }
-
+ protected abstract class BooleanConfigRule extends Rule
+ {
public void body(String ns, String name, String text) throws Exception
{
- ServletToolboxManager stm = (ServletToolboxManager)digester.peek();
+ Object parent = digester.peek();
if ("yes".equalsIgnoreCase(text))
{
- stm.setCreateSession(true);
+ setBoolean(parent, Boolean.TRUE);
}
else
{
- /* follow java rules for boolean value parsing
- * (equivalent to "true".equalsIgnoreCase(text) )*/
- stm.setCreateSession(Boolean.valueOf(text).booleanValue());
+ setBoolean(parent, Boolean.valueOf(text));
}
+ }
+
+ /**
+ * Takes the parent object and boolean value in order to
+ * call the appropriate method on the parent for the
+ * implementing rule.
+ *
+ * @param parent the parent object/element in the digester's stack
+ * @param value the boolean value contained in the current element
+ */
+ public abstract void setBoolean(Object parent, Boolean value)
+ throws Exception;
+ }
+
+
+ /**
+ * Rule that sets <code>setCreateSession()</code> for the top object
+ * on the stack, which must be a
+ * <code>org.apache.velocity.tools.ServletToolboxManager</code>.
+ */
+ protected final class CreateSessionRule extends BooleanConfigRule
+ {
+ public void setBoolean(Object obj, Boolean b) throws Exception
+ {
+ ((ServletToolboxManager)obj).setCreateSession(b.booleanValue());
+ }
+ }
+
+
+ /**
+ * Rule that sets <code>setCreateSession()</code> for the top object
+ * on the stack, which must be a
+ * <code>org.apache.velocity.tools.ServletToolboxManager</code>.
+ */
+ protected final class XhtmlRule extends BooleanConfigRule
+ {
+ public void setBoolean(Object obj, Boolean b) throws Exception
+ {
+ ((ServletToolboxManager)obj).setXhtml(b);
}
}