Using WebMacro outside of a WebApplication

Danni Miller <[email protected]> Tue, 20 Sep 2005 08:56:01 -0700 (PDT)
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
I would like to use the expression handling of
WebMacro outside of typical WebMacro. I have been able
to use a StringMacro which evalutates out properly,
but I would also like to evalute a full expression
such as $val + $val1 When I evaluate such an
expression I get String substitutions. Is there any
way to do this with WebMacro 2.0. I am not sure what I
should use to have this functionality, or if those
classes are public. I have a sample below of what I am
trying to accomplish. 

By the way I have to say I love the ideas and
implementation of WebMacro. Thanks

import org.webmacro.engine.StringMacro;
import org.webmacro.engine.MacroAdapter;
import org.webmacro.engine.StringMacroAdapter;
import org.webmacro.Context;
import org.webmacro.Macro;


public class Test {

    public static void main(String[] args) {
        try {



            Context ctx = new Context();
            ctx.put("name", "David");
            ctx.put("val1", 1);
            ctx.put("val2", 155);

            Macro macro = null;

            macro = new StringMacro("$name");
            System.out.println( macro.evaluate( ctx));

            macro = new
StringMacro("$name.substring(0,2).length()");
            System.out.println( macro.evaluate( ctx));

            macro = new
StringMacro("$name.substring(0,2).length()+5");
            System.out.println( macro.evaluate( ctx));

            macro = new StringMacro("$val1 + $val2");
            System.out.println( macro.evaluate( ctx));

            macro = new StringMacroAdapter("$val1 +
156");
            System.out.println( macro.evaluate( ctx));

            macro = MacroAdapter.createMacro("$val1 +
$val2");
            System.out.println( macro.evaluate( ctx));





        } catch(Throwable t){
            t.printStackTrace();
        }


    }
}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php