org.apache.struts2.portlet.result
Class PortletVelocityResult

java.lang.Object
  extended by org.apache.struts2.dispatcher.StrutsResultSupport
      extended by org.apache.struts2.portlet.result.PortletVelocityResult
All Implemented Interfaces:
Result, java.io.Serializable, StrutsStatics

public class PortletVelocityResult
extends StrutsResultSupport

Using the Servlet container's JspFactory, this result mocks a JSP execution environment and then displays a Velocity template that will be streamed directly to the servlet output.

This result type takes the following parameters:

This result follows the same rules from StrutsResultSupport.

Example:
 <!-- START SNIPPET: example -->
  <result name="success" type="velocity">
    <param name="location">foo.vm</param>
  </result>
  <!-- END SNIPPET: example -->
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
DEFAULT_PARAM
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
 
Constructor Summary
PortletVelocityResult()
           
PortletVelocityResult(java.lang.String location)
           
 
Method Summary
protected  org.apache.velocity.context.Context createContext(VelocityManager velocityManager, ValueStack stack, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String location)
          Creates the VelocityContext that we'll use to render this page.
 void doExecute(java.lang.String location, ActionInvocation invocation)
           
 void executeRenderResult(java.lang.String finalLocation, ActionInvocation invocation)
          Creates a Velocity context from the action, loads a Velocity template and executes the template.
protected  java.lang.String getContentType(java.lang.String templateLocation)
          Retrieve the content type for this template.
protected  java.lang.String getEncoding(java.lang.String templateLocation)
          Retrieve the encoding for this template.
protected  org.apache.velocity.Template getTemplate(ValueStack stack, org.apache.velocity.app.VelocityEngine velocity, ActionInvocation invocation, java.lang.String location, java.lang.String encoding)
          Given a value stack, a Velocity engine, and an action invocation, this method returns the appropriate Velocity template to render.
 void setDefaultEncoding(java.lang.String encoding)
           
 void setVelocityManager(VelocityManager mgr)
           
 
Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
conditionalParse, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortletVelocityResult

public PortletVelocityResult()

PortletVelocityResult

public PortletVelocityResult(java.lang.String location)
Method Detail

setVelocityManager

public void setVelocityManager(VelocityManager mgr)

setDefaultEncoding

public void setDefaultEncoding(java.lang.String encoding)

doExecute

public void doExecute(java.lang.String location,
                      ActionInvocation invocation)
               throws java.lang.Exception
Specified by:
doExecute in class StrutsResultSupport
Throws:
java.lang.Exception

executeRenderResult

public void executeRenderResult(java.lang.String finalLocation,
                                ActionInvocation invocation)
                         throws java.lang.Exception
Creates a Velocity context from the action, loads a Velocity template and executes the template. Output is written to the servlet output stream.

Parameters:
finalLocation - the location of the Velocity template
invocation - an encapsulation of the action execution state.
Throws:
java.lang.Exception - if an error occurs when creating the Velocity context, loading or executing the template or writing output to the servlet response stream.

getContentType

protected java.lang.String getContentType(java.lang.String templateLocation)
Retrieve the content type for this template.

People can override this method if they want to provide specific content types for specific templates (eg text/xml).

Returns:
The content type associated with this template (default "text/html")

getEncoding

protected java.lang.String getEncoding(java.lang.String templateLocation)
Retrieve the encoding for this template.

People can override this method if they want to provide specific encodings for specific templates.

Returns:
The encoding associated with this template (defaults to the value of 'struts.i18n.encoding' property)

getTemplate

protected org.apache.velocity.Template getTemplate(ValueStack stack,
                                                   org.apache.velocity.app.VelocityEngine velocity,
                                                   ActionInvocation invocation,
                                                   java.lang.String location,
                                                   java.lang.String encoding)
                                            throws java.lang.Exception
Given a value stack, a Velocity engine, and an action invocation, this method returns the appropriate Velocity template to render.

Parameters:
stack - the value stack to resolve the location again (when parse equals true)
velocity - the velocity engine to process the request against
invocation - an encapsulation of the action execution state.
location - the location of the template
encoding - the charset encoding of the template
Returns:
the template to render
Throws:
java.lang.Exception - when the requested template could not be found

createContext

protected org.apache.velocity.context.Context createContext(VelocityManager velocityManager,
                                                            ValueStack stack,
                                                            javax.servlet.http.HttpServletRequest request,
                                                            javax.servlet.http.HttpServletResponse response,
                                                            java.lang.String location)
Creates the VelocityContext that we'll use to render this page.

Parameters:
velocityManager - a reference to the velocityManager to use
stack - the value stack to resolve the location against (when parse equals true)
location - the name of the template that is being used
Returns:
the a minted Velocity context.


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.