info.magnolia.module.templating
Class ModelExecutionFilter

java.lang.Object
  extended by info.magnolia.cms.filters.AbstractMgnlFilter
      extended by info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter
          extended by info.magnolia.module.templating.ModelExecutionFilter
All Implemented Interfaces:
info.magnolia.cms.filters.MgnlFilter, javax.servlet.Filter

public class ModelExecutionFilter
extends info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter

Filter that executes the model for a paragraph before template rendering. Looks for a request parameter containing the UUID of the paragraph to execute. The model can decide to send output by itself in which case page rendering is skipped. The model can also return a URI prefixed by "redirect:", "permanent:" or "forward:" to trigger either a temporary redirect, a permanent redirect or a forward respectively. For redirects the URI can be absolute or relative within the web application (the context path is added automatically).

By implementing the EarlyExecutionAware interface the callback will instead be made to a dedicated method making it easier to separate functionality for the two scenarios.

To provide proper semantics this class mirrors functionality in RenderingEngine and AbstractRender, specifically in how it sets up the current content in aggregation state and creation and execution of the model.

Author:
tmattsson
See Also:
AbstractRenderer, RequestDispatchUtil, EarlyExecutionAware

Field Summary
static java.lang.String ACTION_RESULT_ATTRIBUTE_PREFIX
           
static java.lang.String DEFAULT_MODEL_EXECUTION_ATTRIBUTE_NAME
           
static java.lang.String MODEL_ATTRIBUTE_PREFIX
           
 
Constructor Summary
ModelExecutionFilter()
           
 
Method Summary
 void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
           
protected static info.magnolia.cms.core.AggregationState getAggregationStateSafely()
           
protected  info.magnolia.cms.core.Content getContent(java.lang.String uuid)
          Returns the Content node for the supplied uuid.
protected  Paragraph getParagraph(info.magnolia.cms.core.Content content)
          Returns the Paragraph for the supplied Content.
protected  RenderingModelBasedRenderer getRenderingModelBasedRenderer(Paragraph paragraph)
          Returns the ParagraphRenderer for the supplied Paragraph if it supports RenderingModel.
protected  java.lang.String getUuidOfParagraphToExecute()
           
protected  boolean handleActionResult(java.lang.String actionResult, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns true if special handling was performed.
 void setAttributeName(java.lang.String attributeName)
           
 
Methods inherited from class info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter
bypasses, doFilter
 
Methods inherited from class info.magnolia.cms.filters.AbstractMgnlFilter
acceptsEncoding, acceptsGzipEncoding, addAndVerifyHeader, addBypass, addMapping, destroy, getBypasses, getDispatching, getMapping, getMappings, getName, headerContains, init, isEnabled, mapsTo, matches, matchesDispatching, setDispatching, setEnabled, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODEL_ATTRIBUTE_PREFIX

public static final java.lang.String MODEL_ATTRIBUTE_PREFIX

ACTION_RESULT_ATTRIBUTE_PREFIX

public static final java.lang.String ACTION_RESULT_ATTRIBUTE_PREFIX

DEFAULT_MODEL_EXECUTION_ATTRIBUTE_NAME

public static final java.lang.String DEFAULT_MODEL_EXECUTION_ATTRIBUTE_NAME
See Also:
Constant Field Values
Constructor Detail

ModelExecutionFilter

public ModelExecutionFilter()
Method Detail

setAttributeName

public void setAttributeName(java.lang.String attributeName)

doFilter

public void doFilter(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in class info.magnolia.cms.filters.AbstractMgnlFilter
Throws:
java.io.IOException
javax.servlet.ServletException

getAggregationStateSafely

protected static info.magnolia.cms.core.AggregationState getAggregationStateSafely()

getUuidOfParagraphToExecute

protected java.lang.String getUuidOfParagraphToExecute()

getContent

protected info.magnolia.cms.core.Content getContent(java.lang.String uuid)
                                             throws javax.servlet.ServletException
Returns the Content node for the supplied uuid. Never returns null.

Throws:
javax.servlet.ServletException

getParagraph

protected Paragraph getParagraph(info.magnolia.cms.core.Content content)
                          throws javax.servlet.ServletException
Returns the Paragraph for the supplied Content. Never returns null.

Throws:
javax.servlet.ServletException

getRenderingModelBasedRenderer

protected RenderingModelBasedRenderer getRenderingModelBasedRenderer(Paragraph paragraph)
                                                              throws javax.servlet.ServletException
Returns the ParagraphRenderer for the supplied Paragraph if it supports RenderingModel. Never returns null.

Throws:
java.lang.IllegalArgumentException - if there is no renderer registered for the paragraph
javax.servlet.ServletException - if the renderer does not support RenderingModel

handleActionResult

protected boolean handleActionResult(java.lang.String actionResult,
                                     javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response)
                              throws java.io.IOException,
                                     javax.servlet.ServletException
Returns true if special handling was performed.

Throws:
java.io.IOException
javax.servlet.ServletException


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.