You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ar...@apache.org on 2003/02/28 06:14:03 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/nested NestedRootTag.java NestedParentSupport.java NestedPropertySupport.java NestedWriteNestingTag.java NestedPropertyTag.java NestedNameSupport.java NestedPropertyHelper.java NestedReference.java NestedTagSupport.java
arron 2003/02/27 21:14:02
Modified: src/share/org/apache/struts/taglib/nested NestedRootTag.java
NestedParentSupport.java NestedPropertySupport.java
NestedWriteNestingTag.java NestedPropertyTag.java
NestedNameSupport.java NestedPropertyHelper.java
NestedReference.java NestedTagSupport.java
Log:
Core Nested Clases
- Most importantly, updated the Copyright to
include 2003.
- Secondly, rejig of the nested tags to allow
them to dance with Tomcat 4.1.18
Revision Changes Path
1.7 +42 -39 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NestedRootTag.java 8 Dec 2002 06:54:51 -0000 1.6
+++ NestedRootTag.java 28 Feb 2003 05:14:01 -0000 1.7
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -84,8 +84,8 @@
* @since Struts 1.1
* @version $Revision$ $Date$
*/
-public class NestedRootTag extends BodyTagSupport implements NestedParentSupport, NestedNameSupport {
-
+public class NestedRootTag extends BodyTagSupport implements NestedNameSupport {
+
/** Getter method for the <i>property</i> property
* @return String value of the property property
*/
@@ -96,7 +96,7 @@
* @param property new value for the property property
*/
public void setProperty(String property) {}
-
+
/** Getter method for the <i>name</i> property
* @return String value of the name property
*/
@@ -109,15 +109,7 @@
public void setName(String name) {
this.name = name;
}
-
-
- /** Getter method for the nestedProperty property
- * @return String value of the nestedProperty property
- */
- public String getNestedProperty() {
- return this.nestedProperty;
- }
-
+
/**
* Overriding method of the heart of the tag. Gets the relative property
* and tells the JSP engine to evaluate its body content.
@@ -125,23 +117,24 @@
* @return int JSP continuation directive.
*/
public int doStartTag() throws JspException {
-
/* set the nested reference for possible inclusions etc */
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
- reference = (NestedReference)
- request.getAttribute(NestedPropertyHelper.NESTED_INCLUDES_KEY);
- if (name == null) {
- this.name = reference.getBeanName();
- this.nestedProperty = reference.getNestedProperty();
- } else {
- NestedReference newRef = new NestedReference(this.name, "");
- request.setAttribute(NestedPropertyHelper.NESTED_INCLUDES_KEY, newRef);
+ // get al the originals
+ originalName = name;
+ originalNesting = NestedPropertyHelper.getCurrentProperty(request);
+ originalNestingName = NestedPropertyHelper.getCurrentName(request, this);
+
+ // set what we have to
+ if (name != null) {
+ NestedPropertyHelper.setProperty(request, "");
+ NestedPropertyHelper.setName(request, this.name);
}
-
- return (EVAL_BODY_TAG);
+
+ // do the JSP thing
+ return (EVAL_BODY_AGAIN);
}
-
+
/**
* Render the resulting content evaluation.
*
@@ -153,10 +146,10 @@
ResponseUtils.writePrevious(pageContext, bodyContent.getString());
bodyContent.clearBody();
}
-
+
return (SKIP_BODY);
}
-
+
/**
* Evaluate the rest of the page
*
@@ -165,23 +158,33 @@
public int doEndTag() throws JspException {
/* reset the reference */
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
- NestedPropertyHelper.setIncludeReference(request, reference);
-
+
+ if (originalNesting == null) {
+ NestedPropertyHelper.deleteReference(request);
+ } else {
+ NestedPropertyHelper.setName(request, originalNestingName);
+ NestedPropertyHelper.setProperty(request, "nestOne");
+ }
+ this.name = originalName;
+
return (EVAL_PAGE);
}
-
-
+
+
/**
* JSP method to release all resources held by the tag.
*/
public void release() {
super.release();
this.name = null;
+ this.originalName = null;
+ this.originalNesting = null;
+ this.originalNestingName = null;
}
-
+
/* usual member variables */
private String name = null;
- private String nestedProperty = "";
-
- private NestedReference reference;
+ private String originalName = "";
+ private String originalNesting = "";
+ private String originalNestingName = "";
}
1.3 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedParentSupport.java
Index: NestedParentSupport.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedParentSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NestedParentSupport.java 22 Jan 2002 03:30:50 -0000 1.2
+++ NestedParentSupport.java 28 Feb 2003 05:14:01 -0000 1.3
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
1.3 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertySupport.java
Index: NestedPropertySupport.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedPropertySupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NestedPropertySupport.java 22 Jan 2002 03:30:50 -0000 1.2
+++ NestedPropertySupport.java 28 Feb 2003 05:14:01 -0000 1.3
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
1.4 +38 -38 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedWriteNestingTag.java
Index: NestedWriteNestingTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedWriteNestingTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NestedWriteNestingTag.java 8 Dec 2002 06:54:51 -0000 1.3
+++ NestedWriteNestingTag.java 28 Feb 2003 05:14:01 -0000 1.4
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,9 +59,9 @@
*/
package org.apache.struts.taglib.nested;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
-import javax.servlet.jsp.tagext.Tag;
import org.apache.struts.util.ResponseUtils;
@@ -75,8 +75,8 @@
* @since Struts 1.1
* @version $Revision$
*/
-public class NestedWriteNestingTag extends BodyTagSupport implements NestedPropertySupport {
-
+public class NestedWriteNestingTag extends BodyTagSupport {
+
/** Getter method for the <i>property</i> property
* @return String value of the property property
*/
@@ -90,8 +90,8 @@
public void setProperty(String newProperty) {
this.property = newProperty;
}
-
-
+
+
/** Getter method for the <i>filter</i> property
* @return String value of the filter property
*/
@@ -105,8 +105,8 @@
public void setFilter(boolean newFilter) {
this.filter = newFilter;
}
-
-
+
+
/**
* Overriding method of the heart of the tag. Gets the relative property
* and tells the JSP engine to evaluate its body content.
@@ -114,45 +114,45 @@
* @return int JSP continuation directive.
*/
public int doStartTag() throws JspException {
-
- /* qualified nested property */
- String nProperty = null;
- /* property which we can process against */
- String usableProperty = null;
-
- /* make sure we're working against good property */
- if (this.property == null || this.property.trim().length() <= 0) {
- usableProperty = "./";
- } else {
- usableProperty = this.property;
- }
-
- Tag pTag = NestedPropertyHelper.getNestingParentTag(this);
- /* set the nested property value */
- nProperty = NestedPropertyHelper.getNestedProperty(usableProperty, pTag);
-
+ // set the original property
+ originalProperty = property;
+
+ HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
+ String nesting = NestedPropertyHelper.getAdjustedProperty(request, property);
+
/* write output, filtering if required */
if (this.filter) {
- ResponseUtils.write(pageContext, ResponseUtils.filter(nProperty));
+ ResponseUtils.write(pageContext, ResponseUtils.filter(nesting));
} else {
- ResponseUtils.write(pageContext, nProperty);
+ ResponseUtils.write(pageContext, nesting);
}
-
+
/* continue with page processing */
return (SKIP_BODY);
}
-
-
+
+ public int doEndTag() throws JspException {
+ // do the super thing
+ int i = super.doEndTag();
+ // reset the property
+ property = originalProperty;
+ // complete
+ return i;
+ }
+
+
/**
* JSP method to release all resources held by the tag.
*/
public void release() {
super.release();
- this.property = null;
this.filter = false;
+ this.property = null;
+ this.originalProperty = null;
}
-
- /* the usual private member variable */
- private String property = null;
+
+ /* the usual private member variables */
private boolean filter = false;
+ private String property = null;
+ private String originalProperty = null;
}
1.7 +44 -68 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NestedPropertyTag.java 8 Dec 2002 06:54:51 -0000 1.6
+++ NestedPropertyTag.java 28 Feb 2003 05:14:01 -0000 1.7
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -79,8 +79,11 @@
* @since Struts 1.1
* @version $Revision$ $Date$
*/
-public class NestedPropertyTag extends BodyTagSupport implements NestedParentSupport, NestedNameSupport {
-
+public class NestedPropertyTag extends BodyTagSupport implements NestedNameSupport {
+
+ public String getName() { return null; }
+ public void setName(String newNamed) {}
+
/** Getter method for the <i>property</i> property
* @return String value of the property property
*/
@@ -95,32 +98,8 @@
*/
public void setProperty(String newProperty) {
property = newProperty;
- if (!isNesting) {
- originalProperty = newProperty;
- }
- }
-
- /** Getter method for the <i>name</i> property
- * @return String value of the name property
- */
- public String getName() {
- return this.name;
- }
- /** Setter method for the <i>name</i> property
- * @param name new value for the name property
- */
- public void setName(String name) {
- this.name = name;
}
-
-
- /** Getter method for the nestedProperty property
- * @return String value of the nestedProperty property
- */
- public String getNestedProperty() {
- return property;
- }
-
+
/**
* Overriding method of the heart of the tag. Gets the relative property
* and tells the JSP engine to evaluate its body content.
@@ -128,74 +107,71 @@
* @return int JSP continuation directive.
*/
public int doStartTag() throws JspException {
-
- /* Set back to the original property */
- property = originalProperty;
-
- /* let the NestedHelper set the properties it can */
- isNesting = true;
- NestedPropertyHelper.setNestedProperties(this);
- isNesting = false;
-
- /* make the current reference */
- NestedReference nr = new NestedReference(getName(), getNestedProperty());
- /* replace and store old session */
+ originalProperty = property;
+
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
- originalReference = NestedPropertyHelper.setIncludeReference(request, nr);
-
- return (EVAL_BODY_TAG);
+ originalNest = NestedPropertyHelper.getCurrentProperty(request);
+ originalName = NestedPropertyHelper.getCurrentName(request, this);
+
+ String nested = NestedPropertyHelper.getAdjustedProperty(request, originalProperty);
+ NestedPropertyHelper.setProperty(request, nested);
+ NestedPropertyHelper.setName(request, originalName);
+
+ // run the body part
+ return (EVAL_BODY_AGAIN);
}
-
-
+
+
/**
* Render the resulting content evaluation.
*
* @return int JSP continuation directive.
*/
public int doAfterBody() throws JspException {
+
/* Render the output */
if (bodyContent != null) {
ResponseUtils.writePrevious(pageContext, bodyContent.getString());
bodyContent.clearBody();
}
-
+
return (SKIP_BODY);
}
-
-
+
+
/**
* Evaluate the rest of the page
*
* @return int JSP continuation directive.
*/
public int doEndTag() throws JspException {
-
/* set the reference back */
- HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
- NestedPropertyHelper.setIncludeReference(request, originalReference);
- originalReference = null;
-
+ HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
+ if (originalNest == null) {
+ NestedPropertyHelper.deleteReference(request);
+ } else {
+ NestedPropertyHelper.setName(request, originalName);
+ NestedPropertyHelper.setProperty(request, originalNest);
+ }
+ property = originalProperty;
return (EVAL_PAGE);
}
-
-
+
+
/**
* JSP method to release all resources held by the tag.
*/
public void release() {
super.release();
this.property = null;
- this.name = null;
+ this.originalNest = null;
+ this.originalName = null;
+ this.originalProperty = null;
}
-
+
/* the usual private member variable */
private String property = null;
- private String name = null;
-
- /* hold original property */
+ private String originalNest = null;
+ private String originalName = null;
private String originalProperty = null;
- private boolean isNesting = false;
-
- /* includes nested references */
- private NestedReference originalReference;
}
1.4 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedNameSupport.java
Index: NestedNameSupport.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedNameSupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NestedNameSupport.java 8 Dec 2002 06:54:51 -0000 1.3
+++ NestedNameSupport.java 28 Feb 2003 05:14:01 -0000 1.4
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
1.13 +161 -189 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NestedPropertyHelper.java 6 Feb 2003 00:26:11 -0000 1.12
+++ NestedPropertyHelper.java 28 Feb 2003 05:14:01 -0000 1.13
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,245 +59,217 @@
*/
package org.apache.struts.taglib.nested;
-import java.util.StringTokenizer;
-
+import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.tagext.Tag;
-import org.apache.struts.taglib.html.FormTag;
import org.apache.struts.taglib.html.Constants;
+import org.apache.struts.taglib.html.FormTag;
-/** A simple helper class that does everything that needs to be done to get the
- * nested tag extension to work. Knowing what tags can define the lineage of
- * other tags, a tag asks of it to look up to the next nested tag and get it's
- * relative nested property.
- *
- * With all tags keeping track of themselves, we only have to seek to the next
- * level, or parent tag, were a tag will append a dot and it's own property.
+/**
+ * <p>A simple helper class that does everything that needs to be done to get
+ * the nested tag extension to work. The tags will pass in their relative
+ * properties and this class will leverage the accessibility of the request
+ * object to calculate the nested references and manage them from a central
+ * place.</p>
+ *
+ * <p>The helper method {@link #setNestedProperties} takes a reference to the
+ * tag itself so all the simpler tags can have their references managed from a
+ * central location. From here, the reference to a provided name is also
+ * preserved for use.</p>
+ *
+ * <p>With all tags keeping track of themselves, we only have to seek to the
+ * next level, or parent tag, were a tag will append a dot and it's own
+ * property.</p>
*
* @author Arron Bates
* @since Struts 1.1
* @version $Revision$ $Date$
*/
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 request User's request object
- * @param reference New reference to put into the session
- */
- public static final NestedReference setIncludeReference(HttpServletRequest request,
- NestedReference reference) {
- /* get the old one if any */
- NestedReference nr = (NestedReference)
- request.getAttribute(NESTED_INCLUDES_KEY);
- if (reference != null) {
- /* put in the new one */
- request.setAttribute(NESTED_INCLUDES_KEY, reference);
- } else {
- /* null target, just remove it */
- request.removeAttribute(NESTED_INCLUDES_KEY);
- }
- /* return the old */
- return nr;
- }
-
-
-
- /**
- * The working horse method.
- * This method works its way back up though the tag tree until it reaches
- * a nested tag from which we're meant to be nesting against.
- * It identifies nested tags by their implementing interfaces and via this
- * mechanism might not have to traverse the entire way up the tree to get
- * to the root tag.
- *
- * @param tag The tag to start with
- * @return The parent tag to which we're nesting against
+
+
+ /**
+ * Returns the current nesting property from the request object.
+ * @param request object to fetch the property reference from
+ * @return String of the bean name to nest against
*/
- public static Tag getNestingParentTag(NestedTagSupport tag) {
- Tag namedTag = (Tag)tag;
- Tag parentTag = null;
-
- /* loop all parent tags until we get one that can be nested against */
- do {
- namedTag = namedTag.getParent();
- if (namedTag instanceof NestedParentSupport ||
- namedTag instanceof FormTag) {
- parentTag = namedTag;
- }
- } while (parentTag == null && namedTag != null);
-
- if (namedTag == null) {
- // need to spit some chips
- }
-
- return parentTag;
+ public static final String getCurrentProperty(HttpServletRequest request) {
+ // get the old one if any
+ NestedReference nr = (NestedReference) request.getAttribute(NESTED_INCLUDES_KEY);
+ // return null or the property
+ return (nr == null) ? null : nr.getNestedProperty();
}
-
-
-
+
+
/**
- * Providing a property and the nested tag's parent, this method will return
- * the qualified nested name. It also checks for a relative property to make
- * sure it's handled correctly.
+ * <p>Returns the bean name from the request object that the properties are
+ * nesting against.</p>
*
- * @param property String of the property to get the nesting version of
- * @param parentTag the nested tag's nesting parent.
- * @return String of the fully qualified nesting property
+ * <p>The requirement of the tag itself could be removed in the future, but is
+ * required if support for the <html:form> tag is maintained.</p>
+ * @param request object to fetch the bean reference from
+ * @param nested tag from which to start the search from
+ * @return the string of the bean name to be nesting against
*/
- public static String getNestedProperty(String property, Tag parentTag) {
+ public static final String getCurrentName(HttpServletRequest request,
+ NestedNameSupport nested) {
+ // get the old one if any
+ NestedReference nr = (NestedReference) request.getAttribute(NESTED_INCLUDES_KEY);
+ // return null or the property
+ if (nr != null) {
+ return nr.getBeanName();
- // return if there's nothing to play with.
- if (property == null) { return null; }
+ } else {
+ // need to look for a form tag...
+ Tag tag = (Tag) nested;
+ Tag formTag = null;
- /* if we're just under a root tag no work required */
- if (parentTag instanceof FormTag) {
- /* don't forget to take care of the relative properties */
- if (property.indexOf('/') == -1) {
- return property;
- } else {
- return property.substring(property.indexOf('/')+1, property.length());
- }
- }
-
- if (!(parentTag instanceof NestedParentSupport)) {
- // need to spit chips
- }
-
- NestedParentSupport nestedParent = (NestedParentSupport)parentTag;
+ // loop all parent tags until we get one that can be nested against
+ do {
+ tag = tag.getParent();
+ if (tag != null && tag instanceof FormTag) {
+ formTag = tag;
+ }
+ } while (formTag == null && tag != null);
- if (nestedParent != null) {
- /* return dot notated property from the parent */
- if (property.indexOf('/') == -1) {
- property = nestedParent.getNestedProperty() +"."+ property;
- } else {
- property = getRelativeProperty(property,nestedParent.getNestedProperty());
+ if (formTag == null) {
+ return "";
}
+ // return the form's name
+ return ((FormTag) formTag).getBeanName();
}
+ }
- /* Some properties may be at the start of their hierarchy */
- if (property.startsWith(".")) {
- return property.substring(1, property.length());
- }
- return property;
+ /**
+ * Get the adjusted property. ie: apply the provided property, to the property
+ * already stored in the request object.
+ * @param request to pull the reference from
+ * @param property to retrieve the evaluated nested property with
+ * @return String of the final nested property reference.
+ */
+ public static final String getAdjustedProperty(HttpServletRequest request,
+ String property) {
+ // get the old one if any
+ String parent = getCurrentProperty(request);
+ return calculateRelativeProperty(property, parent);
}
-
-
- /** A convenience method to provide the property straight from a tag using
- * its getProperty() method
- *
- * @param tag the whose property property is to be qualified by nesting
- * @return String of the fully qualified nesting property
+
+ /**
+ * Sets the provided property into the request object for reference by the
+ * other nested tags.
+ * @param request object to set the new property into
+ * @param property String to set the property to
*/
- public static String getNestedProperty(NestedPropertySupport tag) {
- Tag parentTag = getNestingParentTag(tag);
- return getNestedProperty(tag.getProperty(), parentTag);
+ public static final void setProperty(HttpServletRequest request,
+ String property) {
+ // get the old one if any
+ NestedReference nr = referenceInstance(request);
+ nr.setNestedProperty(property);
}
-
-
-
+
/**
- * This method works its way back up though the tag tree until it reaches
- * a nested tag which we can get a reliable source of the bean name.
- *
- * @param tag The tag to start with
- * @return name of the nesting bean we're using
+ * Sets the provided name into the request object for reference by the
+ * other nested tags.
+ * @param request object to set the new name into
+ * @param name String to set the name to
*/
- public static String getNestedNameProperty(NestedTagSupport tag) {
-
- Tag namedTag = (Tag)tag;
- String defaultName = null;
- // see if we're already in the right location
- if (namedTag instanceof NestedNameSupport) {
- String name = ((NestedNameSupport)namedTag).getName();
- // return if we already have a name and not just default
- if (name != null) {
- if (name.equals(Constants.BEAN_KEY)) {
- defaultName = name;
- } else {
- return name;
- }
- }
- }
+ public static final void setName(HttpServletRequest request, String name) {
+ // get the old one if any
+ NestedReference nr = referenceInstance(request);
+ nr.setBeanName(name);
+ }
- /* loop all parent tags until we get one which
- gives a reliable bean name */
- do {
- namedTag = namedTag.getParent();
- } while ( namedTag != null &&
- !(namedTag instanceof FormTag) &&
- !(namedTag instanceof NestedParentSupport) );
-
- if (namedTag == null) {
- if (defaultName != null) {
- return defaultName;
- }
- // now there's an issue
+ /**
+ * Deletes the nested reference from the request object.
+ * @param request object to remove the reference from
+ */
+ public static final void deleteReference(HttpServletRequest request) {
+ // delete the reference
+ request.removeAttribute(NESTED_INCLUDES_KEY);
+ }
+
+ /**
+ * Helper method that will set all the relevant nesting properties for the
+ * provided tag reference depending on the implementation.
+ * @param request object to pull references from
+ * @param tag to set the nesting values into
+ */
+ public static void setNestedProperties(HttpServletRequest request,
+ NestedPropertySupport tag) {
+ boolean adjustProperty = true;
+ /* if the tag implements NestedNameSupport, set the name for the tag also */
+ if (tag instanceof NestedNameSupport) {
+ NestedNameSupport nameTag = (NestedNameSupport)tag;
+ if (nameTag.getName() == null|| Constants.BEAN_KEY.equals(nameTag.getName())) {
+ nameTag.setName(getCurrentName(request, (NestedNameSupport) tag));
+ } else {
+ adjustProperty = false;
+ }
}
-
- String nameTemp = null;
- if (namedTag instanceof FormTag) {
- nameTemp = ((FormTag)namedTag).getBeanName();
- } else if (namedTag instanceof NestedParentSupport) {
- nameTemp = ((NestedParentSupport)namedTag).getName();
+
+ /* get and set the relative property, adjust if required */
+ String property = tag.getProperty();
+ if (adjustProperty) {
+ property = getAdjustedProperty(request, property);
}
- return nameTemp;
+ tag.setProperty(property);
}
-
-
+
+
/**
- * A convenience method by which a tag can just pass itself in and have all of
- * its relevant properties set for it.
- *
- * @param tag The nested tag whose properties are to be set
+ * Pulls the current nesting reference from the request object, and if there
+ * isn't one there, then it will create one and set it.
+ * @param request object to manipulate the reference into
+ * @return current nesting reference as stored in the request object
*/
- public static void setNestedProperties(NestedPropertySupport tag) {
-
- /* get and set the relative property */
- String property = getNestedProperty(tag);
- tag.setProperty(property);
-
- /* if the tag implements NestedNameSupport, set the name for the tag also */
- if (tag instanceof NestedNameSupport && property != null) {
- String name = getNestedNameProperty(tag);
- ((NestedNameSupport)tag).setName(name);
+ private static final NestedReference referenceInstance(HttpServletRequest request) {
+ /* get the old one if any */
+ NestedReference nr = (NestedReference) request.getAttribute(NESTED_INCLUDES_KEY);
+ // make a new one if required
+ if (nr == null) {
+ nr = new NestedReference();
+ request.setAttribute(NESTED_INCLUDES_KEY, nr);
}
+ // return the reference
+ return nr;
}
-
-
-
+
/* This property, providing the property to be appended, and the parent tag
* to append the property to, will calculate the stepping of the property
- * and return the qualified nested property
+ * and return the qualified nested property
*
* @param property the property which is to be appended nesting style
* @param parent the "dot notated" string representing the structure
* @return qualified nested property that the property param is to the parent
*/
- private static String getRelativeProperty(String property, String parent) {
-
+ private static String calculateRelativeProperty(String property,
+ String parent) {
+ if (parent == null) { parent = ""; }
+ if (property == null) { property = ""; }
+
/* Special case... reference my parent's nested property.
Otherwise impossible for things like indexed properties */
if ("./".equals(property) || "this/".equals(property)) {
return parent;
}
+
/* remove the stepping from the property */
String stepping;
-
+
/* isolate a parent reference */
if (property.endsWith("/")) {
stepping = property;
property = "";
} else {
- stepping = property.substring(0,property.lastIndexOf('/')+1);
+ stepping = property.substring(0, property.lastIndexOf('/') + 1);
/* isolate the property */
- property = property.substring(property.lastIndexOf('/')+1,property.length());
+ property = property.substring(property.lastIndexOf('/') + 1, property.length());
}
-
+
if (stepping.startsWith("/")) {
/* return from root */
return property;
@@ -309,11 +281,11 @@
/* tokenize the stepping */
StringTokenizer strT = new StringTokenizer(stepping, "/");
int count = strT.countTokens();
-
+
if (count >= propCount) {
/* return from root */
return property;
-
+
} else {
/* append the tokens up to the token difference */
count = propCount - count;
@@ -323,7 +295,7 @@
result.append('.');
}
result.append(property);
-
+
/* parent reference will have a dot on the end. Leave it off */
if (result.charAt(result.length()-1) == '.') {
return result.substring(0,result.length()-1);
1.2 +10 -6 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedReference.java
Index: NestedReference.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedReference.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NestedReference.java 13 Mar 2002 13:13:28 -0000 1.1
+++ NestedReference.java 28 Feb 2003 05:14:01 -0000 1.2
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,6 @@
* <http://www.apache.org/>.
*
*/
-
package org.apache.struts.taglib.nested;
/**
@@ -69,6 +68,11 @@
* @version $Revision$
*/
public class NestedReference {
+
+ /**
+ * Empty constructor.
+ */
+ public NestedReference() {}
/**
1.3 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedTagSupport.java
Index: NestedTagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/nested/NestedTagSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NestedTagSupport.java 22 Jan 2002 03:30:50 -0000 1.2
+++ NestedTagSupport.java 28 Feb 2003 05:14:01 -0000 1.3
@@ -6,7 +6,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org