Package org.apache.commons.jelly.parser

Examples of org.apache.commons.jelly.parser.XMLParser


    {
        // FIXME: This should all be done by Jelly.
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware( true );
        XMLReader reader = factory.newSAXParser().getXMLReader();
        XMLParser parser = new XMLParser( reader );
        parser.setContext( context );
        parser.setClassLoader( context.getClassLoader() );

        Script script = null;

        InputSource source = null;
        if ( encoding != null )
        {
            InputStreamReader isr = null;
            try
            {
                isr = new InputStreamReader( scriptInputStream, encoding );
                source = new InputSource( isr );

            }
            finally
            {
                if ( isr != null )
                {
                    try
                    {
                        isr.close();
                    }
                    catch ( IOException e )
                    {
                        log.debug( "WARNING: Cannot close stream!", e );
                    }
                    isr = null;
                }
            }

        }
        else
        {
            source = new InputSource( scriptInputStream );
        }

        if ( systemId != null )
        {
            source.setSystemId( systemId );
        }
        if ( log.isDebugEnabled() )
            log.debug( "the system identifier to help resolve relative URLs : " + systemId );
        script = parser.parse( source );

        script = script.compile();

        return script;
    }
View Full Code Here


    /**
     * Factory method to create a new Jelly parser
     * @return XMLParser
     */
    protected XMLParser createJellyParser() {
        XMLParser answer = new XMLParser();
        answer.setContext(context);
        return answer;
    }
View Full Code Here

    }
   
       
    protected Document runScript(String fileName) throws Exception {
        InputStream in = new FileInputStream(fileName);
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        JellyContext context = parser.getContext();
       
        SAXContentHandler contentHandler = new SAXContentHandler();
        XMLOutput output = new XMLOutput( contentHandler );
       
        contentHandler.startDocument();
View Full Code Here

    /**
     * Tests that parsing an example script correctly creates the parent relationships
     */
    public void testParser() throws Exception {
        InputStream in = new FileInputStream("src/test/org/apache/commons/jelly/sql/example2.jelly");
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
       
        log.debug("Found: " + script);
       
        assertTagsHaveParent( script, null );
View Full Code Here

        runUnitTest( "src/test/org/apache/commons/jelly/xml/testExpressions.jelly");
    }
   
    public void testParse() throws Exception {
        InputStream in = new FileInputStream("src/test/org/apache/commons/jelly/xml/example.jelly");
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        log.debug("Found: " + script);
        assertTrue("Parsed a Script", script instanceof Script);
        StringWriter buffer = new StringWriter();
        script.run(parser.getContext(), XMLOutput.createXMLOutput(buffer));
        String text = buffer.toString().trim();
        if (log.isDebugEnabled()) {
            log.debug("Evaluated script as...");
            log.debug(text);
        }
View Full Code Here

    }
   
    public Document parseUnitTest(String name) throws Exception {
        // parse script
        InputStream in = new FileInputStream(name);
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        assertTrue("Parsed a Script", script instanceof Script);
        StringWriter buffer = new StringWriter();
        script.run(parser.getContext(), XMLOutput.createXMLOutput(buffer));

        String text = buffer.toString().trim();
        if (log.isDebugEnabled()) {
            log.debug("Evaluated script as...");
            log.debug(text);
View Full Code Here

        super(testName);
    }

    public void testArgs() throws Exception {
        InputStream in = new FileInputStream("src/test/org/apache/commons/jelly/test_args.jelly");
        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        log.debug("Found: " + script);
        assertTrue("Parsed a Script", script instanceof Script);
        String[] args = { "one", "two", "three" };
        JellyContext context = new JellyContext();
View Full Code Here

   
    /**
     * Compiles the script
     */
    protected Script compileScript() throws Exception {
        XMLParser parser = new XMLParser();
        parser.setContext(getJellyContext());
        Script script = parser.parse(getUrl().toString());
        script = script.compile();
        if (log.isDebugEnabled()) {
            log.debug("Compiled script: " + getUrl());
        }
        return script;
View Full Code Here

    /**
     * Attempts to parse the script from the given uri using the
     * {@link #getResource} method then returns the compiled script.
     */
    public Script compileScript(String uri) throws Exception {
        XMLParser parser = new XMLParser();
        parser.setContext(this);
        InputStream in = getResourceAsStream(uri);
        if (in == null) {
            throw new JellyException("Could not find Jelly script: " + uri);
        }
        Script script = parser.parse(in);
        return script.compile();
    }
View Full Code Here

    /**
     * Attempts to parse the script from the given URL using the
     * {@link #getResource} method then returns the compiled script.
     */
    public Script compileScript(URL url) throws Exception {
        XMLParser parser = new XMLParser();
        parser.setContext(this);
        Script script = parser.parse(url.toString());
        return script.compile();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jelly.parser.XMLParser

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.