info.magnolia.rendering.renderer
Class AbstractRenderer

java.lang.Object
  extended by info.magnolia.rendering.renderer.AbstractRenderer
All Implemented Interfaces:
Renderer, RenderingModelBasedRenderer
Direct Known Subclasses:
FreemarkerRenderer, JspRenderer

public abstract class AbstractRenderer
extends Object
implements Renderer, RenderingModelBasedRenderer

Abstract renderer which can be used to implement paragraph or template renderers. Sets up the context by providing the following objects: content, aggregationState, page, model, actionResult, mgnl

Version:
$Id$

Field Summary
protected static String MODEL_ATTRIBUTE
           
 
Constructor Summary
AbstractRenderer()
           
 
Method Summary
protected  String determineTemplatePath(javax.jcr.Node content, RenderableDefinition definition, RenderingModel<?> model, String actionResult)
           
protected  info.magnolia.cms.core.AggregationState getAggregationStateSafely()
          This gets the aggregation state without throwing an exception if the current context is not a WebContext.
protected  javax.jcr.Node getMainContentSafely(javax.jcr.Node content)
          Gets the current main contain and treats the situation where the context is not a web context nicely by using the current content instead.
protected abstract  Map<String,Object> newContext()
          Create a new context object which is a map.
protected
<T extends RenderingModel<?>>
T
newModel(Class<T> modelClass, javax.jcr.Node content, RenderableDefinition definition, RenderingModel<?> parentModel)
           
 RenderingModel<?> newModel(javax.jcr.Node content, RenderableDefinition definition, RenderingModel<?> parentModel)
          Instantiates the model based on the class defined by the RenderableDefinition.getModelClass() property.
protected abstract  void onRender(javax.jcr.Node content, RenderableDefinition definition, RenderingContext renderingCtx, Map<String,Object> ctx, String templateScript)
          Finally execute the rendering.
 void render(RenderingContext renderingCtx, Map<String,Object> contextObjects)
          Called by RenderingEngine after it has setup the RenderingContext.
protected  void restoreContext(Map<String,Object> ctx, Map<String,Object> state)
           
protected  void saveAttribute(Map<String,Object> ctx, Map<String,Object> state, String name)
           
protected  Map<String,Object> saveContextState(Map<String,Object> ctx)
           
protected  Object setContextAttribute(Map<String,Object> ctx, String name, Object value)
           
protected  void setupContext(Map<String,Object> ctx, javax.jcr.Node content, RenderableDefinition definition, RenderingModel<?> model, Object actionResult)
           
protected  javax.jcr.Node wrapNodeForModel(javax.jcr.Node content, javax.jcr.Node mainContent)
          Wraps the current content node before passing it to the model.
protected  javax.jcr.Node wrapNodeForTemplate(javax.jcr.Node content, javax.jcr.Node mainContent)
          Wraps the current content node before exposing it to the template renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODEL_ATTRIBUTE

protected static final String MODEL_ATTRIBUTE
Constructor Detail

AbstractRenderer

public AbstractRenderer()
Method Detail

render

public void render(RenderingContext renderingCtx,
                   Map<String,Object> contextObjects)
            throws RenderException
Description copied from interface: Renderer
Called by RenderingEngine after it has setup the RenderingContext.

Specified by:
render in interface Renderer
Parameters:
renderingCtx - rendering context prepared by the caller
contextObjects - objects to expose to the template script
Throws:
RenderException

determineTemplatePath

protected String determineTemplatePath(javax.jcr.Node content,
                                       RenderableDefinition definition,
                                       RenderingModel<?> model,
                                       String actionResult)

newModel

public RenderingModel<?> newModel(javax.jcr.Node content,
                                  RenderableDefinition definition,
                                  RenderingModel<?> parentModel)
                           throws RenderException
Instantiates the model based on the class defined by the RenderableDefinition.getModelClass() property. All the request parameters are then mapped to the model's properties.

Specified by:
newModel in interface RenderingModelBasedRenderer
Throws:
RenderException

newModel

protected <T extends RenderingModel<?>> T newModel(Class<T> modelClass,
                                                   javax.jcr.Node content,
                                                   RenderableDefinition definition,
                                                   RenderingModel<?> parentModel)
                                        throws RenderException
Throws:
RenderException

saveContextState

protected Map<String,Object> saveContextState(Map<String,Object> ctx)

saveAttribute

protected void saveAttribute(Map<String,Object> ctx,
                             Map<String,Object> state,
                             String name)

restoreContext

protected void restoreContext(Map<String,Object> ctx,
                              Map<String,Object> state)

setupContext

protected void setupContext(Map<String,Object> ctx,
                            javax.jcr.Node content,
                            RenderableDefinition definition,
                            RenderingModel<?> model,
                            Object actionResult)

getMainContentSafely

protected javax.jcr.Node getMainContentSafely(javax.jcr.Node content)
Gets the current main contain and treats the situation where the context is not a web context nicely by using the current content instead.


getAggregationStateSafely

protected info.magnolia.cms.core.AggregationState getAggregationStateSafely()
This gets the aggregation state without throwing an exception if the current context is not a WebContext.


wrapNodeForModel

protected javax.jcr.Node wrapNodeForModel(javax.jcr.Node content,
                                          javax.jcr.Node mainContent)
Wraps the current content node before passing it to the model.

Parameters:
content - the actual content
mainContent - the current "main content" or "page", which might be needed in certain wrapping situations

wrapNodeForTemplate

protected javax.jcr.Node wrapNodeForTemplate(javax.jcr.Node content,
                                             javax.jcr.Node mainContent)
Wraps the current content node before exposing it to the template renderer.

Parameters:
content - the actual content being exposed to the template
mainContent - the current "main content" or "page", which might be needed in certain wrapping situations
See Also:
TODO : return an Object instance instead - more flexibility for the template engine ?

setContextAttribute

protected Object setContextAttribute(Map<String,Object> ctx,
                                     String name,
                                     Object value)

newContext

protected abstract Map<String,Object> newContext()
Create a new context object which is a map.


onRender

protected abstract void onRender(javax.jcr.Node content,
                                 RenderableDefinition definition,
                                 RenderingContext renderingCtx,
                                 Map<String,Object> ctx,
                                 String templateScript)
                          throws RenderException
Finally execute the rendering.

Throws:
RenderException


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