1 16 17 package org.apache.velocity.tools.view.servlet; 18 19 import org.apache.commons.digester.Digester; 20 import org.apache.commons.digester.Rule; 21 import org.apache.velocity.tools.view.ToolboxRuleSet; 22 import org.apache.velocity.tools.view.servlet.ServletToolboxManager; 23 import org.apache.velocity.tools.view.servlet.ServletToolInfo; 24 25 34 public class ServletToolboxRuleSet extends ToolboxRuleSet 35 { 36 37 47 public void addRuleInstances(Digester digester) 48 { 49 digester.addRule("toolbox/create-session", new CreateSessionRule()); 50 digester.addRule("toolbox/xhtml", new XhtmlRule()); 51 super.addRuleInstances(digester); 52 } 53 54 55 58 protected void addToolRules(Digester digester) 59 { 60 super.addToolRules(digester); 61 digester.addBeanPropertySetter("toolbox/tool/scope", "scope"); 62 } 63 64 65 68 protected Class getToolInfoClass() 69 { 70 return ServletToolInfo.class; 71 } 72 73 74 75 76 80 protected abstract class BooleanConfigRule extends Rule 81 { 82 public void body(String ns, String name, String text) throws Exception 83 { 84 Object parent = digester.peek(); 85 if ("yes".equalsIgnoreCase(text)) 86 { 87 setBoolean(parent, Boolean.TRUE); 88 } 89 else 90 { 91 setBoolean(parent, Boolean.valueOf(text)); 92 } 93 } 94 95 103 public abstract void setBoolean(Object parent, Boolean value) 104 throws Exception ; 105 } 106 107 108 113 protected final class CreateSessionRule extends BooleanConfigRule 114 { 115 public void setBoolean(Object obj, Boolean b) throws Exception 116 { 117 ((ServletToolboxManager)obj).setCreateSession(b.booleanValue()); 118 } 119 } 120 121 122 127 protected final class XhtmlRule extends BooleanConfigRule 128 { 129 public void setBoolean(Object obj, Boolean b) throws Exception 130 { 131 ((ServletToolboxManager)obj).setXhtml(b); 132 } 133 } 134 135 } 136 | Popular Tags |