You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Daryl Stultz <da...@6degrees.com> on 2003/09/12 20:18:46 UTC

Jelly: run script from string

Hi folks, I'm trying to learn Jelly.

I'd like to execute a script from a raw string (perhaps it comes from a
database). How can I do this? It seems all the runScript methods take a
url or a file. 

Thanks.

Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] Jelly: run script from string

Posted by Daryl Stultz <da...@6degrees.com>.
"Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
>Here is what I just managed to compile and which, if you test it, Dary, 
Works just fine.

As far as the API goes I would prefer a method (in addition to yours) on
JellyContext runScript(inputStream,  xmlOutput);

Thanks for the help.

Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] Jelly: run script from string

Posted by Paul Libbrecht <pa...@activemath.org>.
dion@multitask.com.au wrote:
> Paul Libbrecht <pa...@ags.uni-sb.de> wrote on 16/09/2003 01:30:51 AM:
>>Not too sure how it was in beta 3. I would encourage you to check-out 
>>the latest version. It's pretty much un-moving these days.
> Cough, you mean all the commits I've done in the last week to get the 
> whole thing building mean nothing :-)

Oooops, way sorry! This was the case before last week!!
(not however that an update was compatible...)

> [snip]
> 
>>All in all, it gives the diff attached prodcued with:
>>"cvs diff src/java/org/apache/commons/jelly/JellyContext.java"
>>(would look forward to better instructions to make a "uni" diff)
> There was no attachment.

Oh, the list has eaten it. So it was a good idea to send this to Peter 
Royal directly...
It's committed as far as I can tell.

Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] Jelly: run script from string

Posted by di...@multitask.com.au.
Paul Libbrecht <pa...@ags.uni-sb.de> wrote on 16/09/2003 01:30:51 AM:

> Daryl,
> 
> Not too sure how it was in beta 3. I would encourage you to check-out 
> the latest version. It's pretty much un-moving these days.

Cough, you mean all the commits I've done in the last week to get the 
whole thing building mean nothing :-)

[snip]
> All in all, it gives the diff attached prodcued with:
> "cvs diff src/java/org/apache/commons/jelly/JellyContext.java"
> (would look forward to better instructions to make a "uni" diff)
> 
There was no attachment.
--
dIon Gillard, Multitask Consulting
Blog:      http://blogs.codehaus.org/people/dion/




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] Jelly: run script from string

Posted by Paul Libbrecht <pa...@ags.uni-sb.de>.
Daryl,

Not too sure how it was in beta 3. I would encourage you to check-out 
the latest version. It's pretty much un-moving these days.

Here is what I just managed to compile and which, if you test it, Dary, 
would feel perfect in the tree presumably (there's a few comitters on 
this list).
(ideally, a unit-test would be welcome).

On line 67 (or so), add import java.io.Reader;
(big deal)

On line 474, have added the following method:
     public Script compileScriptFromString(String scriptString)
		throws JellyException {
         XMLParser parser = getXMLParser();
         parser.setContext(this);
         Reader in = new java.io.StringReader(scriptString);
         Script script = null;
         try {
             script = parser.parse(in);
         } catch (IOException e) {
             throw new JellyException("Could not parse Jelly script",e);
         } catch (SAXException e) {
             throw new JellyException("Could not parse Jelly script",e);
         }
         try {in.close();} catch (IOException ex) {}
         return script.compile();
     }

which should be the one you need.

If people allow, I have also put try/catch around 
"System.getProperties()" put in the context-initialization... Will 
continue striving for applet runnability of commons things....
All in all, it gives the diff attached prodcued with:
"cvs diff src/java/org/apache/commons/jelly/JellyContext.java"
(would look forward to better instructions to make a "uni" diff)

Paul


On Lundi, sept 15, 2003, at 15:19 Europe/Paris, Daryl Stultz wrote:

> "Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
>> Why not use all things with "Characters" ? (i.e. a StringReader ? A
>> reader is also accepted for an InputSource).
>
> That's what I was looking for but I can't seem to find it. Can you 
> give me
> an example of it? I'm using Jelly 1.0 beta 3. Is it in this version? I
> can't imaging them not providing an InputStream or InputSource, but
> nonetheless I can't find it (in Jelly, JellyContext or Script).
>
> This is probably asking too much: is there a way to make use of an 
> already
> parsed stream and compile the script from that? IOW, a SOAP service has
> already parsed the XML. Can I get a hold of that and compile is as a 
> Jelly
> script? Just an optimization - not really necessary.
>
> Daryl Stultz


Re: Jelly: run script from string

Posted by Daryl Stultz <da...@6degrees.com>.
"Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
>Why not use all things with "Characters" ? (i.e. a StringReader ? A 
>reader is also accepted for an InputSource).

That's what I was looking for but I can't seem to find it. Can you give me
an example of it? I'm using Jelly 1.0 beta 3. Is it in this version? I
can't imaging them not providing an InputStream or InputSource, but
nonetheless I can't find it (in Jelly, JellyContext or Script).

This is probably asking too much: is there a way to make use of an already
parsed stream and compile the script from that? IOW, a SOAP service has
already parsed the XML. Can I get a hold of that and compile is as a Jelly
script? Just an optimization - not really necessary.

Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Jelly: run script from string

Posted by Paul Libbrecht <pa...@ags.uni-sb.de>.
On Lundi, sept 15, 2003, at 09:47 Europe/Paris, Sylvain Chambon wrote:

> On Fri, 12 Sep 2003 14:18:46 -0400, Daryl Stultz <da...@6degrees.com> 
> wrote:
>
>> I'd like to execute a script from a raw string (perhaps it comes from 
>> a
>> database). How can I do this? It seems all the runScript methods take 
>> a
>> url or a file.
>
> If there's an easy way I didn't find it... What I did was extend 
> JellyContext in order to have a compileScript method that can use a 
> String (which is fairly easy as what the parser really needs is an 
> InputStream -- give it a ByteArrayInputStream taken from your String's 
> bytes).

Why not use all things with "Characters" ? (i.e. a StringReader ? A 
reader is also accepted for an InputSource).

> Then you have a Script object which you can call the run(JellyContext, 
> XMLOutput) method on.
>
> I use this hack extensively (in a presentation framework that is made 
> of myriads of tiny scripts assembled together at runtime) and have 
> done for a few months now; it may not be the "cleanest" way to do it 
> but it works fine so far. The major problem would be keeping track of 
> changes to the Jelly APIs, in particular JellyContext and Script.

There hasn't been much changes since March so it might be good you 
submit the addition of the named method as a patch ?

Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Jelly: run script from string

Posted by Sylvain Chambon <sy...@kelua.com>.
On Fri, 12 Sep 2003 14:18:46 -0400, Daryl Stultz <da...@6degrees.com> 
wrote:

> I'd like to execute a script from a raw string (perhaps it comes from a
> database). How can I do this? It seems all the runScript methods take a
> url or a file.

If there's an easy way I didn't find it... What I did was extend 
JellyContext in order to have a compileScript method that can use a String 
(which is fairly easy as what the parser really needs is an InputStream -- 
give it a ByteArrayInputStream taken from your String's bytes).

Then you have a Script object which you can call the run(JellyContext, 
XMLOutput) method on.

I use this hack extensively (in a presentation framework that is made of 
myriads of tiny scripts assembled together at runtime) and have done for a 
few months now; it may not be the "cleanest" way to do it but it works fine 
so far. The major problem would be keeping track of changes to the Jelly 
APIs, in particular JellyContext and Script.

Sylvain.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Jelly: run script from string

Posted by di...@multitask.com.au.
I don't think there is an easy way.
--
dIon Gillard, Multitask Consulting
Blog:      http://blogs.codehaus.org/people/dion/


"Daryl Stultz" <da...@6degrees.com> wrote on 13/09/2003 04:18:46 AM:

> Hi folks, I'm trying to learn Jelly.
> 
> I'd like to execute a script from a raw string (perhaps it comes from a
> database). How can I do this? It seems all the runScript methods take a
> url or a file. 
> 
> Thanks.
> 
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org