arron 02/03/13 05:13:28 Modified: src/share/org/apache/struts/taglib/nested NestedPropertyHelper.java NestedPropertyTag.java NestedRootTag.java src/share/org/apache/struts/taglib/nested/html NestedFormTag.java src/share/org/apache/struts/taglib/nested/logic NestedIterateTag.java Added: src/share/org/apache/struts/taglib/nested NestedReference.java Log: Allowing the details of a nested structure to be maintained through to a dynamicly included JSP. Revision Changes Path 1.6 +35 -6 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyHelper.java Index: NestedPropertyHelper.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyHelper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- NestedPropertyHelper.java 12 Feb 2002 07:01:57 -0000 1.5 +++ NestedPropertyHelper.java 13 Mar 2002 13:13:28 -0000 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyHelper.java,v 1.5 2002/02/12 07:01:57 arron Exp $ - * $Revision: 1.5 $ - * $Date: 2002/02/12 07:01:57 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyHelper.java,v 1.6 2002/03/13 13:13:28 arron Exp $ + * $Revision: 1.6 $ + * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -62,6 +62,7 @@ import java.util.StringTokenizer; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; +import javax.servlet.http.HttpSession; import org.apache.struts.taglib.nested.html.*; import org.apache.struts.taglib.nested.logic.*; import org.apache.struts.taglib.html.FormTag; @@ -76,10 +77,35 @@ * * @author Arron Bates * @since Struts 1.1 - * @version $Revision: 1.5 $ $Date: 2002/02/12 07:01:57 $ + * @version $Revision: 1.6 $ $Date: 2002/03/13 13:13:28 $ */ public class NestedPropertyHelper { + /* key that the tags can rely on to set the details against */ + public static final String NESTED_INCLUDES_KEY = "<nested-includes-key/>"; + + /** Sets the passed reference to the session object, and returns any reference + * that was already there + * @param session User's session object + * @param reference New reference to put into the session + */ + public static final NestedReference setIncludeReference(HttpSession session, + NestedReference reference) { + /* get the old one if any */ + NestedReference nr = (NestedReference) + session.getAttribute(NESTED_INCLUDES_KEY); + if (reference != null) { + /* put in the new one */ + session.setAttribute(NESTED_INCLUDES_KEY, reference); + } else { + /* null target, just remove it */ + session.removeAttribute(NESTED_INCLUDES_KEY); + } + /* return the old */ + return nr; + } + + /** * The working horse method. @@ -128,8 +154,7 @@ public static String getNestedProperty(String property, Tag parentTag) { /* if we're just under a root tag no work required */ - if ((parentTag instanceof NestedRootTag) - || (parentTag instanceof FormTag)) { + if (parentTag instanceof FormTag) { /* don't forget to take care of the relative properties */ if (property.indexOf('/') == -1) { return property; @@ -151,6 +176,10 @@ property = getRelativeProperty(property,nestedParent.getNestedProperty()); } + /* Some properties may be at the start of their hierarchy */ + if (property.startsWith(".")) { + return property.substring(1, property.length()); + } return property; } 1.3 +21 -4 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyTag.java Index: NestedPropertyTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyTag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NestedPropertyTag.java 22 Jan 2002 03:30:50 -0000 1.2 +++ NestedPropertyTag.java 13 Mar 2002 13:13:28 -0000 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyTag.java,v 1.2 2002/01/22 03:30:50 arron Exp $ - * $Revision: 1.2 $ - * $Date: 2002/01/22 03:30:50 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertyTag.java,v 1.3 2002/03/13 13:13:28 arron Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -61,6 +61,7 @@ import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; +import javax.servlet.http.HttpSession; import org.apache.struts.util.*; /** @@ -75,7 +76,7 @@ * * @author Arron Bates * @since Struts 1.1 - * @version $Revision: 1.2 $ $Date: 2002/01/22 03:30:50 $ + * @version $Revision: 1.3 $ $Date: 2002/03/13 13:13:28 $ */ public class NestedPropertyTag extends BodyTagSupport implements NestedParentSupport, NestedNameSupport { @@ -134,6 +135,13 @@ isNesting = true; NestedPropertyHelper.setNestedProperties(this); isNesting = false; + + /* make the current reference */ + NestedReference nr = new NestedReference(getName(), getNestedProperty()); + /* replace and store old session */ + HttpSession session = (HttpSession)pageContext.getSession(); + originalReference = NestedPropertyHelper.setIncludeReference(session,nr); + return (EVAL_BODY_TAG); } @@ -160,6 +168,12 @@ * @return int JSP continuation directive. */ public int doEndTag() throws JspException { + + /* set the reference back */ + HttpSession session = (HttpSession)pageContext.getSession(); + NestedPropertyHelper.setIncludeReference(session, originalReference); + originalReference = null; + return (EVAL_PAGE); } @@ -180,4 +194,7 @@ /* hold original property */ private String originalProperty = null; private boolean isNesting = false; + + /* includes nested references */ + private NestedReference originalReference; } 1.3 +28 -5 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedRootTag.java Index: NestedRootTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedRootTag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NestedRootTag.java 22 Jan 2002 03:30:50 -0000 1.2 +++ NestedRootTag.java 13 Mar 2002 13:13:28 -0000 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedRootTag.java,v 1.2 2002/01/22 03:30:50 arron Exp $ - * $Revision: 1.2 $ - * $Date: 2002/01/22 03:30:50 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedRootTag.java,v 1.3 2002/03/13 13:13:28 arron Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -61,6 +61,7 @@ import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; +import javax.servlet.http.HttpSession; import org.apache.struts.util.*; /** @@ -80,7 +81,7 @@ * * @author Arron Bates * @since Struts 1.1 - * @version $Revision: 1.2 $ $Date: 2002/01/22 03:30:50 $ + * @version $Revision: 1.3 $ $Date: 2002/03/13 13:13:28 $ */ public class NestedRootTag extends BodyTagSupport implements NestedParentSupport, NestedNameSupport { @@ -113,7 +114,7 @@ * @return String value of the nestedProperty property */ public String getNestedProperty() { - return ""; + return this.nestedProperty; } /** @@ -123,6 +124,20 @@ * @return int JSP continuation directive. */ public int doStartTag() throws JspException { + + /* set the nested reference for possible inclusions etc */ + HttpSession session = (HttpSession)pageContext.getSession(); + reference = (NestedReference) + session.getAttribute(NestedPropertyHelper.NESTED_INCLUDES_KEY); + + if (name == null) { + this.name = reference.getBeanName(); + this.nestedProperty = reference.getNestedProperty(); + } else { + NestedReference newRef = new NestedReference(this.name, ""); + session.setAttribute(NestedPropertyHelper.NESTED_INCLUDES_KEY, newRef); + } + return (EVAL_BODY_TAG); } @@ -147,6 +162,10 @@ * @return int JSP continuation directive. */ public int doEndTag() throws JspException { + /* reset the reference */ + HttpSession session = (HttpSession)pageContext.getSession(); + NestedPropertyHelper.setIncludeReference(session, reference); + return (EVAL_PAGE); } @@ -159,5 +178,9 @@ this.name = null; } + /* usual member variables */ private String name = null; + private String nestedProperty = ""; + + private NestedReference reference; } 1.1 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedReference.java Index: NestedReference.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedReference.java,v 1.1 2002/03/13 13:13:28 arron Exp $ * $Revision: 1.1 $ * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 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.taglib.nested; /** * So that a nested hierarchy can penetrate a dynamic JSP include, this class * will hold the details of a bean name and nested property. * * @author Arron Bates * @since Struts 1.1 * @version $Revision: 1.1 $ */ public class NestedReference { /** * Constructor takes the all the relevant details to init the object. * @param name String name of the bean that the include is to reference * @param property String nested property value that the include will be * continuing on with. */ public NestedReference(String name, String property) { this.beanName = name; this.property = property; } /** Getter for the bean name * @return String value that will be the bean's reference */ public String getBeanName() { return beanName; } /** Setter for the bean name * @param newName String value to set the bean reference. */ public void setBeanName(String newName) { this.beanName = newName; } /** Getter for the nested property * @return String value that is the nested property for the current nesting */ public String getNestedProperty() { return this.property; } /** Setter for the nested property * @param newProperty String value of the new current nesting level */ public void setNestedProperty(String newProperty) { this.property = newProperty; } /* Usual member variables */ private String beanName; private String property; } 1.3 +41 -4 jakarta-struts/src/share/org/apache/struts/taglib/nested/html/NestedFormTag.java Index: NestedFormTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/html/NestedFormTag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NestedFormTag.java 22 Jan 2002 03:30:50 -0000 1.2 +++ NestedFormTag.java 13 Mar 2002 13:13:28 -0000 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/html/NestedFormTag.java,v 1.2 2002/01/22 03:30:50 arron Exp $ - * $Revision: 1.2 $ - * $Date: 2002/01/22 03:30:50 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/html/NestedFormTag.java,v 1.3 2002/03/13 13:13:28 arron Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -62,13 +62,14 @@ import org.apache.struts.taglib.nested.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; +import javax.servlet.http.HttpSession; import org.apache.struts.taglib.html.FormTag; /** * NestedFormTag. * @author Arron Bates * @since Struts 1.1 - * @version $Revision: 1.2 $ $Date: 2002/01/22 03:30:50 $ + * @version $Revision: 1.3 $ $Date: 2002/03/13 13:13:28 $ */ public class NestedFormTag extends FormTag implements NestedParentSupport { @@ -83,5 +84,41 @@ public String getProperty() { return ""; } + public void setProperty(String newProperty) {} + + + /** + * Overriding to allow the chance to set the details of the system, so that + * dynamic includes can be possible + * @return int JSP continuation directive. + */ + public int doStartTag() throws JspException { + /* store original result */ + int temp = super.doStartTag(); + + /* set the details */ + HttpSession session = (HttpSession)pageContext.getSession(); + NestedReference nr = new NestedReference(getName(), getNestedProperty()); + NestedPropertyHelper.setIncludeReference(session, nr); + + /* continue */ + return temp; + } + + /** + * This is only overriden to clean up the include reference + * @return int JSP continuation directive. + */ + public int doAfterBody() throws JspException { + /* store original result */ + int temp = super.doAfterBody(); + + /* all done. clean up */ + HttpSession session = (HttpSession)pageContext.getSession(); + NestedPropertyHelper.setIncludeReference(session, null); + + /* return super result */ + return temp; + } } 1.3 +48 -6 jakarta-struts/src/share/org/apache/struts/taglib/nested/logic/NestedIterateTag.java Index: NestedIterateTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/logic/NestedIterateTag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NestedIterateTag.java 22 Jan 2002 03:30:51 -0000 1.2 +++ NestedIterateTag.java 13 Mar 2002 13:13:28 -0000 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/logic/NestedIterateTag.java,v 1.2 2002/01/22 03:30:51 arron Exp $ - * $Revision: 1.2 $ - * $Date: 2002/01/22 03:30:51 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/logic/NestedIterateTag.java,v 1.3 2002/03/13 13:13:28 arron Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/13 13:13:28 $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -61,6 +61,7 @@ import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; +import javax.servlet.http.HttpSession; import org.apache.struts.taglib.nested.*; import org.apache.struts.taglib.html.FormTag; import org.apache.struts.taglib.logic.IterateTag; @@ -72,7 +73,7 @@ * * @author Arron Bates * @since Struts 1.1 - * @version $Revision: 1.2 $ $Date: 2002/01/22 03:30:51 $ + * @version $Revision: 1.3 $ $Date: 2002/03/13 13:13:28 $ */ public class NestedIterateTag extends IterateTag implements NestedParentSupport, NestedNameSupport { @@ -108,8 +109,18 @@ NestedPropertyHelper.setNestedProperties(this); isNesting = false; - /* do the tag */ - return super.doStartTag(); + + /* get the original result */ + int temp = super.doStartTag(); + + /* set the include reference */ + HttpSession session = (HttpSession)pageContext.getSession(); + currentReference = new NestedReference(getName(), getNestedProperty()); + originalReference = NestedPropertyHelper.setIncludeReference(session, + currentReference); + + /* return the result */ + return temp; } /** this is overridden so that properties being set by the JSP page aren't @@ -128,7 +139,38 @@ } } + + /** + * This is only overriden as the include reference will need it's index + * updated. + * + * @return int JSP continuation directive. + */ + public int doAfterBody() throws JspException { + /* store original result */ + int temp = super.doAfterBody(); + + if (temp != SKIP_BODY) { + /* set the new reference */ + currentReference.setNestedProperty(getNestedProperty()); + } else { + /* all done. clean up */ + currentReference = null; + + HttpSession session = (HttpSession)pageContext.getSession(); + NestedPropertyHelper.setIncludeReference(session, originalReference); + originalReference = null; + } + + /* return super result */ + return temp; + } + /* hold original property */ private String originalProperty = null; private boolean isNesting = false; + + /* includes nested references */ + private NestedReference originalReference; + private NestedReference currentReference; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>