Revision: 1292
http://stripes.svn.sourceforge.net/stripes/?rev=1292&view=rev
Author: bengunter
Date: 2010-09-29 19:06:17 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
STS-391: Did some final cleanup of some of the streaming layout code.
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/LayoutRenderTag.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
2010-09-29 16:26:36 UTC (rev 1291)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutComponentRenderer.java
2010-09-29 19:06:17 UTC (rev 1292)
@@ -46,16 +46,16 @@
private static final Log log =
Log.getInstance(LayoutComponentRenderer.class);
private LinkedList<PageContext> pageContext;
- private String componentName;
- private LayoutContext sourceContext;
+ private String component;
+ private LayoutContext context;
/**
* Create a new instance to render the named component to a string.
*
- * @param componentName The name of the component to render.
+ * @param component The name of the component to render.
*/
- public LayoutComponentRenderer(String componentName) {
- this.componentName = componentName;
+ public LayoutComponentRenderer(String component) {
+ this.component = component;
}
/**
@@ -87,16 +87,6 @@
}
/**
- * Indicates the context in the stack of layout contexts against which the
component is being
- * rendered. Any attempt to render a component with the same name as the
component currently
- * being rendered must execute against a context further down the stack to
avoid infinite
- * recursion.
- */
- public LayoutContext getSourceContext() {
- return sourceContext;
- }
-
- /**
* Write the component to the page context's writer, optionally buffering
the output.
*
* @return True if the named component was found and it indicated that it
successfully rendered;
@@ -107,59 +97,59 @@
public boolean write() throws ServletException, IOException {
final PageContext pageContext = getPageContext();
if (pageContext == null) {
- log.error("Failed to render component \"", componentName, "\"
without a page context!");
+ log.error("Failed to render component \"", this.component, "\"
without a page context!");
return false;
}
// Grab some values from the current context so they can be restored
when we're done
- final LayoutContext context = LayoutContext.lookup(pageContext);
- final boolean phaseFlag = context.isComponentRenderPhase();
- final String component = context.getComponent();
- final boolean silent = context.getOut().isSilent();
- final LayoutContext currentSource = getSourceContext();
- log.debug("Render component \"", componentName, "\" in ",
getCurrentPage());
+ 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
- context.setComponentRenderPhase(true);
- context.setComponent(componentName);
- context.getOut().setSilent(true, pageContext);
+ 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 source = currentSource == null ? context :
currentSource
- .getPrevious(); source != null; source =
source.getPrevious()) {
+ for (LayoutContext context = savedContext == null ? currentContext
: savedContext
+ .getPrevious(); context != null; context =
context.getPrevious()) {
// Skip contexts where the desired component is not registered.
- if (!source.getComponents().containsKey(componentName)) {
- log.trace("Not rendering \"", componentName, "\" in
context ",
- source.getRenderPage(), " -> ",
source.getDefinitionPage());
+ if (!context.getComponents().containsKey(this.component)) {
+ log.trace("Not rendering \"", this.component, "\" in
context ",
+ context.getRenderPage(), " -> ",
context.getDefinitionPage());
continue;
}
- sourceContext = source;
+ this.context = context;
- log.debug("Start execute \"", componentName, "\" in ",
context.getRenderPage(),
- " -> ", context.getDefinitionPage(), " from ",
source.getRenderPage(),
- " -> ", source.getDefinitionPage());
- pageContext.include(source.getRenderPage(), false);
- log.debug("End execute \"", componentName, "\" in ",
context.getRenderPage(),
- " -> ", context.getDefinitionPage(), " from ",
source.getRenderPage(),
- " -> ", source.getDefinitionPage());
+ log.debug("Start execute \"", this.component, "\" in ",
+ currentContext.getRenderPage(), " -> ",
currentContext.getDefinitionPage(),
+ " from ", context.getRenderPage(), " -> ",
context.getDefinitionPage());
+ pageContext.include(context.getRenderPage(), false);
+ 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 (context.getComponent() == null)
+ if (currentContext.getComponent() == null)
return true;
}
}
finally {
// Reset the context properties
- context.setComponentRenderPhase(phaseFlag);
- context.setComponent(component);
- context.getOut().setSilent(silent, pageContext);
- sourceContext = currentSource;
+ currentContext.setComponentRenderPhase(savedPhase);
+ currentContext.setComponent(savedComponent);
+ currentContext.getOut().setSilent(savedSilent, pageContext);
+ this.context = savedContext;
}
- log.debug("Component \"", componentName, "\" evaluated to empty string
in context ",
- context.getRenderPage(), " -> ", context.getDefinitionPage());
+ log.debug("Component \"", this.component, "\" evaluated to empty
string in context ",
+ currentContext.getRenderPage(), " -> ",
currentContext.getDefinitionPage());
return false;
}
@@ -171,27 +161,28 @@
public String toString() {
final PageContext pageContext = getPageContext();
if (pageContext == null) {
- log.error("Failed to render component \"", componentName, "\"
without a page context!");
- return "[Failed to render component \"" + componentName + "\"
without a page context!]";
+ log.error("Failed to render component \"", this.component, "\"
without a page context!");
+ return "[Failed to render component \"" + this.component
+ + "\" without a page context!]";
}
final LayoutContext context = LayoutContext.lookup(pageContext);
String contents;
context.getOut().openBuffer(pageContext);
try {
- log.debug("Start stringify \"", componentName, "\" in ",
context.getRenderPage(),
+ log.debug("Start stringify \"", this.component, "\" in ",
context.getRenderPage(),
" -> ", context.getDefinitionPage());
write();
}
catch (Exception e) {
- log.error(e, "Unhandled exception trying to render component \"",
componentName,
+ log.error(e, "Unhandled exception trying to render component \"",
this.component,
"\" to a string in context ", context.getRenderPage(), //
" -> ", context.getDefinitionPage());
- return "[Failed to render \"" + componentName + "\". See log for
details.]";
+ return "[Failed to render \"" + this.component + "\". See log for
details.]";
}
finally {
- log.debug("End stringify \"", componentName, "\" in ",
context.getRenderPage(), " -> ",
- context.getDefinitionPage());
+ log.debug("End stringify \"", this.component, "\" in ",
context.getRenderPage(),
+ " -> ", context.getDefinitionPage());
contents = context.getOut().closeBuffer(pageContext);
}
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
2010-09-29 16:26:36 UTC (rev 1291)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
2010-09-29 19:06:17 UTC (rev 1292)
@@ -35,7 +35,7 @@
private String name;
private LayoutContext context;
- private boolean contextIsNew, silent, outer;
+ private boolean contextIsNew, silent;
/** Gets the name of the layout to be used. */
public String getName() { return name; }
@@ -62,6 +62,11 @@
return context;
}
+ /** True if this is the outermost layout tag, the one that initiated the
render process. */
+ public boolean isOuterLayoutTag() {
+ return getLayoutAncestor() == null;
+ }
+
/** Used by the JSP container to provide the tag with dynamic attributes.
*/
public void setDynamicAttribute(String uri, String localName, Object
value) throws JspException {
getContext().getParameters().put(localName, value);
@@ -81,7 +86,6 @@
@Override
public int doStartTag() throws JspException {
LayoutContext context = getContext();
- outer = context.getPrevious() == null;
silent = context.getOut().isSilent();
if (contextIsNew) {
@@ -119,7 +123,7 @@
// Substitution of the layout writer for the regular JSP
writer does not work for
// the initial render tag. Its body evaluation still uses the
original JSP writer
// for output. Clear the output buffer before executing the
definition page.
- if (outer) {
+ if (isOuterLayoutTag()) {
try {
context.getOut().clear();
}
@@ -134,15 +138,15 @@
log.debug("Start layout exec in ",
context.getDefinitionPage());
boolean silent = context.getOut().isSilent();
context.getOut().setSilent(true, pageContext);
- pageContext.include(this.name, false);
+ pageContext.include(getName(), false);
context.getOut().setSilent(silent, pageContext);
log.debug("End layout exec in ",
context.getDefinitionPage());
}
catch (Exception e) {
throw new StripesJspException(
"An exception was raised while invoking a layout. The
layout used was " +
- "'" + this.name + "'. The following information was
supplied to the render " +
- "tag: " + this.context.toString(), e);
+ "'" + getName() + "'. The following information was
supplied to the render " +
+ "tag: " + context.toString(), e);
}
// Check that the layout actually got rendered as some
containers will
@@ -150,7 +154,7 @@
if (!context.isRendered()) {
throw new StripesJspException(
"Attempt made to render a layout that does not
exist. The layout name " +
- "provided was '" + this.name + "'. Please check
that a JSP/view exists at " +
+ "provided was '" + getName() + "'. Please check
that a JSP/view exists at " +
"that location within your web application."
);
}
@@ -169,13 +173,12 @@
context.getOut().setSilent(silent, pageContext);
// Skip the rest of the page if this is the outer-most render tag
- return outer ? SKIP_PAGE : EVAL_PAGE;
+ return isOuterLayoutTag() ? SKIP_PAGE : EVAL_PAGE;
}
finally {
this.context = null;
this.contextIsNew = false;
this.silent = false;
- this.outer = false;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development