Package org.apache.commons.jelly

Examples of org.apache.commons.jelly.XMLOutput


        HttpServletRequest req,
        HttpServletResponse res)
        throws IOException, UnsupportedEncodingException, JellyException {

        ServletOutputStream output = res.getOutputStream();
        XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
        context.runScript(script, xmlOutput);
        xmlOutput.flush();
        xmlOutput.close();
        output.flush();
    }
View Full Code Here


            throw new JellyException("Script file " + scriptFile + " not found");
        }

        try {
            // extract the -o option for the output file to use
            final XMLOutput output = cmdLine.hasOption("o") ?
                    XMLOutput.createXMLOutput(new FileWriter(cmdLine.getOptionValue("o"))) :
                    XMLOutput.createXMLOutput(System.out);

            Jelly jelly = new Jelly();
            jelly.setScript(scriptFile);

            Script script = jelly.compileScript();

            // add the system properties and the command line arguments
            JellyContext context = jelly.getJellyContext();
            context.setVariable("args", args);
            context.setVariable("commandLine", cmdLine);
            script.run(context, output);

            // now lets wait for all threads to close
            Runtime.getRuntime().addShutdownHook(new Thread() {
                    public void run() {
                        try {
                            output.close();
                        }
                        catch (Exception e) {
                            // ignore errors
                        }
                    }
View Full Code Here

    /**
     * Writes the body fo this tag to the given Writer
     */
    protected void writeBody(Writer writer) throws SAXException, JellyTagException {

        XMLOutput newOutput = createXMLOutput(writer);
        try {
            // we need to avoid multiple start/end document events
            newOutput.setContentHandler(
                new SafeContentHandler(newOutput.getContentHandler())
            );
            newOutput.startDocument();
            invokeBody(newOutput);
            newOutput.endDocument();
        }
        finally {
            try { newOutput.close(); } catch (IOException e) {}
        }
    }
View Full Code Here

            ? new HTMLWriter(writer, format)
            : new XMLWriter(writer, format);

        xmlWriter.setEscapeText(isEscapeText());

        XMLOutput answer = new XMLOutput() {
            public void close() throws IOException {
                xmlWriter.close();
            }
        };
        answer.setContentHandler(xmlWriter);
        answer.setLexicalHandler(xmlWriter);
        return answer;
    }
View Full Code Here

    /**
     * Parses the body of this tag and returns the parsed document
     */
    protected void parseBody(XMLOutput output) throws JellyTagException {
        ContentHandler handler = getJellyParser();
        XMLOutput newOutput = new XMLOutput(handler);

        try {
            handler.startDocument();
            invokeBody(newOutput);
            handler.endDocument();
View Full Code Here

     * @param script is the URL to the script which should create a TestSuite
     * @return a newly created TestSuite
     */
    public static TestSuite createTestSuite(URL script) throws Exception {
        JellyContext context = new JellyContext(script);
        XMLOutput output = XMLOutput.createXMLOutput(System.out);
        context = context.runScript(script, output);
        TestSuite answer = (TestSuite) context.getVariable("org.apache.commons.jelly.junit.suite");
        if ( answer == null ) {
            log.warn( "Could not find a TestSuite created by Jelly for the script:" + script );
            // return an empty test suite
View Full Code Here

        setUpScript("outputBad.jelly");
        Script script = getJelly().compileScript();
       
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
       
        XMLOutput ouput = XMLOutput.createXMLOutput(bos);
       
        script.run(getJellyContext(),ouput);
        ouput.flush();
        assertEquals("<html></html>",bos.toString());
    }
View Full Code Here

    public void testOutputData() throws Exception {
        setUpScript("outputData.jelly");
        Script script = getJelly().compileScript();

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLOutput ouput = XMLOutput.createXMLOutput(bos);

        script.run(getJellyContext(),ouput);
        ouput.flush();
        assertEquals("[string]",bos.toString().trim());
  }
View Full Code Here

        StringWriter writer = new StringWriter();
        OutputFormat format = new OutputFormat();
        final XMLWriter xmlWriter = new XMLWriter(writer, format);
        xmlWriter.setEscapeText(false);

        XMLOutput output = new XMLOutput(xmlWriter, xmlWriter);

        String decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        String golden = "<!DOCTYPE foo [\n";
        golden += "  <!ELEMENT foo (#PCDATA)>\n";
        golden += "]><foo></foo>";

        output.startDocument();
        output.write(golden);
        output.endDocument();
        System.err.println("output was: '" + writer.toString() +"'");
        System.err.println("golden is : '" + golden +"'");
        assertEquals("output should contain the CDATA section",
                decl + golden, writer.toString());
    }
View Full Code Here

        StringWriter writer = new StringWriter();
        OutputFormat format = new OutputFormat();
        final XMLWriter xmlWriter = new HTMLWriter(writer, format);
        xmlWriter.setEscapeText(false);

        XMLOutput output = new XMLOutput(xmlWriter, xmlWriter);

        String golden = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
        golden += "<html>";

        output.startDocument();
        output.write(golden);
        output.endDocument();
        assertEquals("output should contain the namespaces", golden, writer.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jelly.XMLOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.