Package org.apache.avalon.excalibur.xml

Examples of org.apache.avalon.excalibur.xml.Parser


     * @throws ResourceNotFoundException if file not found or
     *         HTTP location does not exist.
     * @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);

            parser.parse( this.getInputSource(), handler);
        } catch (SAXException e) {
            // Preserve original exception
            throw e;
        } catch (Exception e){
            throw new ProcessingException("Exception during processing of "
View Full Code Here


            getLogger().debug("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron);
            getLogger().debug("Sitemap check delay = " + checkDelay + " sec");
        }

        // Read sitemap roles
        Parser p = null;
        Configuration rolesConfig;
        try {
            p = (Parser)this.manager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/sitemap/sitemap.roles").openStream();
            InputSource is = new InputSource(inputStream);
            is.setSystemId("org/apache/cocoon/sitemap/sitemap.roles");
            p.parse(is, b);
            rolesConfig = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations", e);
        } finally {
View Full Code Here

     * @return a <code>Configuration</code> value
     * @exception ConfigurationException if an error occurs
     * @exception ContextException if an error occurs
     */
    public Configuration configure(ExcaliburComponentManager startupManager) throws ConfigurationException, ContextException {
        Parser p = null;
        Configuration roleConfig = null;

        try {
            this.configurationFile.refresh();
            p = (Parser)startupManager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/cocoon.roles").openStream();
            InputSource is = new InputSource(inputStream);
            is.setSystemId(this.configurationFile.getSystemId());
            p.parse(is, b);
            roleConfig = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations", e);
        } finally {
            if (p != null) startupManager.release(p);
        }

        DefaultRoleManager drm = new DefaultRoleManager();
        drm.setLogger(getLogger().getChildLogger("roles"));
        drm.configure(roleConfig);
        roleConfig = null;

        try {
            p = (Parser)startupManager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputSource is = this.configurationFile.getInputSource();
            p.parse(is, b);
            this.configuration = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations",e);
        } finally {
            if (p != null) startupManager.release(p);
        }

        Configuration conf = this.configuration;
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Root configuration: " + conf.getName());
        }
        if (! "cocoon".equals(conf.getName())) {
            throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Configuration version: " + conf.getAttribute("version"));
        }
        if (!Constants.CONF_VERSION.equals(conf.getAttribute("version"))) {
            throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
        }

        String userRoles = conf.getAttribute("user-roles", "");
        if (!"".equals(userRoles)) {
            try {
                p = (Parser)startupManager.lookup(Parser.ROLE);
                SAXConfigurationHandler b = new SAXConfigurationHandler();
                org.apache.cocoon.environment.Context context =
                    (org.apache.cocoon.environment.Context) this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
                URL url = context.getResource(userRoles);
                InputSource is = new InputSource(new BufferedInputStream(url.openStream()));
                is.setSystemId(this.configurationFile.getSystemId());
                p.parse(is, b);
                roleConfig = b.getConfiguration();
            } catch (Exception e) {
                getLogger().error("Could not configure Cocoon environment with user roles file", e);
                throw new ConfigurationException("Error trying to load user-roles configuration", e);
            } finally {
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.parse(in, luceneIndexContentHandler);
            //
            // document is parsed
            //
        } catch (IOException ioe) {
            throw new ProcessingException("Cannot read!", ioe);
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);

      InputSource source = getInputSource();
      parser.parse(source, newHandler);

    } catch (Exception ex) {
      throw new SAXException(ex);
    } finally {
      if (parser != null) componentManager.release(parser);
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);
                        parser.parse(input, xinclude_handler);
                    }
                } catch(SAXException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(ProcessingException e) {
View Full Code Here

    /**
     * Generate XML data out of request InputStream.
     */
    public void generate() throws IOException, SAXException, ProcessingException
    {
        Parser parser = null;
        String parameter = parameters.getParameter(StreamGenerator.FORM_NAME, null);
        int len = 0;
        String contentType = null;
        try {
            HttpServletRequest request = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
            contentType = request.getContentType();
            if (contentType == null) {
                throw new IOException("Requred header ContentType is missing.");
            } else if (contentType.startsWith("application/x-www-form-urlencoded")) {
                String sXml = request.getParameter(parameter);
                inputSource = new InputSource(new StringReader(sXml));
            } else if (contentType.startsWith("text/plain") ||
                    contentType.startsWith("text/xml") ||
                    contentType.startsWith("application/xml")) {

                len = request.getContentLength();
                if (len > 0) {
                        PostInputStream anStream = new PostInputStream(request.getInputStream(), len);
                        inputSource = new InputSource(anStream);
                } else {
                    throw new IOException("getContentLen() == 0");
                }
            } else {
                throw new IOException("Unexpected getContentType(): " + request.getContentType());
            }

            if (getLogger().isDebugEnabled()) {
                getLogger().debug("processing stream ContentType= " + request.getContentType() + "ContentLen= " + len);
            }
            String charset =  getCharacterEncoding(request, contentType) ;
            if( charset != null)
            {
                this.inputSource.setEncoding(charset);
            }
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.parse(this.inputSource, super.xmlConsumer);
        } catch (IOException e) {
            getLogger().error("StreamGenerator.generate()", e);
            throw new ResourceNotFoundException("StreamGenerator could not find resource", e);
        } catch (SAXException e) {
            getLogger().error("StreamGenerator.generate()", e);
View Full Code Here

        if (httpResponse == null || httpRequest == null || httpContext == null) {
            throw new ProcessingException("HttpServletRequest or HttpServletResponse or ServletContext object not available");
        }

        JSPEngine engine = null;
        Parser parser = null;
        Source src = null;
        try {
            src = this.resolver.resolve(this.source);
            String url = src.getSystemId();
            // Guarantee src parameter is a file
            if (!url.startsWith("file:/"))
                throw new IOException("Protocol not supported: " + url);

            url = url.substring(5);
            getLogger().debug("JspGenerator executing JSP:" + url);

            engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
            byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);

            // explicitly specify bytestream encoding
            InputSource input = new InputSource(new ByteArrayInputStream(bytes));
            input.setEncoding("utf-8");

            // pipe the results into the parser
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.parse(input, this.xmlConsumer);
        } catch (ServletException e) {
            getLogger().debug("ServletException in JspGenerator.generate()", e);
            getLogger().debug("Embedded ServletException JspGenerator.generate()", e.getRootCause());
            throw new ProcessingException("ServletException in JspGenerator.generate()",e.getRootCause());
        } catch (SAXException e) {
View Full Code Here

            this.inputSource = null;
        }
    }

    public void generate() throws ProcessingException {
        Parser parser = null;
        try {
            // Figure out what file to open and do so
            getLogger().debug("processing file [" + super.source + "]");
            this.inputSource = this.resolver.resolve(super.source);

            getLogger().debug("file resolved to [" + this.inputSource.getSystemId() + "]");

            // TODO: why doesn't this work?
            // Reader in = src.getCharacterStream();
            Reader in = new java.io.InputStreamReader(this.inputSource.getInputStream());

            // Set up the BSF manager and register relevant helper "beans"
            BSFManager mgr = new BSFManager();

            // add support for additional languages

            if (this.additionalLanguages != null)
            {
                for (int i = 0; i < this.additionalLanguages.length; ++i)
                {
                    getLogger().debug("adding BSF language " + this.additionalLanguages[i].name + " with engine " + this.additionalLanguages[i].engineSrc);

                    mgr.registerScriptingEngine(this.additionalLanguages[i].name,
                                                this.additionalLanguages[i].engineSrc,
                                                this.additionalLanguages[i].extensions);
                }
            }

            StringBuffer output = new StringBuffer();

            mgr.registerBean("resolver", this.resolver);
            mgr.registerBean("source", super.source);
            mgr.registerBean("objectModel", this.objectModel);
            mgr.registerBean("parameters", this.parameters);
            mgr.registerBean("output", output);
            mgr.registerBean("logger", getLogger());

            getLogger().debug("BSFManager execution begining");

            // Execute the script

            mgr.exec(BSFManager.getLangFromFilename(this.inputSource.getSystemId()),
                     this.inputSource.getSystemId(), 0, 0, IOUtils.getStringFromReader(in));

            getLogger().debug("BSFManager execution complete");
            getLogger().debug("output = [" + output.toString() + "]");

            // Extract the XML string from the BSFManager and parse it

            InputSource xmlInput =
                    new InputSource(new StringReader(output.toString()));
            parser = (Parser)(this.manager.lookup(Parser.ROLE));
            parser.parse(xmlInput, this.xmlConsumer);
        } catch (ProcessingException e) {
            throw e;
        } catch (FileNotFoundException e) {
            throw new ResourceNotFoundException(
                "Could not load script " + this.inputSource.getSystemId(), e);
View Full Code Here

            throw new ProcessingException("HttpServletRequest or HttpServletResponse object not available");
        }

        // ensure that we are serving a file...
        Source inputSource = null;
        Parser parser = null;
        try {
            inputSource = this.resolver.resolve(this.source);
            String systemId = inputSource.getSystemId();
            if (!systemId.startsWith("file:/"))
                throw new IOException("protocol not supported: " + systemId);

            // construct both ends of the pipe
            PipedInputStream input = new PipedInputStream();

            // start PHP producing results into the pipe
            PhpServlet php = new PhpServlet();
            php.init(new config((ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT)));
            php.setInput(systemId.substring(6));
            php.setOutput(new PipedOutputStream(input));
            php.setRequest(httpRequest);
            php.setResponse(httpResponse);
            new Thread(php).start();

            // pipe the results into the parser
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.parse(new InputSource(input), this.xmlConsumer);

            // clean up
            php.destroy();
        } catch (IOException e) {
            getLogger().debug("PhpGenerator.generate()", e);
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.xml.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.