You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Nathan Bubna (JIRA)" <de...@velocity.apache.org> on 2009/06/11 16:19:07 UTC

[jira] Resolved: (VELOCITY-726) Add StringResourceLoader

     [ https://issues.apache.org/jira/browse/VELOCITY-726?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-726.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.6

We already have a StringResourceLoader:  

org.apache.velocity.runtime.resource.loader. StringResourceLoader

> Add StringResourceLoader
> ------------------------
>
>                 Key: VELOCITY-726
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-726
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.6.2
>            Reporter: Wim Deblauwe
>             Fix For: 1.6
>
>
> I would like to see an implementation of ResourceLoader that where you can pass a literal String, and that is the template. Something like this:
> public class StringResourceLoader extends ResourceLoader
> {
> 	@Override
> 	public void init( ExtendedProperties extendedProperties )
> 	{
> 	}
> 	@Override
> 	public InputStream getResourceStream( String s ) throws ResourceNotFoundException
> 	{
> 		return new ByteArrayInputStream( s.getBytes() );
> 	}
> 	@Override
> 	public boolean isSourceModified( Resource resource )
> 	{
> 		return true;
> 	}
> 	@Override
> 	public long getLastModified( Resource resource )
> 	{
> 		return 0;
> 	}
> }
> I tested this and it works, but I am assuming this could be handy for others as well.
> On a side note. Why do you have all this ResourceLoaders and their configuration? Would it not be easier to just create a getTemplate( InputStream ) method, then people can get the inputstream from whereever they want? I had now go through quite some hoops with classloading because I need to use Velocity from a plugin into another system. (For those also struggeling with this, you need to call:
> Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
> before you create your VelocityContext, and use the ClasspathResourceLoader)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org