org.apache.velocity.runtime.resource.ContentResource Java Examples

The following examples show how to use org.apache.velocity.runtime.resource.ContentResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AliadaResourceFactory.java    From aliada-tool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a resource according with given data.
 * 
 * @param resourceName the resource name.
 * @param resourceType the resource kind.
 * @return The resource described by name and type.
 */
public static Resource getResource(final String resourceName, final int resourceType) {
    switch (resourceType) {
        case ResourceManager.RESOURCE_TEMPLATE:
            return new AliadaTemplate();
        case ResourceManager.RESOURCE_CONTENT:
            return new ContentResource();
        default:
        	throw new IllegalArgumentException("WARNIGN: Unknown resource type: " + resourceType);
    }
}
 
Example #2
Source File: TestVelocityView.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void setupContentResource(ResourceLoader loader, RuntimeInstance runtimeServices, String templateName, String fakeContent) {
    try {
        ContentResource resource = new ContentResource();
        resource.setRuntimeServices(runtimeServices);
        resource.setResourceLoader(loader);
        resource.setName(templateName);
        resource.setData(fakeContent);

        doReturn(resource).when(runtimeServices).getContent(templateName);
        doReturn(resource).when(runtimeServices).getContent(eq(templateName), any(String.class));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: RuntimeInstance.java    From velocity-engine with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.  Uses the current value
 * if INPUT_ENCODING as the character encoding.
 *
 * @param name Name of content resource to get
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException When the template could not be parsed.
 */
public ContentResource getContent(String name)
    throws ResourceNotFoundException, ParseErrorException
{
    /*
     *  the encoding is irrelvant as we don't do any converstion
     *  the bytestream should be dumped to the output stream
     */

    return getContent(name, getDefaultEncoding());
}
 
Example #4
Source File: RuntimeInstance.java    From velocity-engine with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.
 *
 * @param name Name of content resource to get
 * @param encoding Character encoding to use
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException When the template could not be parsed.
 */
public ContentResource getContent(String name, String encoding)
    throws ResourceNotFoundException, ParseErrorException
{
    requireInitialization();

    return (ContentResource)
            resourceManager.getResource(name,
                    ResourceManager.RESOURCE_CONTENT, encoding);
}
 
Example #5
Source File: RuntimeSingleton.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.  Uses the current value
 * if INPUT_ENCODING as the character encoding.
 *
 * @param name Name of content resource to get
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException When the template could not be parsed.
 * @see RuntimeInstance#getContent(String)
 */
public static ContentResource getContent(String name)
    throws ResourceNotFoundException, ParseErrorException
{
    return ri.getContent(name);
}
 
Example #6
Source File: RuntimeSingleton.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.
 *
 * @param name Name of content resource to get
 * @param encoding Character encoding to use
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException When the template could not be parsed.
 * @see RuntimeInstance#getContent(String, String)
 */
public static ContentResource getContent( String name, String encoding )
    throws ResourceNotFoundException, ParseErrorException
{
    return ri.getContent(name, encoding);
}
 
Example #7
Source File: RuntimeServices.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.  Uses the current value
 * if INPUT_ENCODING as the character encoding.
 *
 * @param name Name of content resource to get
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException
 */
ContentResource getContent(String name)
    throws ResourceNotFoundException, ParseErrorException;
 
Example #8
Source File: RuntimeServices.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a static content resource from the
 * resource manager.
 *
 * @param name Name of content resource to get
 * @param encoding Character encoding to use
 * @return parsed ContentResource object ready for use
 * @throws ResourceNotFoundException if template not found
 *          from any available source.
 * @throws ParseErrorException
 */
ContentResource getContent(String name, String encoding)
    throws ResourceNotFoundException, ParseErrorException;