portal.core.render
Interface IVelocityPageContext


public interface IVelocityPageContext

An object instance implementing this interface is available to a velocity template layout as $context. Note that none of the methods throws a checked exception. This is to avoid the often very long and meaningless stacktraces thrown by the velocity engine. Each method will however log any errors, warnings and exceptions.

Since:
0.9
Author:
bavodr

Method Summary
 Component getComponent()
          Retrieve the component being rendered with tis velocity template.
 java.lang.String getDownloadURL(java.lang.String resourceName, java.lang.String filename)
          Query the resource service for the named resource.
 java.lang.String getResourceURL(java.lang.String resourceName)
          Query the resource service for the named resource.
 boolean hasChild(java.lang.String componentName)
          Check if a child with the given name is available.
 void includeChild(java.lang.String componentName)
          Search for a component in this container with the given name.
 void paneInclude(java.lang.String componentName)
          Deprecated. see includeChild(String)
 

Method Detail

getComponent

public Component getComponent()

Retrieve the component being rendered with tis velocity template. The reference can then be used from within the template.

Returns:
the component that is being rendered with this velocity template

hasChild

public boolean hasChild(java.lang.String componentName)

Check if a child with the given name is available. This method can be used from within a velocity template layout for conditional inclusion of a child. It checks if the component rendered by this layout is a container and, when yes, if it contains the named child.

Parameters:
componentName - the name of the child component
Returns:
true when there is such a child, false otherwise

paneInclude

public void paneInclude(java.lang.String componentName)
Deprecated. see includeChild(String)

This method is identical to includeChild(String) and is kept for backward compatibility. Use of this method is deprecated and a warning will be logged on each invocation.

Parameters:
componentName - the name of the child component

includeChild

public void includeChild(java.lang.String componentName)

Search for a component in this container with the given name. When found include the rendering output of this component at the current location.

When the component being rendered is not a container or does not contain the named child, a warning will be logged and the rendering continues.

Parameters:
componentName - the name of the child component

getResourceURL

public java.lang.String getResourceURL(java.lang.String resourceName)

Query the resource service for the named resource. When found, it will register the resource with the render engine and return an url to retrieve the resource.

This can be used to include images or other resources in the html output without the need of instantiating an Image class for example.

Example:

<img src='$context.getResourceURL("image.png")'>

Returns:
the relative url that can be used to retrieve the contents of the resource

getDownloadURL

public java.lang.String getDownloadURL(java.lang.String resourceName,
                                       java.lang.String filename)

Query the resource service for the named resource. When found, it will register the resource with the render engine and return an url to retrieve the resource.

Some HTTP headers will be added so that the browser will present the user with a "Save As ..." dialog instead of showing the resource inline. Note that the browser can choose to implement this behavior differently.

Example:

<img src='$context.getDownloadURL("resources/graphics/image.png", "image.png)'>

Parameters:
resourceName - the name of the resource
filename - the suggested filename in the browsers Save As dialog
Returns:
the relative url that can be used to retrieve the contents of the resource