001    /*
002     * Copyright 1999-2001,2004 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    
018    package org.apache.commons.workflow.web;
019    
020    
021    import org.apache.commons.digester.Digester;
022    import org.apache.commons.workflow.base.BaseRuleSet;
023    
024    
025    /**
026     * <p><strong>RuleSet</strong> for the Step definitions supported by the
027     * <em>web</em> library.  This library is normally associated with the
028     * following namespace URI:</p>
029     * <pre>
030     *   http://commons.apache.org/workflow/web
031     * </pre>
032     *
033     * @author Craig R. McClanahan
034     * @version $Revision: 561366 $ $Date: 2007-07-31 16:58:29 +0100 (Tue, 31 Jul 2007) $
035     */
036    
037    public class WebRuleSet extends BaseRuleSet {
038    
039    
040        // ------------------------------------------------------------ Constructor
041    
042    
043        /**
044         * Construct a default instance of the <code>RuleSet</code>.
045         */
046        public WebRuleSet() {
047    
048            super();
049            setNamespaceURI("http://commons.apache.org/workflow/web");
050    
051        }
052    
053    
054        // --------------------------------------------------------- Public Methods
055    
056    
057        /**
058         * <p>Add the set of Rule instances defined in this RuleSet to the
059         * specified <code>Digester</code> instance, associating them with
060         * our namespace URI (if any).  This method should only be called
061         * by a Digester instance.</p>
062         *
063         * @param digester Digester instance to which the new Rule instances
064         *  should be added.
065         */
066        public void addRuleInstances(Digester digester) {
067    
068            // Add rules for each Step defined in this package
069            addStandardStep(digester, "forward",
070                            "org.apache.commons.workflow.web.ForwardStep");
071            addStandardStep(digester, "goto",
072                            "org.apache.commons.workflow.web.GotoStep");
073            if (isServlet23()) {
074                addStandardStep(digester, "include",
075                                "org.apache.commons.workflow.web.IncludeStep23");
076            }
077            addStandardStep(digester, "populate",
078                            "org.apache.commons.workflow.web.PopulateStep");
079    
080            // Add rules for all variations on descriptors being matched
081            addStandardDescriptor(digester, "descriptor");   // Standard version
082    
083        }
084    
085    
086        // ------------------------------------------------------ Protected Methods
087    
088    
089        /**
090         * Are we executing in a Servlet 2.3 (or later) environment?
091         */
092        protected boolean isServlet23() {
093    
094            try {
095                Class.forName("javax.servlet.Filter");  // 2.3-or-later class
096                return (true);
097            } catch (ClassNotFoundException e) {
098                return (false);
099            }
100    
101        }
102    
103    
104    }