Example usage for org.apache.commons.jelly Script run

List of usage examples for org.apache.commons.jelly Script run

Introduction

In this page you can find the example usage for org.apache.commons.jelly Script run.

Prototype

public void run(JellyContext context, XMLOutput output) throws JellyTagException;

Source Link

Document

Evaluates the body of a tag

Usage

From source file:com.viltgroup.xcp.jenkins.maven.XcpMavenSettings.java

public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath,
        FilePath generatedFilePath) {/*  ww  w .  j  a v  a 2  s .  com*/
    XMLOutput output = null;
    try {
        // create directories if needed
        generatedFilePath.getParent().mkdirs();

        // prepare output writer
        output = XMLOutput.createXMLOutput(generatedFilePath.write());

        // load jelly template
        String templateLocation = String.format("/%s/template.jelly",
                XcpMavenSettings.class.getName().replace('.', '/'));
        URL templateURL = XcpMavenSettings.class.getResource(templateLocation);

        // generate settings.xml from template
        Jelly jelly = new Jelly();
        jelly.setUrl(templateURL);
        Script script = jelly.compileScript();
        // add xCP Designer path to the jelly context
        JellyContext context = new JellyContext();
        context.setVariable("workspacePath", OSPathHacks.processFilePath(workspacePath));
        context.setVariable("xcpDesignerPath", xcpDesignerPath);
        context.setVariable("xcpDesignerMavenPath",
                String.format("%s/maven", OSPathHacks.processFilePath(xcpDesignerPath)));
        context.setVariable("localRepositoryPath", OSPathHacks.processFilePath(localRepositoryPath));
        script.run(context, output);
        output.flush();
    } catch (IOException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (JellyTagException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (JellyException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (InterruptedException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } finally {
        if (output != null)
            try {
                output.close();
            } catch (IOException e) {
            }
    }
}

From source file:com.cyclopsgroup.waterview.jelly.taglib.BaseJellyControlTag.java

/**
 * Method to run script/*  w w  w  . j a  va2 s  .c o  m*/
 *
 * @param script Script to run
 * @param output XMLOutput
 * @throws Exception Throw it out
 */
protected void runScript(Script script, XMLOutput output) throws Exception {
    script.run(context, output);
}

From source file:com.cyclopsgroup.waterview.web.taglib.FormButtonTag.java

/**
 * Overwrite or implement method processTag()
 *
 * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput)
 *//*from  w  w w. ja  va  2  s  .co  m*/
protected void processTag(XMLOutput output) throws Exception {
    requireParent(SubmitTag.class);
    if (StringUtils.isEmpty(getTitle())) {
        setTitle(getBodyText());
    }
    JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE);
    Script script = je.getScript("/waterview/FormButton.jelly");
    getContext().setVariable("button", this);
    script.run(getContext(), output);
}

From source file:com.cyclopsgroup.waterview.web.taglib.FormImageTag.java

/**
 * Overwrite or implement method processTag()
 *
 * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput)
 *///from  w w w.  ja va2s  . com
protected void processTag(XMLOutput output) throws Exception {
    requireParent(SubmitTag.class);
    requireAttribute("url");
    JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE);
    Script script = je.getScript("/waterview/FormImage.jelly");
    getContext().setVariable("image", this);
    script.run(getContext(), output);
}

From source file:com.cyclopsgroup.waterview.jelly.DeterminePageValve.java

private Page loadPage(Script script) throws JellyTagException {
    JellyContext jc = new JellyContext(jelly.getGlobalContext());
    script.run(jc, XMLOutput.createDummyXMLOutput());
    return (Page) jc.getVariable(Page.NAME);
}

From source file:com.cyclopsgroup.waterview.jelly.valves.DeterminePageValve.java

private Page loadPage(Script script, JellyEngine jellyEngine) throws JellyTagException {
    JellyContext jc = new JellyContext(jellyEngine.getGlobalContext());
    script.run(jc, XMLOutput.createDummyXMLOutput());
    return (Page) jc.getVariable(Page.NAME);
}

From source file:hudson.Functions.java

/**
 * Evaluate a Jelly script and return output as a String.
 *
 * @since 1.267// w w  w. ja va2s. co m
 */
public static String runScript(Script script) throws JellyTagException {
    StringWriter out = new StringWriter();
    script.run(getCurrentJellyContext(), XMLOutput.createXMLOutput(out));
    return out.toString();
}

From source file:com.cyclopsgroup.waterview.web.taglib.JellyFormControlTag.java

/**
 * Overwrite or implement method processTag()
 *
 * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput)
 *//*from w  w  w .  ja  v a  2 s  . c  o m*/
protected void processTag(XMLOutput output) throws Exception {
    requireAttribute("script");
    invokeBody(XMLOutput.createDummyXMLOutput());

    if (formTag == null) {
        throw new JellyTagException("Form tag must be defined");
    }
    JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE);
    Script script = je.getScript(getScript());

    JellyContext jc = new JellyContext(getContext());
    jc.setVariable("formTag", formTag);
    jc.setVariable("form", formTag.getForm());

    script.run(jc, output);
}

From source file:com.cyclopsgroup.waterview.jelly.JellyPageRenderer.java

/**
 * Override method render in super class of JellyPageRenderer
 * /* ww  w  .j  a  v  a2  s  .  com*/
 * @see com.cyclopsgroup.waterview.PageRenderer#render(com.cyclopsgroup.cyclib.Context, java.lang.String, java.lang.String, com.cyclopsgroup.waterview.UIRuntime)
 */
public void render(Context context, String packageName, String module, UIRuntime runtime) throws Exception {
    XMLOutput jellyOutput = (XMLOutput) context.get("jellyOutput");
    if (jellyOutput == null) {
        jellyOutput = XMLOutput.createXMLOutput(runtime.getOutput());
        context.put("jellyOutput", jellyOutput);
    }

    JellyContext jc = new JellyContext(initialJellyContext);
    for (Iterator i = context.keys(); i.hasNext();) {
        String name = (String) i.next();
        jc.setVariable(name, context.get(name));
    }

    String scriptPath = getScriptPath(packageName, module);
    Script script = getScript(scriptPath);
    synchronized (script) {
        try {
            script.run(jc, jellyOutput);
            runtime.getOutput().flush();
        } catch (Exception e) {
            throw e;
        } finally {
            jc.getVariables().clear();
        }
    }
}

From source file:com.cyclopsgroup.waterview.richweb.fs.TreeTagTest.java

/**
 * Test do tag//from   www. jav  a  2s .c om
 *
 * @throws Exception Throw it out
 */
public void testDoTag() throws Exception {
    JellyEngine je = (JellyEngine) lookup(JellyEngine.ROLE);
    Script script = je.getScript("TestTreeScript.jelly");
    JellyContext jc = new JellyContext(je.getGlobalContext());
    File root = new File("src/java/test/com/cyclopsgroup/waterview/richweb");
    jc.setVariable("tree", new DirectoryTree(root));
    jc.setVariable("treeInstance", new RuntimeTree());
    jc.setVariable(FakePageRuntime.NAME, new FakePageRuntime(new PrintWriter(System.out)));
    script.run(jc, XMLOutput.createXMLOutput(System.out));
}