Example usage for org.apache.commons.jelly Jelly compileScript

List of usage examples for org.apache.commons.jelly Jelly compileScript

Introduction

In this page you can find the example usage for org.apache.commons.jelly Jelly compileScript.

Prototype

public Script compileScript() throws JellyException 

Source Link

Document

Compiles the script

Usage

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

public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath,
        FilePath generatedFilePath) {/*w w  w .j  a va  2 s. c o  m*/
    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:org.sapia.soto.state.cocoon.view.JellyView.java

/**
 * @param uri/*from   w w  w .j a  v a2  s . c om*/
 *          the URI to a Jelly script.
 * @throws IOException
 * @throws Exception
 */
public void setSrc(String uri) throws IOException, Exception {
    _uri = uri;

    ResourceHandler handler = (ResourceHandler) env().getResourceHandlerFor(Utils.chopScheme(uri));
    _res = handler.getResourceObject(uri);

    Jelly j = new Jelly();
    _lastModified = _res.lastModified();
    j.setUrl(new URL(_res.getURI()));
    _jelly = j.compileScript();
}

From source file:org.sapia.soto.state.cocoon.view.JellyView.java

private synchronized void reload() throws Exception {
    if (_res.lastModified() != _lastModified) {
        Jelly j = new Jelly();
        j.setUrl(new URL(_res.getURI()));
        _jelly = j.compileScript();
    }/*  ww  w  .  j  a  va2  s. c o  m*/

    _lastModified = _res.lastModified();
}