Example usage for org.apache.commons.jelly XMLOutput createXMLOutput

List of usage examples for org.apache.commons.jelly XMLOutput createXMLOutput

Introduction

In this page you can find the example usage for org.apache.commons.jelly XMLOutput createXMLOutput.

Prototype

protected static XMLOutput createXMLOutput(final XMLWriter xmlWriter) 

Source Link

Document

Factory method to create a new XMLOutput from an XMLWriter

Usage

From source file:com.hp.test.framework.runner.Runallthetests.java

@Test(enabled = true, dataProvider = "getjellyFiles")
public void test(String parm1, Object parm2) throws Exception {
    // ckw.compar_kywords(parm1);
    context.runScript(new InputSource(new FileInputStream(parm1)),
            XMLOutput.createXMLOutput(new StringWriter()));

}

From source file:hudson.util.HyperlinkingOutTagTest.java

private void assertOutput(String in, String out) throws Exception {
    StringWriter w = new StringWriter();
    XMLOutput xmlo = XMLOutput.createXMLOutput(w);
    HyperlinkingOutTag tag = new HyperlinkingOutTag();
    tag.setValue(new ConstantExpression(in));
    tag.doTag(xmlo);/*www. j  ava2 s .  c  o m*/
    assertEquals(out, w.toString());
}

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

/**
 * Override method render in super class of JellyPageRenderer
 * //ww w .  j av a 2s.  c  om
 * @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:hudson.Functions.java

/**
 * Evaluate a Jelly script and return output as a String.
 *
 * @since 1.267//from   w  ww.j  a va2 s. com
 */
public static String runScript(Script script) throws JellyTagException {
    StringWriter out = new StringWriter();
    script.run(getCurrentJellyContext(), XMLOutput.createXMLOutput(out));
    return out.toString();
}

From source file:org.apache.commons.jelly.demos.HomepageBuilder.java

public void buildPage(String template, JellyContext ctx) {

    //        try {
    ////www  .  ja v  a2s.c om
    //        Embedded embedded = new Embedded();
    //        embedded.setOutputStream(new FileOutputStream("out.html"));
    //        //embedded.setVariable("some-var","some-object");
    //
    //        embedded.setScript("file:///anoncvs/jakarta-commons-sandbox/jelly/sample.jelly");
    //        //or one can do.
    //        //embedded.setScript(scriptAsInputStream);
    //
    //        boolean bStatus=embedded.execute();
    //        if(!bStatus) //if error
    //        {
    //        System.out.println(embedded.getErrorMsg());
    //        }
    //
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        }

    try {

        OutputStream output = new FileOutputStream("demopage.html");

        JellyContext context = new JellyContext();
        context.setVariable("name", nameField.getText());
        context.setVariable("background", colorField.getText());
        context.setVariable("url", urlField.getText());

        Vector v = new Vector();
        Enumeration items = listModel.elements();
        while (items.hasMoreElements()) {
            v.add(items.nextElement());
        }
        context.setVariable("hobbies", v);

        XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
        context.runScript(resolveURL("src/test/org/apache/commons/jelly/demos/" + template), xmlOutput);
        xmlOutput.flush();
        System.out.println("Finished merging template");

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.codehaus.mojo.AbstractJellyMojo.java

/**
 * Execute the .jelly script associated with the concrete class
 *///from  w  w w  .  j  av  a2 s .c  o  m
public void execute() throws MojoExecutionException {
    try {
        final String scriptName = this.getClass().getSimpleName() + ".jelly";
        if (scriptName == null || scriptName.equals(""))
            throw new MojoExecutionException("script name unspecified");
        URL fileName = this.getClass().getResource(scriptName);
        if (fileName == null)
            throw new MojoExecutionException(scriptName + " not found");

        setParams();

        // add plugin's parameters to the groovy context
        JellyContext context = new JellyContext();
        if (params != null) {
            Iterator i = params.keySet().iterator();
            while (i.hasNext()) {
                String key = (String) i.next();
                context.setVariable(key, params.get(key));
            }
        }

        XMLOutput xmlOutput = XMLOutput.createXMLOutput(System.out);
        context.runScript(fileName, xmlOutput);
        xmlOutput.flush();
    } catch (Exception e) {
        throw new MojoExecutionException("Mojo error occurred:", e);
    }
}

From source file:org.codehaus.nanning.definition.AspectRepository.java

/**
 * Merges all defined aspect-repositories of the xml-file into this one, at least one needs to be defined.
 *
 * @param resource/*from   w  w w  .  j a v  a2 s.com*/
 * @throws org.codehaus.nanning.definition.ConfigureException
 */
public void configure(URL resource) throws ConfigureException {
    JellyContext context = new JellyContext();
    try {
        context.registerTagLibrary(AspectTagLibrary.TAG_LIBRARY_URI, new AspectTagLibrary());
        context.registerTagLibrary("", new AspectTagLibrary());
        XMLOutput xmlOutput = XMLOutput.createXMLOutput(new ByteArrayOutputStream());
        context.runScript(resource, xmlOutput);
    } catch (Exception e) {
        throw new ConfigureException(e);
    }

    Collection aspectRepositories = AspectTagLibrary.findDefinedRepositories(context);
    Iterator iterator = aspectRepositories.iterator();
    if (!iterator.hasNext()) {
        throw new ConfigureException("No aspect-repository defined.");
    }
    while (iterator.hasNext()) {
        AspectRepository configuredRepository = (AspectRepository) iterator.next();
        this.interceptorDefinitions.putAll(configuredRepository.interceptorDefinitions);
        this.aspectClasses.putAll(configuredRepository.aspectClasses);
        this.aspectDefinitions.putAll(configuredRepository.aspectDefinitions);
    }
}

From source file:org.jenkins.ci.plugins.JobPollAction.java

public HttpResponse doLog(StaplerRequest req, StaplerResponse rsp) {
    HttpResponse result = new HttpResponse() {
        public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node)
                throws IOException, ServletException {
            SCMAction scmAction = target.getAction(SCMAction.class);
            if (scmAction != null) {
                try {
                    XMLOutput xmlOutput = XMLOutput.createXMLOutput(rsp.getWriter());
                    scmAction.writeLogTo(xmlOutput);
                } catch (IOException e) {
                }/* w ww. ja v  a 2s.  c om*/
            }

        }
    };

    return result;
}