You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Raphaël Piéroni <ra...@yahoo.fr> on 2003/03/06 10:02:14 UTC

[Jelly] jelly script in an Object's String attribute

Hello everybody, 
I'm currently trying to understand how to use jelly but, 
it seems that we can not use a script stored as a string attribute of
an object.

i have a plentyfull of objects that will have to execute a jelly script
that is not stored a a file but a an attribute of the executing object.

i have found that to run a script you have to know the URI where the
script is, but i don't know how to make the URI going to an
instanciated object. (i may, but it's not a good design for me store
the scripts in a jar file, but i still don't know how to create a good
URI)

in advance, thanks for any piece of advice.

Raphaël Piéroni


=====
------------------------------------
| Raphaël Piéroni                  |
| 33+ 223 351 354                  |
| mailto:rpieroni@dexem.com        |
| http://www.dexem.com             |
| mailing:raphael_mailing@yahoo.fr |
------------------------------------

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

Re: [Jelly] jelly script in an Object's String attribute / FROM user list

Posted by Raphaël Piéroni <ra...@yahoo.fr>.
Hello list

it is working (on a little test).

in attached files JellyContext.java (with the two methods written at
start of the class) and a test case (the script is the same as
test_args.jelly)

I may have made mistakes using the context. so feel free to change all
that don't fill the style guide.

Raphaël

=====
------------------------------------
| Raphaël Piéroni                  |
| 33+ 223 351 354                  |
| mailto:rpieroni@dexem.com        |
| http://www.dexem.com             |
| mailing:raphael_mailing@yahoo.fr |
------------------------------------

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

[Jelly] jelly script in an Object's String attribute / FROM user list

Posted by Raphaël Piéroni <ra...@yahoo.fr>.
Hello everybody,
i have created 2 methods for JellyContext. 
but due to some personal agenda, i will not have access to a java
compiler for a little time.

i sent the methods (never compiled) with this mail, if someone is
interrested.

i will try to compile them this WE and test them

i will inform the list after.

the code :
import java.io.PipedOutputStream;
import java.io.PipedInputStream;
import java.io.OutputStreamWriter;

public JellyContext JellyContext.runStringScript(String stringScript,
XMLOutput output) {

    Script script = compileStringScript(stringScript);


    JellyContext newJellyContext = newJellyContext();
    //newJellyContext.setRootURL( newJellyContextURL );
    //newJellyContext.setCurrentURL( newJellyContextURL );
    newJellyContext.setExport( DEFAULT_EXPORT );
    newJellyContext.setInherit( DEFAULT_INHERIT );

 //   if ( inherit ) {
        // use the same variable scopes
    newJellyContext.variables = this.variables;
 //   }

    if (log.isDebugEnabled() ) {
        log.debug( "About to run script: " + url );
        log.debug( "root context URL: " + newJellyContext.rootURL );
        log.debug( "current context URL: " + newJellyContext.currentURL
);
    }

    script.run(newJellyContext, output);
    return newJellyContext;
}

public Script JelltContext.compileStringScript(String script) throws
JellyException {
    XMLParser parser = new XMLParser();
    parser.setContext(this);
    PipedOutputStream pos;
    InputStream in = new PipedInputStream(pos);
    OutputStreamWriter osw = new OutputStreamWriter(pos);
    osw.write(script, 0, script.length());

    if (in == null) {
        throw new JellyException("Could not find Jelly script: " +
script);
    }
    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);
    }

    return script.compile();
}



 --- Raphaël Piéroni <ra...@yahoo.fr> a écrit : > Hello
everybody, 
> I'm currently trying to understand how to use jelly but, 
> it seems that we can not use a script stored as a string attribute of
> an object.
> 
> i have a plentyfull of objects that will have to execute a jelly
> script
> that is not stored a a file but a an attribute of the executing
> object.
> 
> i have found that to run a script you have to know the URI where the
> script is, but i don't know how to make the URI going to an
> instanciated object. (i may, but it's not a good design for me store
> the scripts in a jar file, but i still don't know how to create a
> good
> URI)
> 
> in advance, thanks for any piece of advice.
> 
> Raphaël Piéroni
> 
> 
> =====
> ------------------------------------
> | Raphaël Piéroni                  |
> | 33+ 223 351 354                  |
> | mailto:rpieroni@dexem.com        |
> | http://www.dexem.com             |
> | mailing:raphael_mailing@yahoo.fr |
> ------------------------------------
> 
> ___________________________________________________________
> Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> Yahoo! Mail : http://fr.mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>  

=====
------------------------------------
| Raphaël Piéroni                  |
| 33+ 223 351 354                  |
| mailto:rpieroni@dexem.com        |
| http://www.dexem.com             |
| mailing:raphael_mailing@yahoo.fr |
------------------------------------

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

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