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 with support for typical functionality such as setting context attributes and executing a rendering model. Sets up the context by providing the following objects:


Field Summary
protected static String MODEL_ATTRIBUTE
           
 
Constructor Summary
AbstractRenderer()
          Deprecated. since 5.0.2, use AbstractRenderer(RenderingEngine)
AbstractRenderer(RenderingEngine renderingEngine)
           
 
Method Summary
 void addContextAttribute(String name, ContextAttributeConfiguration contextAttributeConfiguration)
           
protected  info.magnolia.cms.core.AggregationState getAggregationStateSafely()
          This gets the aggregation state without throwing an exception if the current context is not a WebContext.
 Map<String,ContextAttributeConfiguration> getContextAttributes()
           
protected  javax.jcr.Node getMainContentSafely(javax.jcr.Node content)
          Gets the current main content or returns null if aggregation state is not set.
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  String resolveTemplateScript(javax.jcr.Node content, RenderableDefinition definition, RenderingModel<?> model, String actionResult)
          Hook-method to be overriden when required.
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)
           
 void setContextAttributes(Map<String,ContextAttributeConfiguration> contextAttributes)
           
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)
          Wraps the current content node before passing it to the model.
protected  javax.jcr.Node wrapNodeForTemplate(javax.jcr.Node content)
          Wraps the current content node for exposing it to the template script as a context attribute.
 
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()
Deprecated. since 5.0.2, use AbstractRenderer(RenderingEngine)


AbstractRenderer

@Inject
public AbstractRenderer(RenderingEngine renderingEngine)
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

resolveTemplateScript

protected String resolveTemplateScript(javax.jcr.Node content,
                                       RenderableDefinition definition,
                                       RenderingModel<?> model,
                                       String actionResult)
Hook-method to be overriden when required. Default implementation ignores all arguments except definition.

Parameters:
definition - reference templateScript is retrieved from
Returns:
the templateScript to use

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 content or returns null if aggregation state is not set.


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)
Wraps the current content node before passing it to the model.

Parameters:
content - the actual content
Returns:
the wrapped content

wrapNodeForTemplate

protected javax.jcr.Node wrapNodeForTemplate(javax.jcr.Node content)
Wraps the current content node for exposing it to the template script as a context attribute.

Parameters:
content - the actual content
Returns:
the wrapped content

setContextAttribute

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

getContextAttributes

public Map<String,ContextAttributeConfiguration> getContextAttributes()

setContextAttributes

public void setContextAttributes(Map<String,ContextAttributeConfiguration> contextAttributes)

addContextAttribute

public void addContextAttribute(String name,
                                ContextAttributeConfiguration contextAttributeConfiguration)

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-2014 Magnolia International Ltd.. All Rights Reserved.