mrdon 2003/10/24 17:02:33 Modified: contrib/struts-chain/src/conf chain-config.xml contrib/struts-chain/src/java/org/apache/struts/chain Constants.java Added: contrib/struts-chain/src/java/org/apache/struts/chain AbstractPerformInclude.java SelectInclude.java contrib/struts-chain/src/java/org/apache/struts/chain/servlet PerformInclude.java Log: Adding processInclude() replacement commands Revision Changes Path 1.7 +12 -2 jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml Index: chain-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- chain-config.xml 24 Oct 2003 02:35:02 -0000 1.6 +++ chain-config.xml 25 Oct 2003 00:02:32 -0000 1.7 @@ -88,7 +88,7 @@ processForward SelectForward - processInclude NOT SUPPORTED YET + processInclude SelectInclude / PerformInclude processActionCreate CreateAction @@ -161,7 +161,17 @@ <!-- Select the appropriate ForwardConfig for action mappings that only have an ActionForward --> <command - className="org.apache.struts.chain.servlet.SelectForward"/> + className="org.apache.struts.chain.servlet.SelectForward"/> + + + <!-- Select the include uri (if any) for the current action mapping --> + <command + className="org.apache.struts.chain.SelectInclude"/> + + + <!-- Perform the include (if needed) --> + <command + className="org.apache.struts.chain.servlet.PerformInclude"/> <!-- Create (if needed) the Action for this request --> 1.5 +10 -4 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Constants.java 10 Oct 2003 04:26:16 -0000 1.4 +++ Constants.java 25 Oct 2003 00:02:33 -0000 1.5 @@ -132,7 +132,13 @@ * will be stored.</p> */ public static final String FORWARD_CONFIG_KEY = "forwardConfig"; - + + /** + * <p>The default context attribute under which the + * include path for the current request + * will be stored.</p> + */ + public static final String INCLUDE_KEY = "include"; /** * <p>The default context attribute under which the 1.1 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractPerformInclude.java Index: AbstractPerformInclude.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractPerformInclude.java,v 1.1 2003/10/25 00:02:33 mrdon Exp $ * $Revision: 1.1 $ * $Date: 2003/10/25 00:02:33 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2003 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", "Struts", 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 [EMAIL PROTECTED] * * 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.chain; import org.apache.commons.chain.Command; import org.apache.commons.chain.Context; import org.apache.struts.Globals; import org.apache.commons.chain.web.WebContext; import org.apache.struts.config.ModuleConfig; /** * <p>Perform forwarding or redirection based on the specified * <code>String</code> (if any).</p> * * @author Don Brown * @version $Revision: 1.1 $ $Date: 2003/10/25 00:02:33 $ */ public abstract class AbstractPerformInclude implements Command { // ------------------------------------------------------ Instance Variables private String includeKey = Constants.INCLUDE_KEY; private String moduleConfigKey = Constants.MODULE_CONFIG_KEY; // -------------------------------------------------------------- Properties /** * <p>Return the context attribute key under which the * include uri for the currently selected application * action is stored.</p> */ public String getIncludeKey() { return (this.includeKey); } /** * <p>Set the context attribute key under which the * include uri for the currently selected application * action is stored.</p> * * @param includeKey The new context attribute key */ public void setIncludeKey(String includeKey) { this.includeKey = includeKey; } /** * <p>Return the context attribute key under which the * <code>ModuleConfig</code> for the currently selected application * module is stored.</p> */ public String getModuleConfigKey() { return (this.moduleConfigKey); } /** * <p>Set the context attribute key under which the * <code>ModuleConfig</code> for the currently selected application * module is stored.</p> * * @param moduleConfigKey The new context attribute key */ public void setModuleConfigKey(String moduleConfigKey) { this.moduleConfigKey = moduleConfigKey; } // ---------------------------------------------------------- Public Methods /** * <p>Perform an include based on the specified * include uri (if any).</p> * * @param context The <code>Context</code> for the current request * * @return <code>true</code> so that processing completes */ public boolean execute(Context context) throws Exception { // Retrieve module config instance WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); // Is there an include to be performed? String include = (String) context.get(getIncludeKey()); if (include == null) { return (true); } // Determine the currect uri String uri = moduleConfig.getPrefix() + include; // Perform the appropriate processing on this include uri perform(context, uri); return (true); } // ------------------------------------------------------- Protected Methods /** * <p>Perform the appropriate processing on the specified * include uri.</p> * * @param context The context for this request * @param include The forward to be performed */ protected abstract void perform(Context context, String include) throws Exception; } 1.1 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/SelectInclude.java Index: SelectInclude.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/SelectInclude.java,v 1.1 2003/10/25 00:02:33 mrdon Exp $ * $Revision: 1.1 $ * $Date: 2003/10/25 00:02:33 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2003 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", "Struts", 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 [EMAIL PROTECTED] * * 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.chain; import org.apache.commons.chain.Command; import org.apache.commons.chain.Context; import org.apache.struts.chain.Constants; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.config.ActionConfig; import org.apache.struts.config.ModuleConfig; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * <p>Select and cache the include for this * <code>ActionConfig</code> if specified.</p> * * @author Don Brown * @version $Revision: 1.1 $ $Date: 2003/10/25 00:02:33 $ */ public class SelectInclude implements Command { // ------------------------------------------------------ Instance Variables private String actionConfigKey = Constants.ACTION_CONFIG_KEY; private String includeKey = Constants.INCLUDE_KEY; private static final Log log = LogFactory.getLog(SelectInclude.class); // -------------------------------------------------------------- Properties /** * <p>Return the context attribute key under which the * <code>ActionConfig</code> for the currently selected application * action is stored.</p> */ public String getActionConfigKey() { return (this.actionConfigKey); } /** * <p>Set the context attribute key under which the * <code>ActionConfig</code> for the currently selected application * action is stored.</p> * * @param actionConfigKey The new context attribute key */ public void setActionConfigKey(String actionConfigKey) { this.actionConfigKey = actionConfigKey; } /** * <p>Return the context attribute key under which the * include uri is stored.</p> */ public String getIncludeKey() { return (this.includeKey); } /** * <p>Set the context attribute key under which the * include uri is stored.</p> * * @param includeKey The new context attribute key */ public void setIncludeKey(String includeKey) { this.includeKey = includeKey; } // ---------------------------------------------------------- Public Methods /** * <p>Select and cache the include uri for this * <code>ActionConfig</code> if specified.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues */ public boolean execute(Context context) throws Exception { // Acquire configuration objects that we need ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); // Cache an include uri if found String include = actionConfig.getInclude(); if (include != null) { if (log.isDebugEnabled()) { log.debug("Including " + include); } context.put(getIncludeKey(), include); } return (false); } } 1.1 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformInclude.java Index: PerformInclude.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformInclude.java,v 1.1 2003/10/25 00:02:33 mrdon Exp $ * $Revision: 1.1 $ * $Date: 2003/10/25 00:02:33 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2003 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", "Struts", 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 [EMAIL PROTECTED] * * 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.chain.servlet; import javax.servlet.RequestDispatcher; import org.apache.commons.chain.Context; import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.Globals; import org.apache.struts.chain.AbstractPerformInclude; import org.apache.struts.chain.Constants; import org.apache.struts.util.RequestUtils; /** * <p>Perform forwarding or redirection based on the specified * include uri (if any).</p> * * @author Don Brown * @version $Revision: 1.1 $ $Date: 2003/10/25 00:02:33 $ */ public class PerformInclude extends AbstractPerformInclude { // ------------------------------------------------------- Protected Methods /** * <p>Perform the appropriate processing on the specified * include uri.</p> * * @param context The context for this request * @param uri The uri to be included */ protected void perform(Context context, String uri) throws Exception { ServletWebContext swcontext = (ServletWebContext) context; RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri); rd.forward(swcontext.getRequest(), swcontext.getResponse()); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]