You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Dishara Wijewardana <dd...@gmail.com> on 2012/06/07 21:38:17 UTC

Script statement that can be used to display a given String

Hi all,
In velocity if the foo is an already set String variable or String variable
that has a value
$foo will be the echo statement.

In JSR223 we have an option to getOutputStatement(String output). It should
return the script language specific echo statement syntax.

But after we implement this API, we can do this in this API
as context.getWriter().write(foo).
So if the context is inherits to the page (which is what happens in
general), can we also provide something like
${context.getWriter().write(foo)} ?
Or are we going to use the $foo  instead ?


-- 
Thanks
/Dishara

Re: Script statement that can be used to display a given String

Posted by Nathan Bubna <nb...@gmail.com>.
On Fri, Jun 8, 2012 at 2:36 AM, Claude Brisson <cl...@renegat.net> wrote:
>> I don't know if the script context itself is to be present in the
>> bindings (i.e. in the Velocity context). If so, we should name it
>> $scriptContext rather than $context, since we already use the later
>> for exposing a Velocity context to itself via the ContextTool.
>
> Update: I read in the specs that:
>
>  << In all cases, the ScriptContext used during a script execution must
>  be a value in the Engine Scope of the ScriptEngine whose key is the
>  String “context”. >>
>
> There are several other keys which are to be defined: argv, filename,
> engine, engine_version, language, language_version (all of which are
> optional, but could be useful).
>
> My proposal is to gather all those keys in a $script object (that is,
> to expose the Bindings in itself under the 'script' key). From what I
> read in the specs, we are free to prefix predefined keys with whatever
> we want.

+1

> The motivation is to:
>  - avoid potential naming collisions. The ContextTool, exposing the
>   Velocity context itself under the $context key, will not necessarily
>   be present, or can be under a different key, but better prevent than
>   cure.
>  - follow our current philosophy to gather properties in a control
>   object, as we already do for macros, loops, ...
>
>
>  Claude
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
> For additional commands, e-mail: dev-help@velocity.apache.org
>

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


Re: Script statement that can be used to display a given String

Posted by Claude Brisson <cl...@renegat.net>.
> I don't know if the script context itself is to be present in the
> bindings (i.e. in the Velocity context). If so, we should name it
> $scriptContext rather than $context, since we already use the later
> for exposing a Velocity context to itself via the ContextTool.

Update: I read in the specs that:

  << In all cases, the ScriptContext used during a script execution must
  be a value in the Engine Scope of the ScriptEngine whose key is the
  String “context”. >>

There are several other keys which are to be defined: argv, filename,
engine, engine_version, language, language_version (all of which are
optional, but could be useful).

My proposal is to gather all those keys in a $script object (that is,
to expose the Bindings in itself under the 'script' key). From what I
read in the specs, we are free to prefix predefined keys with whatever
we want.

The motivation is to:
 - avoid potential naming collisions. The ContextTool, exposing the
   Velocity context itself under the $context key, will not necessarily
   be present, or can be under a different key, but better prevent than
   cure.
 - follow our current philosophy to gather properties in a control
   object, as we already do for macros, loops, ...


  Claude

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


Re: Script statement that can be used to display a given String

Posted by Claude Brisson <cl...@renegat.net>.
On Fri, 8 Jun 2012 01:08:17 +0530
Dishara Wijewardana <dd...@gmail.com> wrote:

> Hi all,
> In velocity if the foo is an already set String variable or String
> variable that has a value
> $foo will be the echo statement.
> 
> In JSR223 we have an option to getOutputStatement(String output). It
> should return the script language specific echo statement syntax.

From what I read in the specs, getOutputStatement(String str) doesn't
have anything to do with variables, it's simply the way to echo the
content of the str string.

So apart from any escaping consideration, this method should simply
return str without any processing. And yes, we should also consider
escaping here. If the user wants to echo "$foo", we should echo
something like "#[[$foo]]#" (using the new unparsed content syntax).

> But after we implement this API, we can do this in this API
> as context.getWriter().write(foo).
> So if the context is inherits to the page (which is what happens in
> general), can we also provide something like
> ${context.getWriter().write(foo)} ?
> Or are we going to use the $foo  instead ?
> 

None of them, see above...

Be really careful when you talk about 'contexts', because they mean
different things in Velocity and in the JSR 223. I guess you're talking
about the JSR 223 context here.

About the terminology, my proposal is to always use the term "script
context" (and the ScriptContext corresponding variable name) when we
talk about JSR 223 contexts, and to use always use the term "velocity
context" for Velocity contexts.

I don't know if the script context itself is to be present in the
bindings (i.e. in the Velocity context). If so, we should name it
$scriptContext rather than $context, since we already use the later
for exposing a Velocity context to itself via the ContextTool.


  Claude

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