Package com.bc.ceres.resource
Class ResourceEngine
java.lang.Object
com.bc.ceres.resource.ResourceEngine
An engine to transform resources using a
VelocityEngine
.
Resources given to this engine are processed and added to the embedded
VelocityContext
. For the evaluation the current VelocityContext
and its content is used.
Resources can be retrieved afterwards.
- Since:
- Ceres 0.13.2
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a resource engine.ResourceEngine
(org.apache.velocity.app.VelocityEngine velocityEngine) Create a resource engine using the given velocity engine. -
Method Summary
Modifier and TypeMethodDescriptiongetResource
(String name) Retrieves a resource registered under the given name in theVelocityContext
.org.apache.velocity.VelocityContext
Return the used velocity context.processAndAddResource
(String name, Resource resource) Evaluates the givenResource
using the currentVelocityContext
and adds the result of this processing to theVelocityContext
under given name.processResource
(Resource resource) Evaluates the givenResource
using the currentVelocityContext
and return the result.
-
Constructor Details
-
ResourceEngine
public ResourceEngine()Create a resource engine. -
ResourceEngine
public ResourceEngine(org.apache.velocity.app.VelocityEngine velocityEngine) Create a resource engine using the given velocity engine.- Parameters:
velocityEngine
- A velocity engine
-
-
Method Details
-
getVelocityContext
public org.apache.velocity.VelocityContext getVelocityContext()Return the used velocity context.- Returns:
- the velocity context.
-
processResource
Evaluates the givenResource
using the currentVelocityContext
and return the result.- Parameters:
resource
- the resource- Returns:
- The result of the processing
-
processAndAddResource
Evaluates the givenResource
using the currentVelocityContext
and adds the result of this processing to theVelocityContext
under given name.The evaluated
Resource
is returned.- Parameters:
name
- The name under which the resource is addedresource
- the resource- Returns:
- The result of the processing
-
getResource
Retrieves a resource registered under the given name in theVelocityContext
. If no resource is registered under the given name aIllegalArgumentException
is thrown.- Parameters:
name
- The name of the resource- Returns:
- The registered resource
- Throws:
IllegalArgumentException
- If no resource of the given name exists.
-