Examples of XMLByteStreamCompiler


Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

    /**
     * Uses Cocoon's XMLByteStreamCompiler to convert the content of the given element to compiled
     * SAX events.
     */
    public static Object compileElementContent(Element element) {
        XMLByteStreamCompiler byteStreamCompiler = new XMLByteStreamCompiler();
        DOMStreamer domStreamer = new DOMStreamer();
        domStreamer.setContentHandler(byteStreamCompiler);

        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            try {
                domStreamer.stream(childNodes.item(i));
            } catch (SAXException e) {
                // It's unlikely that an exception will occur here, so use a runtime exception
                throw new RuntimeException("Error in DomHelper.compileElementContent: " + e.toString());
            }
        }
        return byteStreamCompiler.getSAXFragment();
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

        // Get a ServerPagesGenerator
        ServerPagesGenerator generator = (ServerPagesGenerator)this.generatorHandler.get();

        // Generator ouptut, if output-attribute was given
        XMLByteStreamCompiler compiler = null;

        try {
            generator.enableLogging(getLogger());
            generator.compose(this.manager);
            generator.setup(resolver, objectModel, source, parameters);

            // Setup generator output
            if (outputKey == null) {
                // discard output to a "black hole"
                generator.setConsumer(new AbstractXMLConsumer() { } ); // Make the abstract class instanciable
            } else {
                // store output in a byte stream
                compiler = new XMLByteStreamCompiler();
                generator.setConsumer(compiler);
            }

            // Augment the object model for the "action" logicsheet
            objectModel.put(REDIRECTOR_OBJECT, redirector);
            objectModel.put(ACTION_RESULT_OBJECT, resultMap);

            // Let the XSP do it's stuff
            generator.generate();
            success = objectModel.get(ACTION_SUCCESS_OBJECT);

        } finally {
            // Release generator
            generatorHandler.put(generator);

            // Clean up object model
            objectModel.remove(REDIRECTOR_OBJECT);
            objectModel.remove(ACTION_RESULT_OBJECT);
            objectModel.remove(ACTION_SUCCESS_OBJECT);
        }

        if (outputKey != null) {
            // Success defaults to true when the whole output is captured
            if (success == null) {
                success = Boolean.TRUE;
            }

            if (success == Boolean.TRUE) {
                // Store the XSP output in the request
                Request req = ObjectModelHelper.getRequest(objectModel);
                req.setAttribute(outputKey, new XMLByteStreamFragment(compiler.getSAXFragment()));
            }
        }

        return (success == Boolean.TRUE) ? resultMap : null;
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

        // Get a ServerPagesGenerator
        ServerPagesGenerator generator = (ServerPagesGenerator)this.generatorHandler.get();

        // Generator ouptut, if output-attribute was given
        XMLByteStreamCompiler compiler = null;

        try {
            generator.setLogger(getLogger());
            generator.compose(this.manager);
            generator.setup(resolver, objectModel, source, parameters);

            // Setup generator output
            if (outputKey == null) {
                // discard output to a "black hole"
                generator.setConsumer(new AbstractXMLConsumer() { } ); // Make the abstract class instanciable
            } else {
                // store output in a byte stream
                compiler = new XMLByteStreamCompiler();
                generator.setConsumer(compiler);
            }

            // Augment the object model for the "action" logicsheet
            objectModel.put(REDIRECTOR_OBJECT, redirector);
            objectModel.put(ACTION_RESULT_OBJECT, resultMap);

            // Let the XSP do it's stuff
            generator.generate();
            success = objectModel.get(ACTION_SUCCESS_OBJECT);

        } catch (Exception e) {
            getLogger().warn("serverpage error", e);
            throw e;

        } finally {
            // Release generator
            generatorHandler.put(generator);

            // Clean up object model
            objectModel.remove(REDIRECTOR_OBJECT);
            objectModel.remove(ACTION_RESULT_OBJECT);
            objectModel.remove(ACTION_SUCCESS_OBJECT);
        }

        if (outputKey != null) {
            // Success defaults to true when the whole output is captured
            if (success == null) {
                success = Boolean.TRUE;
            }

            if (success == Boolean.TRUE) {
                // Store the XSP output in the request
                Request req = ObjectModelHelper.getRequest(objectModel);
                req.setAttribute(outputKey, new XMLByteStreamFragment(compiler.getSAXFragment()));
            }
        }

        return (success == Boolean.TRUE) ? resultMap : null;
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

                               final ContentHandler contentHandler)
    throws SAXException {
        if (this.isValidCache(coplet)) {
            this.toSAXFromCache(coplet, contentHandler);
        } else {
            XMLByteStreamCompiler bc = new XMLByteStreamCompiler();

            super.streamContent(coplet, uri, bc);

            if ( coplet.getAttribute(DO_NOT_CACHE) != null ) {
                coplet.removeAttribute(DO_NOT_CACHE);
                this.setCacheInvalid(coplet);
                XMLByteStreamInterpreter bi = new XMLByteStreamInterpreter();
                bi.setContentHandler(contentHandler);

                bi.deserialize(bc.getSAXFragment());
            } else {
                this.toCache(coplet, bc.getSAXFragment());

                this.toSAXFromCache(coplet, contentHandler);
            }
        }
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

        // Get a ServerPagesGenerator
        ServerPagesGenerator generator = (ServerPagesGenerator)this.generatorHandler.get();

        // Generator output, if output-attribute was given
        XMLByteStreamCompiler compiler = null;

        try {
            generator.enableLogging(getLogger());
            generator.compose(this.manager);
            generator.setup(resolver, objectModel, source, parameters);

            // Setup generator output
            if (outputKey == null) {
                // discard output to a "black hole"
                generator.setConsumer(new AbstractXMLConsumer() { } ); // Make the abstract class instanciable
            } else {
                // store output in a byte stream
                compiler = new XMLByteStreamCompiler();
                generator.setConsumer(compiler);
            }

            // Augment the object model for the "action" logicsheet
            objectModel.put(REDIRECTOR_OBJECT, redirector);
            objectModel.put(ACTION_RESULT_OBJECT, resultMap);

            // Let the XSP do it's stuff
            generator.generate();
            success = objectModel.get(ACTION_SUCCESS_OBJECT);

        } finally {
            // Release generator
            generatorHandler.put(generator);

            // Clean up object model
            objectModel.remove(REDIRECTOR_OBJECT);
            objectModel.remove(ACTION_RESULT_OBJECT);
            objectModel.remove(ACTION_SUCCESS_OBJECT);
        }

        if (outputKey != null) {
            // Success defaults to true when the whole output is captured
            if (success == null) {
                success = Boolean.TRUE;
            }

            if (success == Boolean.TRUE) {
                // Store the XSP output in the request
                Request req = ObjectModelHelper.getRequest(objectModel);
                req.setAttribute(outputKey, new XMLByteStreamFragment(compiler.getSAXFragment()));
            }
        }

        return (success == Boolean.TRUE) ? resultMap : null;
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

                               final ContentHandler contentHandler)
    throws SAXException {
        if (this.isValidCache(coplet)) {
            this.toSAXFromCache(coplet, contentHandler);
        } else {
            XMLByteStreamCompiler bc = new XMLByteStreamCompiler();

            super.streamContent(coplet, uri, bc);

            if ( coplet.getAttribute(DO_NOT_CACHE) != null ) {
                coplet.removeAttribute(DO_NOT_CACHE);
                this.setCacheInvalid(coplet);
                XMLByteStreamInterpreter bi = new XMLByteStreamInterpreter();
                bi.setContentHandler(contentHandler);

                bi.deserialize(bc.getSAXFragment());
            } else {
            this.toCache(coplet, bc.getSAXFragment());

            this.toSAXFromCache(coplet, contentHandler);
        }
    }
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

        this.index = index;
        this.data = data;

        // FIXME Retrieve components from the CM
        this.deserializer = new XMLByteStreamInterpreter();
        this.serializer = new XMLByteStreamCompiler();
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

        // Get a ServerPagesGenerator
        ServerPagesGenerator generator = (ServerPagesGenerator)this.generatorHandler.get();

        // Generator output, if output-attribute was given
        XMLByteStreamCompiler compiler = null;

        try {
            generator.enableLogging(getLogger());
            generator.compose(this.manager);
            generator.setup(resolver, objectModel, source, parameters);

            // Setup generator output
            if (outputKey == null) {
                // discard output to a "black hole"
                generator.setConsumer(new AbstractXMLConsumer() { } ); // Make the abstract class instanciable
            } else {
                // store output in a byte stream
                compiler = new XMLByteStreamCompiler();
                generator.setConsumer(compiler);
            }

            // Augment the object model for the "action" logicsheet
            objectModel.put(REDIRECTOR_OBJECT, redirector);
            objectModel.put(ACTION_RESULT_OBJECT, resultMap);

            // Let the XSP do it's stuff
            generator.generate();
            success = objectModel.get(ACTION_SUCCESS_OBJECT);

        } finally {
            // Release generator
            generatorHandler.put(generator);

            // Clean up object model
            objectModel.remove(REDIRECTOR_OBJECT);
            objectModel.remove(ACTION_RESULT_OBJECT);
            objectModel.remove(ACTION_SUCCESS_OBJECT);
        }

        if (outputKey != null) {
            // Success defaults to true when the whole output is captured
            if (success == null) {
                success = Boolean.TRUE;
            }

            if (success == Boolean.TRUE) {
                // Store the XSP output in the request
                Request req = ObjectModelHelper.getRequest(objectModel);
                req.setAttribute(outputKey, new XMLByteStreamFragment(compiler.getSAXFragment()));
            }
        }

        return (success == Boolean.TRUE) ? resultMap : null;
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

                               final ContentHandler contentHandler)
    throws SAXException {
        if (this.isValidCache(coplet)) {
            this.toSAXFromCache(coplet, contentHandler);
        } else {
            XMLByteStreamCompiler bc = new XMLByteStreamCompiler();

            super.streamContent(coplet, uri, bc);

            this.toCache(coplet, bc.getSAXFragment());

            this.toSAXFromCache(coplet, contentHandler);
        }
    }
View Full Code Here

Examples of org.apache.cocoon.components.sax.XMLByteStreamCompiler

    /**
     * Uses Cocoon's XMLByteStreamCompiler to convert the content of the given element to compiled
     * SAX events.
     */
    public static Object compileElementContent(Element element) {
        XMLByteStreamCompiler byteStreamCompiler = new XMLByteStreamCompiler();
        DOMStreamer domStreamer = new DOMStreamer();
        domStreamer.setContentHandler(byteStreamCompiler);

        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            try {
                domStreamer.stream(childNodes.item(i));
            } catch (SAXException e) {
                // It's unlikely that an exception will occur here, so use a runtime exception
                throw new RuntimeException("Error in DomHelper.compileElementContent: " + e.toString());
            }
        }
        return byteStreamCompiler.getSAXFragment();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.