struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-struts/web/example/WEB-INF action.xml
Date Sun, 16 Jul 2000 00:49:22 GMT
craigmcc    00/07/15 17:49:22

  Modified:    src/share/org/apache/struts/action ActionServlet.java
               src/share/org/apache/struts/digester Digester.java
               web/example/WEB-INF action.xml
  Added:       src/share/org/apache/struts/digester SetPropertyRule.java
  Log:
  Add a new way to set optional properties on <action> and <forward>
  elements that is more tool friendly (i.e. you can have extended
  ActionForward and ActionMapping implementation classes with additional
  properties but still use a to-be-created DTD for the action.xml file).
  
  The new technique lets you add as many <property> entries as you want,
  nested inside an <action> element.  The previous mechanism of just adding
  more attributes on the <action> element itself will continue to work for
  those who prefer that approach -- but you will need to modify the
  action.dtd DTD (when it is added later) for each new attribute.
  
  Revision  Changes    Path
  1.16      +10 -4     jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ActionServlet.java	2000/06/30 01:19:32	1.15
  +++ ActionServlet.java	2000/07/16 00:49:21	1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.15 2000/06/30 01:19:32 craigmcc Exp $
  - * $Revision: 1.15 $
  - * $Date: 2000/06/30 01:19:32 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.16 2000/07/16 00:49:21 craigmcc Exp $
  + * $Revision: 1.16 $
  + * $Date: 2000/07/16 00:49:21 $
    *
    * ====================================================================
    *
  @@ -164,7 +164,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.15 $ $Date: 2000/06/30 01:19:32 $
  + * @version $Revision: 1.16 $ $Date: 2000/07/16 00:49:21 $
    */
   
   public class ActionServlet
  @@ -581,11 +581,17 @@
   	digester.addSetProperties("action-mappings/action/forward");
   	digester.addSetNext("action-mappings/action/forward", "addForward",
   			    "org.apache.struts.action.ActionForward");
  +	digester.addSetProperty("action-mappings/action/forward/property",
  +				"name", "value");
  +	digester.addSetProperty("action-mappings/action/property",
  +				"name", "value");
   	digester.addObjectCreate("action-mappings/forward",
   				 forwardClass, "className");
   	digester.addSetProperties("action-mappings/forward");
   	digester.addSetNext("action-mappings/forward", "addForward",
   			    "org.apache.struts.action.ActionForward");
  +	digester.addSetProperty("action-mappings/forward/property",
  +				"name", "value");
   
   	// Parse the input stream to configure our mappings
   	try {
  
  
  
  1.6       +20 -5     jakarta-struts/src/share/org/apache/struts/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Digester.java	2000/06/23 19:33:34	1.5
  +++ Digester.java	2000/07/16 00:49:21	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
1.5 2000/06/23 19:33:34 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/06/23 19:33:34 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
1.6 2000/07/16 00:49:21 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/07/16 00:49:21 $
    *
    * ====================================================================
    * 
  @@ -142,7 +142,7 @@
    * hard code the configuration logic.
    *
    * @author Craig McClanahan
  - * @version $Revision: 1.5 $ $Date: 2000/06/23 19:33:34 $
  + * @version $Revision: 1.6 $ $Date: 2000/07/16 00:49:21 $
    */
   
   public final class Digester extends HandlerBase {
  @@ -537,7 +537,7 @@
   		try {
   		    ((Rule) rules.elementAt(i)).begin(list);
   		} catch (Exception e) {
  -		    log("Begin event through exception");
  +		    log("Begin event threw exception", e);
   		    throw new SAXException(e);
   		}
   	    }
  @@ -944,6 +944,21 @@
   
   	addRule(pattern,
   	        new SetPropertiesRule(this));
  +
  +    }
  +
  +
  +    /**
  +     * Add a "set property" rule for the specified parameters.
  +     *
  +     * @param pattern Element matching pattern
  +     * @param name Attribute name containing the property name to be set
  +     * @param value Attribute name containing the property value to set
  +     */
  +    public void addSetProperty(String pattern, String name, String value) {
  +
  +	addRule(pattern,
  +		new SetPropertyRule(this, name, value));
   
       }
   
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/digester/SetPropertyRule.java
  
  Index: SetPropertyRule.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/digester/SetPropertyRule.java,v
1.1 2000/07/16 00:49:22 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/07/16 00:49:22 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  
  package org.apache.struts.digester;
  
  
  import java.util.Hashtable;
  import org.xml.sax.AttributeList;
  import org.apache.struts.util.BeanUtils;
  
  
  /**
   * Rule implementation that sets an individual property on the object at the
   * top of the stack, based on attributes with specified names.
   *
   * @author Craig McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/07/16 00:49:22 $
   */
  
  public final class SetPropertyRule extends Rule {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a "set property" rule with the specified name and value
       * attributes.
       *
       * @param digester The digester with which this rule is associated
       * @param name Name of the attribute that will contain the name of the
       *  property to be set
       * @param value Name of the attribute that will contain the value to which
       *  the property should be set
       */
      public SetPropertyRule(Digester digester, String name, String value) {
  
  	super(digester);
  	this.name = name;
  	this.value = value;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The attribute that will contain the property name.
       */
      private String name = null;
  
  
      /**
       * The attribute that will contain the property value.
       */
      private String value = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the beginning of this element.
       *
       * @param context The associated context
       * @param attributes The attribute list of this element
       */
      public void begin(AttributeList attributes) throws Exception {
  
  	// Identify the actual property name and value to be used
  	String actualName = null;
  	String actualValue = null;
  	Hashtable values = new Hashtable();
  	for (int i = 0; i < attributes.getLength(); i++) {
  	    String name = attributes.getName(i);
  	    String value = attributes.getValue(i);
  	    if (name.equals(this.name))
  		actualName = value;
  	    else if (name.equals(this.value))
  		actualValue = value;
  	}
  	values.put(actualName, actualValue);
  
  	// Populate the corresponding property of the top object
  	Object top = digester.peek();
  	if (digester.getDebug() >= 1)
  	    digester.log("Set " + top.getClass().getName() + " property " +
  			 actualName + " to " + actualValue);
  	BeanUtils.populate(top, values);
  
      }
  
  
  }
  
  
  
  1.5       +7 -6      jakarta-struts/web/example/WEB-INF/action.xml
  
  Index: action.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/action.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- action.xml	2000/06/20 16:34:14	1.4
  +++ action.xml	2000/07/16 00:49:22	1.5
  @@ -47,12 +47,13 @@
     </action>
   
     <!-- Save mail subscription -->
  -  <action    path="/saveSubscription"
  -      actionClass="org.apache.struts.example.SaveSubscriptionAction"
  -    formAttribute="subscriptionForm"
  -        formClass="org.apache.struts.example.SubscriptionForm"
  -        inputForm="/subscription.jsp">
  -    <forward name="success"    path="/editRegistration.do?action=Edit"/>
  +  <action     path="/saveSubscription"
  +       actionClass="org.apache.struts.example.SaveSubscriptionAction">
  +    <property name="formAttribute" value="subscriptionForm"/>
  +    <property name="formClass"
  +             value="org.apache.struts.example.SubscriptionForm"/>
  +    <property name="inputForm"     value="/subscription.jsp"/>
  +    <forward  name="success"        path="/editRegistration.do?action=Edit"/>
     </action>
   
   </action-mappings>
  
  
  

Mime
View raw message