Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.kohsuke.stapler.jelly.jruby;
 
 import  org.apache.commons.jelly.JellyContext;
 import  org.apache.commons.jelly.JellyException;
 import  org.apache.commons.jelly.JellyTagException;
 import  org.apache.commons.jelly.Script;
 import  org.apache.commons.jelly.TagLibrary;
 import  org.apache.commons.jelly.XMLOutput;
 import  org.apache.commons.jelly.expression.ConstantExpression;
import  org.apache.commons.jelly.impl.TagScript;
Exposes ERb/Haml scripts as Script.

This abstract class defines the Java half of it, and it is further subtyped in Ruby for different languages.

Author(s):
Kohsuke Kawaguchi
public abstract class JRubyJellyScript implements Script {
    protected JRubyJellyScript() {
    }
    public Script compile() throws JellyException {
        return this;
    }
    // this method is implemented in Ruby
    public abstract void run(JellyContext context, XMLOutput outputthrows JellyTagException;

    
Invokes other Jelly tag libaries.
    public void invokeTaglib(final IJRubyContext rcon, JellyContext context, XMLOutput outputString uriString localNameMap<RubySymbol,?> attributesfinal RubyProc procthrows JellyException {
        TagScript tagScript = createTagScript(contexturilocalName);
        if (attributes!=null) {
            for (Entry<RubySymbol, ?> e : attributes.entrySet()) {
                tagScript.addAttribute(e.getKey().asJavaString(), new ConstantExpression(e.getValue()));
            }
        }
        
        if (proc!=null) {
            final Ruby runtime = ((IRubyObject)rcon).getRuntime();
            tagScript.setTagBody(new Script() {
                public Script compile() throws JellyException {
                    return this;
                }
                public void run(JellyContext context, XMLOutput outputthrows JellyTagException {
                    JellyContext oc = rcon.getJellyContext();
                    XMLOutput oo = rcon.getOutput();
                    try {
                        rcon.setJellyContext(context);
                        rcon.setOutput(output);
                        proc.getBlock().yield(runtime.getCurrentContext(),null);
                    } finally {
                        rcon.setJellyContext(oc);
                        rcon.setOutput(oo);
                    }
                }
            });
        }
        tagScript.run(contextoutput);
    }
    private TagScript createTagScript(JellyContext contextString uriString namethrows JellyException {
        TagLibrary lib = context.getTagLibrary(uri);
        if (lib==null)
            throw new JellyException("Undefined tag library namespace URI: "+uri);
        TagScript tagScript = lib.createTagScript(namenull/*this parameter appears to be unused.*/);
        if (tagScript!=nullreturn tagScript;
        tagScript = lib.createTagScript(name.replace('_','-'), null);
        if (tagScript!=nullreturn tagScript;
        throw new JellyException(String.format("name '%s' not found for '%s'"nameuri));
    }
New to GrepCode? Check out our FAQ X