> > Could this example be more generic? For instance, context could be
> > read from a flat properties file.
> >  
> 
> I think you meant the javax.script.ScriptContext used in this code
> which can be get from ScriptEngine. This cannot obtain from a
> properties file. Because this is how JSR 223 API is expected to
> behave. And once you obtain the context from the engine you can
> modify it by adding attributes, writers, readers and removing them.

No, sorry, I meant the Velocity context. For instance, if I have a flat
file that contains
  foo = bar
this would typically call velocityScriptEngine.put("foo","bar"). 

> >> Also, concerning ScriptEngine.eval(String): the String argument
> >> should be the content of the script itself, not the filename of
> >> the script.
> >>
> >> This can be done I think. I will do the necessary changes and
> >> commit when
> > all tests get passed.
> >
> 
> One question. This has fixed (I have the patch but not comited yet)
> except for the velocity tooling related scenario .Suppose we pass a
> script of the .vm file to engine.
> But internally how to obtain the template.
> (velocityEngine.getTemplate(String)) . This method should provide the
> template name(assuming script is in the classspath).
> How do we deal with this when we provide the script itself ?
> 

By use of the appropriate velocityEngine.evaluate() method that takes
the template as a String. It will bypass Velocity's internal cache, but
our first goal is to respect the API, then to try to optimize.

Speaking about it, since the engine has access to the filename, we
could try to still use the cache. Velocity's cache is here to not
only bypass the actual reading of the file, but also the parsing
process - and since the OS will already cache the file in memory,
it's the parsing of the template which is the most interesting to
avoid via the caching mechanism. Here, we're given the content of the
file at the same time as its name (via the special property
"javax.script.filename"). So we can still do some caching, by just
ignoring the newly provided content when the filename is present in the
cache.

For this to work properly, we may have to implement our own
Velocity ResourceLoader.

Did you follow my idea, Dishara? Are you ok with it?


  Claude



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

Reply via email to