Package org.apache.cocoon.components.sax

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


                }
            }
        }

        // we are not processing in parallel and have no (valid) cached response
        XMLSerializer serializer = null;
        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 = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                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


                synchronized (object[3]) {
                    ((List)object[3]).remove(uri);
                }
               
                Source source = null;
                XMLSerializer serializer = null;

                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("PreemptiveLoader: Loading " + uri);
                    }

                    source = resolver.resolveURI(uri);
                    serializer = (XMLSerializer)manager.lookup(XMLSerializer.ROLE);
               
                    SourceUtil.toSAX(source, serializer);
               
                    SourceValidity[] validities = new SourceValidity[1];
                    validities[0] = new ExpiresValidity(((Long)object[2]).longValue() * 1000); // milliseconds!
                    CachedResponse response = new CachedResponse(validities,
                                                                 (byte[])serializer.getSAXFragment());
                    ((IncludeCacheStorageProxy)object[0]).put(uri, response);
                    
                } catch (Exception ignore) {
                    // all exceptions are ignored!
                } finally {
View Full Code Here

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

                XMLSerializer serializer = null;
                XMLDeserializer deserializer = null;
                try {
                    if ( ignoreErrors ) {
                        serializer = (XMLSerializer) this.manager.lookup(XMLSerializer.ROLE);
                        deserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
                        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) throw pe;
View Full Code Here

    /**
     * Process one sunlet
     */
    public void run() {
        XMLSerializer compiler = null;
        Element sunletConf = (Element)this.loadedSunlet[1];
        SourceParameters p = (SourceParameters)loadedSunlet[2];

        try {
            // Determine the resource to load
            // If the sunLet is customizable and has no customization info
            // the customization resource is loaded, otherwise the resource
            Resource resource = null;
            boolean showCustomizePage = p.getParameterAsBoolean(Constants.PARAMETER_CUSTOMIZE, false);
            if (showCustomizePage == true) {
                final String value = XMLUtil.getValueOf(sunletConf, "customization/@uri", null);
                if (value == null) {
                    this.logger.error("The sunLet '"+this.sunletID+"' is customizable but has no customization info.");
                }
                resource = new Resource(this.resolver, value);
            }
            if (resource == null) {
                resource = new Resource(this.resolver, XMLUtil.getValueOf(sunletConf, "resource/@uri"));
            }
            boolean handlesSizable = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesSizable", false);

            if (handlesSizable == false && p.getParameter("size", "max").equals("max") == false) {
                // do nothing here
                loadedSunlet[0] = new byte[0];
            } else {

                compiler = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                compiler.startDocument();

                XMLConsumer nextConsumer = compiler;
                NodeList transformations = XMLUtil.selectNodeList(sunletConf,
                                                        "transformation/stylesheet");
                Transformer xslT = null;
                ArrayList transformers = new ArrayList();
                ComponentSelector selector = null;
                Request request = ObjectModelHelper.getRequest(this.objectModel);

                try {
                    if (transformations != null && transformations.getLength() > 0) {
                        selector = (ComponentSelector) this.manager.lookup(Transformer.ROLE + "Selector");
                        nextConsumer = new IncludeXMLConsumer(nextConsumer);
                        for(int k = transformations.getLength()-1; k >=0; k--) {
                            xslT = (Transformer)selector.select("xslt");
                            transformers.add(xslT);
                            xslT.setup(resolver,
                                       objectModel,
                                       XMLUtil.getValueOfNode(transformations.item(k)),
                                       new Parameters());
                            xslT.setConsumer(nextConsumer);
                            nextConsumer = xslT;
                        }
                        nextConsumer.startDocument();
                    }
                    switch (resource.getResourceType()) {
                        case ResourceConnector.RESOURCE_TYPE_CLASS: {
                             Sunlet theSunlet;
                             try {
                                 Class loaderClass = Class.forName(resource.getResourceIdentifier());
                                 theSunlet = (Sunlet)loaderClass.newInstance();
                             } catch (ClassNotFoundException cnfException) {
                                 throw new ProcessingException("getSunlet: Class not found: " + resource.getResourceIdentifier(), cnfException);
                             } catch (IllegalAccessException iaException) {
                                 throw new ProcessingException("getSunlet: Illegal Access: " + resource.getResourceIdentifier(), iaException);
                             } catch (InstantiationException iException) {
                                 throw new ProcessingException("getSunlet: Instantion exception: " + resource.getResourceIdentifier(), iException);
                             }
                             theSunlet.init(objectModel, p);
                             theSunlet.execute(nextConsumer, nextConsumer, objectModel, p);
                             break;
                        }
                        default: {
                            boolean includeFragment = true;
                            boolean handlesParameters = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesParameters", true);
                            String size = p.getParameter("size", "max");
                            if (resource.getResourceType() == ResourceConnector.RESOURCE_TYPE_FILE) {
                                // files have no possibility to evaluate minimized, so if they are not maximized
                                // they will be neglected
                                includeFragment = size.equals("max");

                            } else {
                                includeFragment = size.equals("max");
                                if (includeFragment == false) {
                                    if (this.logger.isWarnEnabled() == true) {
                                        this.logger.warn("Minimized sunlet '"+sunletID+"' not handled correctly.");
                                    }
                                }
                            }
                            if ( includeFragment == true) {
                                String res;

                                if (resource.getResourceType() == ResourceConnector.RESOURCE_TYPE_URI) {
                                     if (this.response != null) {
                                         res = this.response.encodeURL(resource.getResourceIdentifier());
                                     } else {
                                         res = resource.getResourceIdentifier();
                                     }
                                } else {
                                     res = resource.getResourceIdentifier();
                                }
                                if (this.logger.isDebugEnabled() == true) {
                                    this.logger.debug("sunSpot Loading sunlet " + sunletID);
                                }
                                // add the parameters to the request attributes
                                Map info = new HashMap(3);
                                SessionContextImpl.sunLetInfo.set(info);
                                info.put(Constants.SUNLETINFO_PARAMETERS, p);
                                info.put(Constants.SUNLETINFO_PORTALURI, request.getRequestURI());
                                info.put(Constants.SUNLETINFO_STATUSPROFILE, loadedSunlet[7]);
                                this.resourceConnector.streamXML(resource.getResourceType(), null,
                                           res, (handlesParameters == true ? p : null),
                                             new IncludeXMLConsumer(nextConsumer), null);
                                if (this.logger.isDebugEnabled() == true) {
                                    this.logger.debug("sunSpot: Loaded sunlet " + sunletID);
                                }
                            }
                        }
                    }
                    if (xslT != null) {
                        xslT.endDocument();
                        xslT = null;
                    }
                } finally {
                    SessionContextImpl.sunLetInfo.set(null);
                    if (selector != null) {
                        for(int i=0; i<transformers.size(); i++) {
                            selector.release((Component)transformers.get(i));
                        }
                        this.manager.release((Component)selector);
                    }
                }
                transformers.clear();
                nextConsumer = null;
                compiler.endDocument();
                loadedSunlet[0] = compiler.getSAXFragment();

            }
        } catch (Exception local) {
            // this exception is ignored and an error message is included
            // later on when the sunlet is processed
View Full Code Here

    public boolean process(Environment environment) throws Exception {
        this.setup(environment);

        // we cache if the pipelinecachekey is available
        XMLSerializer xmlSerializer = null;

        try {
            if (this.pipelineCacheKey != null) {
                // now we have the key to get the cached object
                CachedEventObject cachedObject = (CachedEventObject)this.eventCache.get(this.pipelineCacheKey);

                if (cachedObject != null) {
                    getLogger().debug("Found cached content for '" + environment.getURI() + "'.");
                    Iterator validityIterator = validityObjects.keySet().iterator();
                    ComponentCacheKey validityKey;
                    boolean valid = true;
                    while (validityIterator.hasNext() && valid) {
                        validityKey = (ComponentCacheKey)validityIterator.next();
                        valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
                        if (getLogger().isDebugEnabled()) {
                            CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
                            getLogger().debug("Compared cached validity '" + cachedValidity +
                                "' with new validity '" + validityObjects.get(validityKey) +
                                "' : " + (valid ? "valid" : "changed"));
                        }
                    }
                    if (valid) {
                        getLogger().debug("Using valid cached content for '" + environment.getURI() + "'.");
                        // get all transformers which are not cacheable
                        int transformerSize = this.transformers.size();
                        while (this.firstNotCacheableTransformerIndex < transformerSize) {
                            this.notCacheableTransformers.add(this.transformers.get(this.firstNotCacheableTransformerIndex));
                            this.firstNotCacheableTransformerIndex++;
                        }

                        XMLDeserializer deserializer = null;
                        try {
                            deserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
                            // connect the pipeline:
                            this.producer = deserializer;
                            this.connectPipeline(environment,
                                                 notCacheableTransformers,
                                                 null);
                            // execute the pipeline:
                            deserializer.deserialize(cachedObject.getSAXFragment());
                        } catch ( ProcessingException e ) {
                            throw e;
                        } catch ( Exception e ) {
                            throw new ProcessingException(
                                 "Failed to execute pipeline.",
                                  e
                            );
                        } finally {
                            this.manager.release(deserializer);
                        }
                    } else {
                        getLogger().debug("Cached content is invalid for '" + environment.getURI() + "'.");
                        // remove invalid cached object
                        this.eventCache.remove(this.pipelineCacheKey);
                        cachedObject = null;
                    }
                }
                if (cachedObject == null) {
                    getLogger().debug("Caching content for further requests of '" + environment.getURI() + "'.");
                    xmlSerializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                }
            }

            if (this.producer == null) {
                // the content was not cached/or is invalid
                this.producer = this.generator;
                this.connectPipeline(environment,
                                     this.transformers,
                                     xmlSerializer);
                // execute the pipeline:
                this.generator.generate();
                // did we have cacheable components?
                if (xmlSerializer != null) {
                    this.eventCache.store(this.pipelineCacheKey,
                        new CachedEventObject(this.validityObjects,
                        xmlSerializer.getSAXFragment()));
                }
            }
        } finally {
            this.manager.release(xmlSerializer);
        }
View Full Code Here

    /**
     * Process one coplet
     */
    public void run() {
        XMLSerializer compiler = null;
        Element copletConf = (Element)this.loadedCoplet[1];
        SourceParameters p = (SourceParameters)loadedCoplet[2];

        try {
            // Determine the resource to load
            // If the coplet is customizable and has no customization info
            // the customization resource is loaded, otherwise the resource
            String resource = null;
            boolean showCustomizePage = p.getParameterAsBoolean(PortalConstants.PARAMETER_CUSTOMIZE, false);
            if (showCustomizePage) {
                final String value = DOMUtil.getValueOf(copletConf, "customization/@uri", (String)null, this.processor);
                if (value == null) {
                    this.logger.error("The coplet '"+this.copletID+"' is customizable but has no customization info.");
                }
                resource = value;
            }
            if (resource == null) {
                resource = DOMUtil.getValueOf(copletConf, "resource/@uri", this.processor);
            }
            boolean handlesSizable = DOMUtil.getValueAsBooleanOf(copletConf, "configuration/handlesSizable", false, this.processor);

            if (!handlesSizable && !p.getParameter("size", "max").equals("max")) {
                // do nothing here
                loadedCoplet[0] = new byte[0];
            } else {

                compiler = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                compiler.startDocument();

                XMLConsumer nextConsumer = compiler;
                NodeList transformations = DOMUtil.selectNodeList(copletConf,
                                                        "transformation/stylesheet", this.processor);
                XSLTProcessor xslt = null;
                ArrayList transformers = null;
                ArrayList sources = null;
                Request request = ObjectModelHelper.getRequest(this.objectModel);
                XMLConsumer stylesheet =null;
               
                try {
                    if (transformations != null && transformations.getLength() > 0) {
                        transformers = new ArrayList();
                        sources = new ArrayList();
                       
                        nextConsumer = new IncludeXMLConsumer(nextConsumer);
                        for(int k = transformations.getLength()-1; k >=0; k--) {
                            xslt = (XSLTProcessor)this.manager.lookup(XSLTProcessor.ROLE);
                            transformers.add(xslt);
                            Source source = this.resolver.resolveURI(DOMUtil.getValueOfNode(transformations.item(k)));
                            sources.add(source);
                            TransformerHandler handler = xslt.getTransformerHandler(source);

                            final SAXResult result = new SAXResult(nextConsumer);
                            result.setLexicalHandler(nextConsumer);
                            handler.setResult(result);
                            nextConsumer = new ContentHandlerWrapper(handler, handler);
                            stylesheet = nextConsumer;
                        }
                        stylesheet.startDocument();
                    }
                    boolean includeFragment = true;
                    boolean handlesParameters = DOMUtil.getValueAsBooleanOf(copletConf, "configuration/handlesParameters", true, this.processor);
                    String size = p.getParameter("size", "max");
                    includeFragment = size.equals("max");
                    if (!includeFragment) {
                        if (this.logger.isWarnEnabled()) {
                            this.logger.warn("Minimized coplet '"+copletID+"' not handled correctly.");
                        }
                    }
                    if ( includeFragment ) {
                        if (this.logger.isDebugEnabled() ) {
                            this.logger.debug("portal: Loading coplet " + copletID);
                        }
                        // add the parameters to the request attributes
                        Map info = new HashMap(3);
                        SessionContextImpl.copletInfo.set(info);
                        info.put(PortalConstants.COPLETINFO_PARAMETERS, p);
                        info.put(PortalConstants.COPLETINFO_PORTALURI, request.getRequestURI());
                        info.put(PortalConstants.COPLETINFO_STATUSPROFILE, loadedCoplet[7]);
                        XMLConsumer xc = new IncludeXMLConsumer(nextConsumer);
                        Source source = null;
                        try {
                            source = SourceUtil.getSource(resource,
                                                          null,
                                                          (handlesParameters ? p : null),
                                                          resolver);
                            SourceUtil.toSAX(source, xc);
                        } finally {
                            resolver.release(source);
                        }

                        if (this.logger.isDebugEnabled()) {
                            this.logger.debug("portal: Loaded coplet " + copletID);
                        }
                    }
                    if ( stylesheet != null ) {
                        stylesheet.endDocument();
                    }
                } finally {
                    SessionContextImpl.copletInfo.set(null);
                    if ( transformers != null ) {
                        for(int i=0; i < transformers.size(); i++) {
                            this.manager.release( (Component)transformers.get(i));
                            this.resolver.release( (Source)sources.get(i));
                        }
                    }
                }
                nextConsumer = null;
                compiler.endDocument();
                loadedCoplet[0] = compiler.getSAXFragment();
            }
        } catch (Exception local) {
            // this exception is ignored and an error message is included
            // later on when the coplet is processed
            this.logger.error("Exception during processing of coplet: " + copletID, local);
View Full Code Here

        if ("description".equals(name)) {
            final String text = this.endTextRecording();
            final String html = "<html><body>"+text+"</body></html>";
           
            Object parsed = null;           
            XMLSerializer serializer = null;
            try {
                serializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                InputStream inputStream = new ByteArrayInputStream(html.getBytes());
                this.xmlizer.toSAX(inputStream,
                                    "text/html",
                                    null,
                                    serializer);
                // if no exception occurs, everything is fine!
                parsed = serializer.getSAXFragment();
            } catch (Exception ignore) {
                // just ignore all exceptions
            } finally {
                this.manager.release( serializer );
            }
View Full Code Here

            }

            if (this.toCacheKey.size() > 0) {
                ListIterator itt = this.xmlSerializerArray.listIterator(this.xmlSerializerArray.size());
                while (itt.hasPrevious()) {
                    XMLSerializer serializer = (XMLSerializer) 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: "
                            + this.toCacheKey);
View Full Code Here

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

View Full Code Here

     * Connect the pipeline.
     */
    protected void connectCachingPipeline(Environment   environment)
    throws ProcessingException {
        try {
            XMLSerializer localXMLSerializer = null;
            if (!this.cacheCompleteResponse) {
                this.xmlSerializer = (XMLSerializer) this.manager.lookup(XMLSerializer.ROLE);
                localXMLSerializer = this.xmlSerializer;
            }

View Full Code Here

TOP

Related Classes of org.apache.cocoon.components.sax.XMLSerializer

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.