View Javadoc

1   package org.apache.velocity.tools.view;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.digester.Digester;
23  import org.apache.commons.digester.Rule;
24  import org.apache.commons.digester.RuleSetBase;
25  import org.xml.sax.Attributes;
26  
27  /**
28   * <p>The set of Digester rules required to parse a toolbox
29   * configuration file (<code>toolbox.xml</code>) for the
30   * XMLToolboxManager class.</p>
31   *
32   * @author Nathan Bubna
33   * @author <a href="mailto:henning@schmiedehausen.org">Henning P. Schmiedehausen</a>
34   * @since VelocityTools 1.1
35   * @version $Id: ToolboxRuleSet.java 595822 2007-11-16 21:07:51Z nbubna $
36   * @deprecated Use {@link org.apache.velocity.tools.config.XmlFactoryConfigurationRuleSet}
37   */
38  @Deprecated
39  public class ToolboxRuleSet extends RuleSetBase
40  {
41  
42      /**
43       * <p>Add the set of Rule instances defined in this RuleSet to the
44       * specified <code>Digester</code> instance, associating them with
45       * our namespace URI (if any).  This method should only be called
46       * by a Digester instance.  These rules assume that an instance of
47       * <code>org.apache.velocity.tools.view.ToolboxManager</code> is pushed
48       * onto the evaluation stack before parsing begins.</p>
49       *
50       * @param digester Digester instance to which the new Rule instances
51       *        should be added.
52       */
53      public void addRuleInstances(Digester digester)
54      {
55          addToolRules(digester);
56          addDataRules(digester);
57      }
58  
59  
60      /**
61       * Add rules for digesting tool elements.
62       */
63      protected void addToolRules(Digester digester)
64      {
65          digester.addObjectCreate("toolbox/tool", getToolInfoClass());
66          digester.addBeanPropertySetter("toolbox/tool/key", "key");
67          digester.addBeanPropertySetter("toolbox/tool/class", "classname");
68          digester.addRule("toolbox/tool/parameter", new ParameterRule());
69          digester.addSetNext("toolbox/tool", "addTool");
70      }
71  
72  
73      /**
74       * Add rules for digesting data elements.
75       */
76      protected void addDataRules(Digester digester)
77      {
78          digester.addObjectCreate("toolbox/data", getDataInfoClass());
79          digester.addSetProperties("toolbox/data");
80          digester.addBeanPropertySetter("toolbox/data/key", "key");
81          digester.addBeanPropertySetter("toolbox/data/value", "value");
82          digester.addSetNext("toolbox/data", "addData");
83      }
84  
85  
86      /**
87       * Return the bean class to be created for tool elements.
88       */
89      protected Class getToolInfoClass()
90      {
91          return ViewToolInfo.class;
92      }
93  
94  
95      /**
96       * Return the bean class to be created for data elements.
97       */
98      protected Class getDataInfoClass()
99      {
100         return DataInfo.class;
101     }
102 
103 
104     /****************************** Custom Rules *****************************/
105 
106     /**
107      *
108      */
109     protected static class ParameterRule extends Rule
110     {
111         public void begin(String ns, String ln, Attributes attributes)
112             throws Exception
113         {
114             ViewToolInfo toolinfo = (ViewToolInfo)digester.peek();
115             String name = attributes.getValue("name");
116             String value = attributes.getValue("value");
117             toolinfo.setParameter(name, value);
118         }
119     }
120 
121 }