Example usage for org.apache.commons.jelly JellyContext setVariable

List of usage examples for org.apache.commons.jelly JellyContext setVariable

Introduction

In this page you can find the example usage for org.apache.commons.jelly JellyContext setVariable.

Prototype

public void setVariable(String name, Object value) 

Source Link

Document

Sets the value of the named variable

Usage

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

/**
 * Overwrite or implement method processTag()
 *
 * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput)
 *///from  w  w w.j  a  v  a  2s  .  c  om
protected void processTag(XMLOutput output) throws Exception {
    requireAttribute("action");
    FormTag formTag = (FormTag) findAncestorWithClass(FormTag.class);
    if (formTag != null) {
        formTag.addButtonTag(this);
    }
    if (!FormTag.isControlsHidden(getContext())) {
        JellyContext jc = new JellyContext(getContext());
        jc.setVariable("submit", this);
        getBody().run(jc, output);
    }
}

From source file:com.groupon.jenkins.buildsetup.GithubRepoAction.java

public String getHtml(ProjectConfigInfo projectConfigInfo)
        throws IOException, ClassNotFoundException, JellyException {
    String name = getClass().getName().replace('.', '/').replace('$', '/') + "/" + "index.jelly";
    URL actionTemplate = getClass().getClassLoader().getResource(name);
    JellyContext context = new JellyContext();
    context.setVariable("p", projectConfigInfo);
    context.setVariable("it", this);
    OutputStream outputStream = new ByteArrayOutputStream();
    XMLOutput output = XMLOutput.createXMLOutput(outputStream);
    context.runScript(actionTemplate, output);
    output.flush();//from  ww  w  . ja  v  a2s  . com
    return "<p>" + outputStream.toString() + " </p>";
}

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)
 *//*ww  w.j  a v  a  2  s  . c  om*/
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.JellyPanel.java

/**
 * Override or implement method of parent class or interface
 *
 * @see com.cyclopsgroup.waterview.spi.Panel#render(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.spi.View[])
 *//*from   w  w  w  . j a  v a2  s  . c  o m*/
public void render(RuntimeData data, View[] views) throws Exception {
    JellyEngine je = (JellyEngine) data.getServiceManager().lookup(JellyEngine.ROLE);
    JellyContext jc = je.createJellyContext(data.getRequestContext());
    jc.setVariable(VIEWS_NAME, views);

    runModule(data, new JellyContextAdapter(jc));

    try {
        XMLOutput output = XMLOutput.createXMLOutput(data.getOutput());
        script.run(jc, output);
        output.flush();
    } catch (Exception e) {
        data.getOutput().println("<pre>");
        e.printStackTrace(data.getOutput());
        data.getOutput().println("</pre>");
    } finally {
        data.getOutput().flush();
    }
}

From source file:com.cloudbees.hudson.plugins.folder.FolderIcon.java

protected String iconClassNameImageOf(String size) {
    String iconClassName = getIconClassName();
    if (StringUtils.isNotBlank(iconClassName)) {
        String spec = null;/*  ww w  .j a  v a  2s.  c o m*/
        if ("16x16".equals(size)) {
            spec = "icon-sm";
        } else if ("24x24".equals(size)) {
            spec = "icon-md";
        } else if ("32x32".equals(size)) {
            spec = "icon-lg";
        } else if ("48x48".equals(size)) {
            spec = "icon-xlg";
        }
        if (spec != null) {
            Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " " + spec);
            if (icon != null) {
                JellyContext ctx = new JellyContext();
                ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
                return icon.getQualifiedUrl(ctx);
            }
        }
    }
    return null;
}

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

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

    invokeBody(XMLOutput.createDummyXMLOutput());
    JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE);
    Script s = je.getScript(getScript());

    if (tableTag == null) {
        throw new JellyException("One table must be defined");
    }

    if (data == null) {
        throw new JellyException("Tabular data must be included");
    }

    JellyContext jc = new JellyContext(getContext());
    jc.setVariable("tableTag", tableTag);
    jc.setVariable("table", tableTag.getTable());
    jc.setVariable("tabularData", getData());
    s.run(jc, output);
}

From source file:com.cyclopsgroup.waterview.richweb.taglib.TreeTag.java

/**
 * Override or implement method of parent class or interface
 *
 * @see com.cyclopsgroup.waterview.jelly.AbstractTag#doTag(org.apache.avalon.framework.service.ServiceManager, org.apache.commons.jelly.XMLOutput)
 *///  www.j  ava2  s. com
protected void doTag(ServiceManager serviceManager, XMLOutput output) throws Exception {
    requireAttribute("tree");
    requireAttribute("instance");
    invokeBody(output);
    if (treeScript == null || nodeVar == null) {
        throw new JellyTagException("A TreeScript tag must be defined in Tree tag");
    }

    JellyContext jc = new JellyContext(getContext());
    jc.setVariable(RuntimeTree.NAME, getInstance());
    jc.setVariable(nodeVar, getInstance().createRuntimeNode(tree.getRootNode()));
    treeScript.run(jc, output);
}

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

/**
 * Render tag content/*from  w ww .j  av a 2s.  c  o  m*/
 *
 * @param node Node to render
 * @param output XMLOutput
 * @param jc JellyContext
 * @throws JellyTagException Throw it out
 */
public void renderTag(RuntimeTreeNode node, JellyContext jc, XMLOutput output) throws JellyTagException {
    jc.setVariable(getVar(), runtime ? node : node.getContent());
    jc.setVariable(CURRENT_RUNTIME_NODE, node);
    jc.setVariable(TREE_TAG, this);

    getBody().run(jc, output);
}

From source file:com.cyclopsgroup.waterview.navigator.impl.DefaultNavigatorHome.java

/**
 * Overwrite or implement method in DefaultNavigatorHome
 *
 * @see org.apache.avalon.framework.activity.Initializable#initialize()
 *///  w w  w.j  av a 2 s  .co m
public void initialize() throws Exception {
    pathIndex = new Hashtable();
    parentPathIndex = new MultiHashMap();
    pageIndex = new Hashtable();

    rootNode = new DefaultNavigatorNode(this, "/", null);
    rootNode.getAttributes().set(DefaultNavigatorNode.PAGE_NAME, "/Index.jelly");
    rootNode.getAttributes().set(DefaultNavigatorNode.TITLE_NAME, "Start");
    addNode(rootNode);

    JellyContext jc = new JellyContext();
    jc.setVariable(getClass().getName(), this);
    jc.registerTagLibrary("http://waterview.cyclopsgroup.com/navigator", new NavigatorTagLibrary());
    for (Enumeration en = getClass().getClassLoader()
            .getResources("META-INF/cyclopsgroup/waterview-navigation.xml"); en.hasMoreElements();) {
        URL resource = (URL) en.nextElement();
        getLogger().info("Reading navigation from " + resource);
        jc.runScript(resource, XMLOutput.createDummyXMLOutput());
    }
    populateNode(rootNode);
}

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

/**
 * Test do tag/*from   w w  w .  j  av a 2s. c o m*/
 *
 * @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));
}