net.sourceforge.stripes.tag.layout
Class LayoutContext

java.lang.Object
  extended by net.sourceforge.stripes.tag.layout.LayoutContext

public class LayoutContext
extends Object

Used to move contextual information about a layout rendering between a LayoutRenderTag and a LayoutDefinitionTag. Holds the set of overridden components and any parameters provided to the render tag.

Since:
Stripes 1.1
Author:
Tim Fennell, Ben Gunter

Field Summary
static String BROKEN_INCLUDE_KEY
          The attribute name by which the indicator of broken include functionality in the application server can be found in the application scope.
static String LAYOUT_CONTEXT_KEY
          The attribute name by which the stack of layout contexts can be found in the request.
 
Constructor Summary
LayoutContext(LayoutRenderTag renderTag)
          A new context may be created only by a LayoutRenderTag.
 
Method Summary
 void doInclude(PageContext pageContext, String relativeUrlPath)
           Called when a layout tag needs to execute a page in order to execute another layout tag.
protected  void doIncludeHack(PageContext pageContext, String relativeUrlPath)
          An alternative to PageContext.include(String, boolean) that works around broken include functionality in certain application servers, including several current and recent releases of WebLogic.
 String getComponent()
          Get the name of the component to be rendered during the current phase of execution.
 LayoutRenderTagPath getComponentPath()
          Get the list of components in the render page that must execute so that the render tag that created this context can execute.
 Map<String,LayoutComponentRenderer> getComponents()
          Gets the Map of overridden components.
 String getDefinitionPage()
          Get the path to the page that contains the LayoutDefinitionTag referenced by the render tag.
 LayoutContext getFirst()
          Get the first context in the list.
 LayoutContext getLast()
          Get the last context in the list.
 LayoutContext getNext()
          Get the next layout context from the stack.
 LayoutWriter getOut()
          Get the layout writer to which the layout is rendered.
 Map<String,Object> getParameters()
          Gets the Map of parameters.
 LayoutContext getPrevious()
          Get the previous layout context from the stack.
 String getRenderPage()
          Get the path to the page that contains the LayoutRenderTag that created this context.
 LayoutRenderTag getRenderTag()
          Get the render tag that created this context.
 boolean isComponentRenderPhase()
          True if the intention of the current page execution is solely to render a component.
protected  boolean isIncludeBroken(PageContext pageContext)
          Returns true if the current thread is executing in an application server that is known to have issues with doing normal includes using PageContext.include(String, boolean).
 boolean isRendered()
          Returns true if the layout has been rendered, false otherwise.
static LayoutContext lookup(PageContext pageContext)
          Look up the current layout context in a JSP page context.
static LayoutContext pop(PageContext pageContext)
          Remove the current layout context from the stack of layout contexts.
static LayoutContext push(LayoutRenderTag renderTag)
          Create a new layout context for the given render tag and push it onto the stack of layout contexts in a JSP page context.
 void setComponent(String component)
          Set the name of the component to be rendered during the current phase of execution.
 void setComponentRenderPhase(boolean b)
          Set the flag that indicates that the coming execution phase is solely to render a component.
 void setNext(LayoutContext next)
          Set the next layout context in the stack.
 void setRendered(boolean rendered)
          False initially, should be set to true when the layout is actually rendered.
 String toString()
          To String implementation the parameters, and the component names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LAYOUT_CONTEXT_KEY

public static final String LAYOUT_CONTEXT_KEY
The attribute name by which the stack of layout contexts can be found in the request.


BROKEN_INCLUDE_KEY

public static final String BROKEN_INCLUDE_KEY
The attribute name by which the indicator of broken include functionality in the application server can be found in the application scope.

Constructor Detail

LayoutContext

public LayoutContext(LayoutRenderTag renderTag)
A new context may be created only by a LayoutRenderTag. The tag provides all the information necessary to initialize the context.

Parameters:
renderTag - The tag that is beginning a new layout render process.
Method Detail

push

public static LayoutContext push(LayoutRenderTag renderTag)
Create a new layout context for the given render tag and push it onto the stack of layout contexts in a JSP page context.


lookup

public static LayoutContext lookup(PageContext pageContext)
Look up the current layout context in a JSP page context.

Parameters:
pageContext - The JSP page context to search for the layout context stack.

pop

public static LayoutContext pop(PageContext pageContext)
Remove the current layout context from the stack of layout contexts.

Parameters:
pageContext - The JSP page context to search for the layout context stack.
Returns:
The layout context that was popped off the stack, or null if the stack was not found or was empty.

getPrevious

public LayoutContext getPrevious()
Get the previous layout context from the stack.


getNext

public LayoutContext getNext()
Get the next layout context from the stack.


setNext

public void setNext(LayoutContext next)
Set the next layout context in the stack.


getFirst

public LayoutContext getFirst()
Get the first context in the list.


getLast

public LayoutContext getLast()
Get the last context in the list.


doInclude

public void doInclude(PageContext pageContext,
                      String relativeUrlPath)
               throws ServletException,
                      IOException

Called when a layout tag needs to execute a page in order to execute another layout tag. Special handling is implemented to ensure the included page is aware of the current layout context while also ensuring that pages included by other means (e.g., jsp:include or c:import) are not aware of the current layout context.

This method calls PageContext.include(String, boolean) with false as the second parameter so that the response is not flushed before the include request executes.

Throws:
ServletException
IOException

isIncludeBroken

protected boolean isIncludeBroken(PageContext pageContext)
Returns true if the current thread is executing in an application server that is known to have issues with doing normal includes using PageContext.include(String, boolean).


doIncludeHack

protected void doIncludeHack(PageContext pageContext,
                             String relativeUrlPath)
                      throws ServletException,
                             IOException
An alternative to PageContext.include(String, boolean) that works around broken include functionality in certain application servers, including several current and recent releases of WebLogic.

Throws:
ServletException
IOException

getRenderTag

public LayoutRenderTag getRenderTag()
Get the render tag that created this context.


getComponents

public Map<String,LayoutComponentRenderer> getComponents()
Gets the Map of overridden components. Will return an empty Map if no components were overridden.


getParameters

public Map<String,Object> getParameters()
Gets the Map of parameters. Will return an empty Map if none were provided.


isRendered

public boolean isRendered()
Returns true if the layout has been rendered, false otherwise.


setRendered

public void setRendered(boolean rendered)
False initially, should be set to true when the layout is actually rendered.


getRenderPage

public String getRenderPage()
Get the path to the page that contains the LayoutRenderTag that created this context.


getDefinitionPage

public String getDefinitionPage()
Get the path to the page that contains the LayoutDefinitionTag referenced by the render tag.


isComponentRenderPhase

public boolean isComponentRenderPhase()
True if the intention of the current page execution is solely to render a component.


setComponentRenderPhase

public void setComponentRenderPhase(boolean b)
Set the flag that indicates that the coming execution phase is solely to render a component.


getComponent

public String getComponent()
Get the name of the component to be rendered during the current phase of execution.


setComponent

public void setComponent(String component)
Set the name of the component to be rendered during the current phase of execution.


getComponentPath

public LayoutRenderTagPath getComponentPath()
Get the list of components in the render page that must execute so that the render tag that created this context can execute.


getOut

public LayoutWriter getOut()
Get the layout writer to which the layout is rendered.


toString

public String toString()
To String implementation the parameters, and the component names.

Overrides:
toString in class Object


© Copyright 2005-2006, Stripes Development Team.