Package org.apache.excalibur.xml.sax

Examples of org.apache.excalibur.xml.sax.SAXParser


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

        SAXParser parser = null;
        StringWriter w = new StringWriter();
        try {
            parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Processing File: " + super.source);
            }
            if (!tmplEngineInitialized) {
                tmplEngine.init();
                tmplEngineInitialized = true;
            }
            /* lets render a template */
            this.tmplEngine.mergeTemplate(super.source, velocityContext, w);

            InputSource xmlInput =
                    new InputSource(new StringReader(w.toString()));
            xmlInput.setSystemId(super.source);
            parser.parse(xmlInput, this.xmlConsumer);
        } catch (IOException e) {
            getLogger().warn("VelocityGenerator.generate()", e);
            throw new ResourceNotFoundException("Could not get Resource for VelocityGenerator", e);
        } catch (SAXParseException e) {
            int line = e.getLineNumber();
View Full Code Here


        contextData = DOMUtil.createDocument();
        contextData.appendChild(contextData.createElementNS(null, "context"));

        Element root = contextData.getDocumentElement();

        SAXParser parser = null;
        try {
            parser = (SAXParser) manager.lookup( SAXParser.ROLE );
            this.buildParameterXML(root, parser);
        } catch (ComponentException ce) {
            throw new ProcessingException("Unable to lookup parser.", ce);
View Full Code Here

                    + this.method.getURI().toString() + "\" (status=" + status + ")");
        }
        InputStream response = this.method.getResponseBodyAsStream();

        /* Let's try to set up our InputSource from the response output stream and to parse it */
        SAXParser parser = null;
        try {
            InputSource inputSource = new InputSource(response);
            parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
            parser.parse(inputSource, super.xmlConsumer);
        } catch (ComponentException ex) {
            throw new ProcessingException("Unable to get parser", ex);
        } finally {
            this.manager.release((Component) parser);
            this.method.releaseConnection();
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;
        SAXParser parser = null;
        try {
            // FIXME (KP): Should we exclude not supported protocols, say 'context'?
            String url = this.source;
            // absolute path is processed as is
            if (!url.startsWith("/")) {
                // get current request path
                String servletPath = httpRequest.getServletPath();
                // remove file part
                servletPath = servletPath.substring(0, servletPath.lastIndexOf('/') + 1);
                url = servletPath + url;
            }

            engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);

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

            byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);

            // explicitly specify bytestream encoding
            InputSource input = new InputSource(new ByteArrayInputStream(bytes));
            // FIXME (KP): Why do we need this?
            input.setEncoding("utf-8");

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

        }
        super.recycle();
    }

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

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

            // 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);

                    BSFManager.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.getURI()),
                     this.inputSource.getURI(), 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 = (SAXParser)(this.manager.lookup(SAXParser.ROLE));
            parser.parse(xmlInput, this.xmlConsumer);
        } catch (SourceException se) {
            throw SourceUtil.handle(se);
        } catch (FileNotFoundException e) {
            throw new ResourceNotFoundException(
                "Could not load script " + this.inputSource.getURI(), e);
View Full Code Here

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

        SAXParser parser = null;
        try {
            parser = (SAXParser) this.manager.lookup(SAXParser.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.parse(xmlInput, this.xmlConsumer);
        } 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

     * @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 {
        SAXParser p = null;
        Configuration roleConfig = null;

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

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

        try {
            p = (SAXParser)startupManager.lookup(SAXParser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputSource is = SourceUtil.getInputSource(this.configurationFile);
            p.parse(is, b);
            this.configuration = b.getConfiguration();
        } catch (Exception e) {
            throw new ConfigurationException("Error trying to load configurations",e);
        } finally {
            if (p != null) startupManager.release((Component)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 = (SAXParser)startupManager.lookup(SAXParser.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);
                if (url == null) {
                    throw new ConfigurationException("User-roles configuration '"+userRoles+"' cannot be found.");
                }
                InputSource is = new InputSource(new BufferedInputStream(url.openStream()));
                is.setSystemId(this.configurationFile.getURI());
                p.parse(is, b);
                roleConfig = b.getConfiguration();
            } catch (Exception e) {
                throw new ConfigurationException("Error trying to load user-roles configuration", e);
            } finally {
                startupManager.release((Component)p);
View Full Code Here

    public final Document transform(String type, String source, Parameters parameters, Document input) {

        ComponentSelector selector = null;
        Transformer transformer = null;
        SourceResolver resolver = null;
        SAXParser parser = null;
        Source inputsource = null;

        Document document = null;
        try {
            selector = (ComponentSelector) this.manager.lookup(Transformer.ROLE+
View Full Code Here

    }

    public final Document load(String source) {

        SourceResolver resolver = null;
        SAXParser parser = null;
        Source assertionsource = null;

        Document assertiondocument = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            assertNotNull("Test lookup of source resolver", resolver);

            parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
            assertNotNull("Test lookup of parser", parser);

            assertNotNull("Test if assertion document is not null",
                          source);
            assertionsource = resolver.resolveURI(source);
            assertNotNull("Test lookup of assertion source",
                          assertionsource);

            DOMBuilder builder = new DOMBuilder();
            assertNotNull("Test if inputstream of the assertion source is not null",
                          assertionsource.getInputStream());

            parser.parse(new InputSource(assertionsource.getInputStream()),
                         new WhitespaceFilter(builder),
                         builder);

            assertiondocument = builder.getDocument();
            assertNotNull("Test if assertion document exists", assertiondocument);
View Full Code Here

    /**
     * Generate XML data out of request InputStream.
     */
    public void generate() throws IOException, SAXException, ProcessingException
    {
        SAXParser parser = 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("Required header ContentType is missing.");
            } else if (contentType.startsWith("application/x-www-form-urlencoded") ||
                    contentType.startsWith("multipart/form-data")) {
                String parameter = parameters.getParameter(FORM_NAME, null);
                if (parameter == null) {
                    throw new ProcessingException(
                        "StreamGenerator expects a sitemap parameter called '" +
                        FORM_NAME + "' for handling form data"
                    );
                }
                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 = (SAXParser)this.manager.lookup(SAXParser.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

TOP

Related Classes of org.apache.excalibur.xml.sax.SAXParser

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.