Examples of XMLByteStreamCompiler


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

    /**
     * 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

                source = SourceUtil.getSource(resource,
                                              this.configurationParameters,
                                              this.resourceParameters,
                                              this.resolver);

                XMLByteStreamCompiler serializer;
                XMLByteStreamInterpreter deserializer;
                try {
                    if ( ignoreErrors ) {
                        serializer = new XMLByteStreamCompiler();
                        deserializer = new XMLByteStreamInterpreter();
                        SourceUtil.toSAX(source, serializer, this.configurationParameters, true);
                        deserializer.setConsumer( this.xmlConsumer );
                        deserializer.deserialize( serializer.getSAXFragment() );
                    } else {
                        SourceUtil.toSAX(source, this.xmlConsumer, this.configurationParameters, true);
                    }
                } catch (ProcessingException pe) {
                    if (!ignoreErrors) {
View Full Code Here

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

    throws SAXException {
        if (this.getLogger().isDebugEnabled()) {
            this.getLogger().debug("BEGIN startCompiledXMLRecording");
        }

        this.addRecorder(new XMLByteStreamCompiler());

        if (this.getLogger().isDebugEnabled()) {
           this.getLogger().debug("END startCompiledXMLRecording");
        }
    }
View Full Code Here

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

    throws SAXException {
        if (this.getLogger().isDebugEnabled()) {
            this.getLogger().debug("BEGIN endCompiledXMLRecording");
        }

        XMLByteStreamCompiler recorder = (XMLByteStreamCompiler)this.removeRecorder();
        Object text = recorder.getSAXFragment();

        if (this.getLogger().isDebugEnabled()) {
            this.getLogger().debug("END endCompiledXMLRecording text="+text);
        }
        return text;
View Full Code Here

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

            fragmentID++;
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("extractLevel now " + extractLevel + ".");
            }

            this.serializer = new XMLByteStreamCompiler();

            // Start the DOM document
            this.serializer.startDocument();

            Iterator itt = prefixMap.entrySet().iterator();
View Full Code Here

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

            }

            if (this.toCacheKey.size()>0) {
                ListIterator itt = this.xmlSerializerArray.listIterator(this.xmlSerializerArray.size());
                while (itt.hasPrevious()) {
                    XMLByteStreamCompiler serializer = (XMLByteStreamCompiler) itt.previous();
                    CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
                                              (byte[])serializer.getSAXFragment());
                    this.cache.store(this.toCacheKey.copy(),
                                     response);

                    if (this.getLogger().isDebugEnabled()) {
                        this.getLogger().debug("Caching results for the following key: "
View Full Code Here

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

    /**
     * Connect the caching point pipeline.
     */
    protected void connectCachingPipeline(Environment   environment)
    throws ProcessingException {
        XMLByteStreamCompiler localXMLSerializer = null;
        XMLByteStreamCompiler cachePointXMLSerializer = null;
        if (!this.cacheCompleteResponse) {
            this.xmlSerializer = new XMLByteStreamCompiler();
            localXMLSerializer = this.xmlSerializer;
        }

        if (this.cachedResponse == null) {
            XMLProducer prev = super.generator;
            XMLConsumer next;

            int cacheableTransformerCount = this.firstNotCacheableTransformerIndex;
            int currentTransformerIndex = 0; //start with the first transformer

            Iterator itt = this.transformers.iterator();
            while ( itt.hasNext() ) {
                next = (XMLConsumer) itt.next();

                // if we have cacheable transformers,
                // check the tranformers for cachepoints
                if (cacheableTransformerCount > 0) {
                    if ( (this.isCachePoint.get(currentTransformerIndex) != null&&
                            ((Boolean)this.isCachePoint.get(currentTransformerIndex)).booleanValue()) {

                        cachePointXMLSerializer = new XMLByteStreamCompiler();
                        next = new XMLTeePipe(next, cachePointXMLSerializer);
                        this.xmlSerializerArray.add(cachePointXMLSerializer);
                    }
                }


                // Serializer is not cacheable,
                // but we  have the longest cacheable key. Do default longest key caching
                if (localXMLSerializer != null) {
                    if (cacheableTransformerCount == 0) {
                        next = new XMLTeePipe(next, localXMLSerializer);
                        this.xmlSerializerArray.add(localXMLSerializer);
                        localXMLSerializer = null;
                    } else {
                        cacheableTransformerCount--;
                    }
                }
                this.connect(environment, prev, next);
                prev = (XMLProducer) next;

                currentTransformerIndex++;
            }
            next = super.lastConsumer;


            // if the serializer is not cacheable, but all the transformers are:
            // (this is default longest key caching)
            if (localXMLSerializer != null) {
                next = new XMLTeePipe(next, localXMLSerializer);
                this.xmlSerializerArray.add(localXMLSerializer);
                localXMLSerializer = null;
            }

            // else if the serializer is cacheable and has cocoon views
            else if ((currentTransformerIndex == this.firstNotCacheableTransformerIndex) &&
                    this.nextIsCachePoint) {
                cachePointXMLSerializer = new XMLByteStreamCompiler();
                next = new XMLTeePipe(next, cachePointXMLSerializer);
                this.xmlSerializerArray.add(cachePointXMLSerializer);
            }
            this.connect(environment, prev, next);

        } else {
            // Here the first part of the pipeline has been retrived from cache
            // we now check if any part of the rest of the pipeline can be cached
            this.xmlDeserializer = new XMLByteStreamInterpreter();
            // connect the pipeline:
            XMLProducer prev = xmlDeserializer;
            XMLConsumer next;
            int cacheableTransformerCount = 0;
            Iterator itt = this.transformers.iterator();
            while ( itt.hasNext() ) {
                next = (XMLConsumer) itt.next();

                if (cacheableTransformerCount >= this.firstProcessedTransformerIndex) {

                    // if we have cacheable transformers left,
                    // then check the tranformers for cachepoints
                    if (cacheableTransformerCount < this.firstNotCacheableTransformerIndex) {
                        if ( !(prev instanceof XMLByteStreamInterpreter) &&
                                (this.isCachePoint.get(cacheableTransformerCount) != null&&
                                ((Boolean)this.isCachePoint.get(cacheableTransformerCount)).booleanValue()) {
                            cachePointXMLSerializer = new XMLByteStreamCompiler();
                            next = new XMLTeePipe(next, cachePointXMLSerializer);
                            this.xmlSerializerArray.add(cachePointXMLSerializer);
                        }
                    }

                    // Serializer is not cacheable,
                    // but we  have the longest cacheable key. Do default longest key caching
                    if (localXMLSerializer != null && !(prev instanceof XMLByteStreamInterpreter)
                            && cacheableTransformerCount == this.firstNotCacheableTransformerIndex) {
                        next = new XMLTeePipe(next, localXMLSerializer);
                        this.xmlSerializerArray.add(localXMLSerializer);
                        localXMLSerializer = null;
                    }
                    this.connect(environment, prev, next);
                    prev = (XMLProducer)next;
                }
                cacheableTransformerCount++;
            }
            next = super.lastConsumer;

            //*all* the transformers are cacheable, but the serializer is not!! this is longest key
            if (localXMLSerializer != null && !(prev instanceof XMLByteStreamInterpreter)) {
                next = new XMLTeePipe(next, localXMLSerializer);
                this.xmlSerializerArray.add(localXMLSerializer);
                localXMLSerializer = null;
            } else if (this.nextIsCachePoint && !(prev instanceof XMLByteStreamInterpreter) &&
                    cacheableTransformerCount == this.firstNotCacheableTransformerIndex) {
                // else the serializer is cacheable but has views
                cachePointXMLSerializer = new XMLByteStreamCompiler();
                next = new XMLTeePipe(next,  cachePointXMLSerializer);
                this.xmlSerializerArray.add(cachePointXMLSerializer);
            }
            this.connect(environment, prev, next);
        }
View Full Code Here

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

                this.getLogger().debug("Starting parallel thread for loading " + uri);
            }
            // now we start a parallel thread, this thread gets all required avalon components
            // so it does not have to lookup them by itself
            try {
                XMLByteStreamCompiler serializer = new XMLByteStreamCompiler();
                Source source = session.resolveURI(uri, this.resolver);

                LoaderThread loader = new LoaderThread(source, serializer);
                final RunnableManager runnableManager = (RunnableManager)this.manager.lookup( RunnableManager.ROLE );
                session.add(uri, loader);
View Full Code Here

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

                }
            }
        }

        // we are not processing in parallel and have no (valid) cached response
        XMLByteStreamCompiler serializer;
        try {
            final Source source = session.resolveURI(uri, this.resolver);
           
            // stream directly (and cache the response)
            if (this.getLogger().isDebugEnabled()) {
                this.getLogger().debug("Streaming directly from source.");
            }
            if (session.getExpires() > 0) {
                serializer = new XMLByteStreamCompiler();
                XMLTeePipe tee = new XMLTeePipe(handler, serializer);
               
                SourceUtil.toSAX(source, tee);
               
                SourceValidity[] validities = new SourceValidity[1];
                validities[0] = session.getExpiresValidity();
                CachedResponse response = new CachedResponse(validities,
                                                             (byte[])serializer.getSAXFragment());
                session.getCacheStorageProxy().put(uri, response);
            } else {
                SourceUtil.toSAX(source, handler);
            }
           
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.