Revision: 1438
http://stripes.svn.sourceforge.net/stripes/?rev=1438&view=rev
Author: bengunter
Date: 2011-04-27 19:31:04 +0000 (Wed, 27 Apr 2011)
Log Message:
-----------
STS-817: The previous patch fixed the stack overflow, but it did not correctly
evaluate components nested within another component where both components have
the same name. This patch fixes that. It now works for the second, more complex
test case described in STS-817.
Modified Paths:
--------------
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentRenderer.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentTag.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutContext.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutTag.java
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentRenderer.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentRenderer.java
2011-04-27 16:29:25 UTC (rev 1437)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentRenderer.java
2011-04-27 19:31:04 UTC (rev 1438)
@@ -104,49 +104,53 @@
// Grab some values from the current context so they can be restored
when we're done
final LayoutContext savedContext = this.context;
final LayoutContext currentContext = LayoutContext.lookup(pageContext);
- final boolean savedPhase = currentContext.isComponentRenderPhase();
- final boolean savedSilent = currentContext.getOut().isSilent();
- final String savedComponent = currentContext.getComponent();
log.debug("Render component \"", this.component, "\" in ",
getCurrentPage());
- // Turn on the render phase flag and set the component to render
- currentContext.setComponentRenderPhase(true);
- currentContext.setComponent(this.component);
- currentContext.getOut().setSilent(true, pageContext);
-
// Descend the stack from here, trying each context where the
component is registered
- try {
- for (LayoutContext context = savedContext == null ? currentContext
: savedContext
- .getPrevious(); context != null; context =
context.getPrevious()) {
+ for (LayoutContext context = savedContext == null ? currentContext :
savedContext
+ .getPrevious(); context != null; context =
context.getPrevious()) {
- // Skip contexts where the desired component is not registered.
- if (!context.getComponents().containsKey(this.component)) {
- log.trace("Not rendering \"", this.component, "\" in
context ",
- context.getRenderPage(), " -> ",
context.getDefinitionPage());
- continue;
- }
- this.context = context;
+ // Skip contexts where the desired component is not registered.
+ if (!context.getComponents().containsKey(this.component)) {
+ log.trace("Not rendering \"", this.component, "\" in context ",
+ context.getRenderPage(), " -> ",
context.getDefinitionPage());
+ continue;
+ }
+ this.context = context;
+ // Take a snapshot of the context state
+ final String savedComponent = context.getComponent();
+ final boolean savedComponentRenderPhase =
context.isComponentRenderPhase();
+ final boolean savedSilent = context.getOut().isSilent();
+
+ try {
+ // Set up the context to render the component
+ context.setComponentRenderPhase(true);
+ context.setComponent(this.component);
+ context.getOut().setSilent(true, pageContext);
+
log.debug("Start execute \"", this.component, "\" in ",
currentContext.getRenderPage(), " -> ",
currentContext.getDefinitionPage(),
" from ", context.getRenderPage(), " -> ",
context.getDefinitionPage());
- currentContext.doInclude(pageContext, context.getRenderPage());
+ context.doInclude(pageContext, context.getRenderPage());
log.debug("End execute \"", this.component, "\" in ",
currentContext.getRenderPage(), " -> ",
currentContext.getDefinitionPage(),
" from ", context.getRenderPage(), " -> ",
context.getDefinitionPage());
// If the component name has been cleared then the component
rendered
- if (currentContext.getComponent() == null)
+ if (context.getComponent() == null)
return true;
}
+ finally {
+ // Restore the context state
+ context.setComponent(savedComponent);
+ context.setComponentRenderPhase(savedComponentRenderPhase);
+ context.getOut().setSilent(savedSilent, pageContext);
+
+ // Restore the saved context
+ this.context = savedContext;
+ }
}
- finally {
- // Reset the context properties
- currentContext.setComponentRenderPhase(savedPhase);
- currentContext.setComponent(savedComponent);
- currentContext.getOut().setSilent(savedSilent, pageContext);
- this.context = savedContext;
- }
log.debug("Component \"", this.component, "\" evaluated to empty
string in context ",
currentContext.getRenderPage(), " -> ",
currentContext.getDefinitionPage());
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentTag.java
2011-04-27 16:29:25 UTC (rev 1437)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentTag.java
2011-04-27 19:31:04 UTC (rev 1438)
@@ -97,7 +97,7 @@
LayoutTag parent = tag.getLayoutParent();
if (parent instanceof LayoutRenderTag) {
parent = parent.getLayoutParent();
- if (parent == null || parent instanceof LayoutComponentTag
+ if (!(parent instanceof LayoutComponentTag) || parent instanceof
LayoutComponentTag
&& isPathComponent((LayoutComponentTag) parent, path) &&
path.hasNext()) {
return tag.getName().equals(path.next());
}
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutContext.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutContext.java
2011-04-27 16:29:25 UTC (rev 1437)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutContext.java
2011-04-27 19:31:04 UTC (rev 1438)
@@ -25,6 +25,7 @@
import javax.servlet.ServletException;
import javax.servlet.jsp.PageContext;
+import net.sourceforge.stripes.exception.StripesRuntimeException;
import net.sourceforge.stripes.util.Log;
/**
@@ -57,6 +58,12 @@
pageContext.pushBody(context.out);
}
else {
+ // Sanity check
+ if (previous.next != null) {
+ throw new StripesRuntimeException(
+ "Attempt to insert a new context into the middle of
the stack");
+ }
+
// Link the two nodes
context.out = previous.out;
previous.next = context;
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
2011-04-27 16:29:25 UTC (rev 1437)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
2011-04-27 19:31:04 UTC (rev 1438)
@@ -53,8 +53,10 @@
if (context == null) {
LayoutContext context = LayoutContext.lookup(pageContext);
- boolean create = context == null ||
!context.isComponentRenderPhase()
- || context.isComponentRenderPhase() &&
isChildOfCurrentComponent();
+ boolean create = context == null
+ || context.getNext() == null
+ && (!context.isComponentRenderPhase() ||
context.isComponentRenderPhase()
+ && isChildOfCurrentComponent());
if (create)
context = LayoutContext.push(this);
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutTag.java
2011-04-27 16:29:25 UTC (rev 1437)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutTag.java
2011-04-27 19:31:04 UTC (rev 1438)
@@ -91,7 +91,7 @@
/** Pop this tag's page context off each of the component renderers' page
context stacks. */
public void cleanUpComponentRenderers() {
- for (LayoutContext c = LayoutContext.lookup(pageContext); c != null; c
= c.getPrevious()) {
+ for (LayoutContext c = LayoutContext.lookup(pageContext).getLast(); c
!= null; c = c.getPrevious()) {
for (LayoutComponentRenderer renderer :
c.getComponents().values()) {
renderer.popPageContext();
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development