Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-726

Add StringResourceLoader

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.2
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None

      Description

      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)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              festerwim Wim Deblauwe
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: