Package org.apache.cocoon.components.parser

Examples of org.apache.cocoon.components.parser.Parser


     * @throws SAXException if failed to parse source document.
     */
    public void toSAX(ContentHandler handler)
        throws SAXException, ProcessingException
    {
        Parser parser = null;
        try {
            parser = (Parser)this.manager.lookup(Parser.ROLE);

            if (handler instanceof XMLConsumer) {
                parser.setConsumer((XMLConsumer)handler);
            } else {
                parser.setContentHandler(handler);
                if (handler instanceof LexicalHandler) {
                    parser.setLexicalHandler((LexicalHandler)handler);
                }
            }
            parser.parse(this.getInputSource());
        } catch (ProcessingException e){
            // Preserve original exception
            throw e;
        } catch (SAXException e) {
            // Preserve original exception
View Full Code Here


  }

  public void toSAX(ContentHandler handler)
    throws SAXException
  {
    Parser parser = null;
    try {
      EmbeddedXMLPipe newHandler = new EmbeddedXMLPipe(handler);

      parser = (Parser)componentManager.lookup(Parser.ROLE);
     
      parser.setContentHandler(newHandler);
      InputSource source = getInputSource();
      parser.parse(source);

    } catch (Exception ex) {
      throw new SAXException(ex);
    } finally {
      if (parser != null) componentManager.release(parser);
View Full Code Here

            LuceneIndexContentHandler luceneIndexContentHandler)
             throws ProcessingException {

        InputStream is = null;
        InputSource in = null;
        Parser parser = null;

        try {
            is = contentURLConnection.getInputStream();
            in = new InputSource(is);

            // get an XML parser
            parser = (Parser) this.manager.lookup(Parser.ROLE);
            //reader.setErrorHandler(new CocoonErrorHandler());
            parser.setContentHandler(luceneIndexContentHandler);
            parser.parse(in);
            //
            // document is parsed
            //
        } catch (IOException ioe) {
            throw new ProcessingException("Cannot read!", ioe);
View Full Code Here

                    }
                    reader.close();
                }
            } else if (parse.equals("xml")) {
                getLogger().debug("Parse type is XML");
                Parser parser = null;
                try {
                    parser = (Parser)manager.lookup(Parser.ROLE);
       
                    InputSource input = url.getInputSource();
       
                    if (suffix.startsWith("xpointer(") && suffix.endsWith(")")) {
                        String xpath = suffix.substring(9,suffix.length()-1);
                        getLogger().debug("XPath is "+xpath);
                        Document document = parser.parseDocument(input);
                        NodeList list = processor.selectNodeList(document,xpath);
                        DOMStreamer streamer = new DOMStreamer(super.contentHandler,super.lexicalHandler);
                        int length = list.getLength();
                        for (int i=0; i<length; i++) {
                            streamer.stream(list.item(i));
                        }
                    } else {
                        IncludeXMLConsumer xinclude_handler = new IncludeXMLConsumer(super.contentHandler,super.lexicalHandler);
                        xinclude_handler.setLogger(getLogger());
                        parser.setConsumer(xinclude_handler);
                        parser.parse(input);
                    }
                } catch(SAXException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(ProcessingException e) {
View Full Code Here

        // Guard against calling generate before setup.
        if (!activeFlag) {
            throw new IllegalStateException("generate called on sitemap component before setup.");
        }

        Parser parser = null;
        try {
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Processing File: " + super.source);
            }

            /* lets render a template */
            StringWriter w = new StringWriter();
            this.tmplEngine.mergeTemplate(super.source, velocityContext, w);

            InputSource xmlInput =
            new InputSource(new StringReader(w.toString()));
            parser.setConsumer(this.xmlConsumer);
            parser.parse(xmlInput);
        } catch (IOException e) {
            getLogger().warn("VelocityGenerator.generate()", e);
            throw new ResourceNotFoundException("Could not get Resource for VelocityGenerator", e);
        } catch (SAXException e) {
            getLogger().error("VelocityGenerator.generate()", e);
View Full Code Here

    }  

    public static void includeInputSource(InputSource source, ComponentManager manager, ContentHandler contentHandler)
        throws RuntimeException {
       
        Parser newParser = null;
       
        try {
            newParser = (Parser) manager.lookup(Parser.ROLE);
            XSPUtil.include(source, contentHandler, newParser);
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.cocoon.components.parser.Parser

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.