Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


           this.getLogger().debug("BEGIN getContentFromFile filename=" + filename +
                             ", typeParams="+typeParameters+
                             ", parameters="+resourceParameters);
        }
        String content;
        Source input = null;
        try {
            input = this.resolver.resolve(filename);
            String absolutePath = input.getSystemId();
            if (absolutePath.startsWith("file:") == false) {
                throw new ProcessingException("Saving to " + filename + " is not possible.");
            }
            File file = new File(absolutePath.substring("file:".length()));
            byte[] data = null;
            InputStream fis = new FileInputStream(file);
            int available;
            byte[] tempData;
            byte[] copyData;
            do {
                available = 1024;
                tempData = new byte[available];
                available = fis.read(tempData, 0, available);
                if (available > 0) {
                    copyData = new byte[(data == null ? 0 : data.length) + available];
                    if (data != null) {
                        System.arraycopy(data, 0, copyData, 0, data.length);
                    }
                    System.arraycopy(tempData, 0, copyData, (data == null ? 0 : data.length), available);
                    data = copyData;
                }
            } while (available > 0);
            fis.close();
            content = (data == null ? "" : new String(data));
        } catch (FileNotFoundException local) {
            throw new ResourceNotFoundException("File not found '" + filename + "'", local);
        } finally {
            if (input != null) input.recycle();
            input = null;
        }
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("END getContentFromFile content="+content);
        }
View Full Code Here


        if ( identifier.startsWith("class://") ) {
            this.resourceType = ResourceConnector.RESOURCE_TYPE_CLASS;
            this.resourceIdentifier = identifier.substring("class://".length());
        } else if ( identifier.indexOf(":/") == -1) {
            // relative, resolve it first
            Source source = null;
            try {
                source = resolver.resolve(identifier);
                identifier = source.getSystemId();
                if ( identifier.startsWith("file:") ) {
                    this.resourceType = ResourceConnector.RESOURCE_TYPE_FILE;
                    this.resourceIdentifier = identifier.substring("file:".length());
                } else {
                    this.resourceType = ResourceConnector.RESOURCE_TYPE_URI;
                    this.resourceIdentifier = identifier;
                }
            } finally {
                source.recycle();
            }
        } else {
            // check for relative cocoon:/ protocol
            if (identifier.startsWith("cocoon:/")
                && identifier.charAt("cocoon:/".length()) != '/') {
View Full Code Here

        }
        if (fragment == null) {
            throw new ProcessingException("insertFragment: fragment is required.");
        }

        Source fileSource = null;
        String systemId = null;
        try {
            fileSource = this.resolver.resolve( fileName );
            systemId = fileSource.getSystemId();
            if (systemId.startsWith("file:") == false) {
                throw new ProcessingException("insertFragment: this is not a file: " + systemId);
            }
        } finally {
            if (fileSource != null) fileSource.recycle();
        }
        if (path.startsWith("/") == true) path = path.substring(1);

        File file = new File(systemId.substring(5));
        DocumentFragment resource = null;
View Full Code Here

        synchronized (AbstractComplementaryConfigurableAction.configurations) {
            conf = (ConfigurationHelper) AbstractComplementaryConfigurableAction.configurations.get(descriptor);

            if (reloadable || conf == null) {
                SourceHandler sourceHandler = null;
                Source resource = null;

                try {
                    sourceHandler = (SourceHandler) this.manager.lookup(SourceHandler.ROLE);
                    if (descriptor.startsWith("file:")) {
                        resource = sourceHandler.getSource((Environment)resolver,((Environment)resolver).getContext(), descriptor.substring(5));
                    } else
                        resource = sourceHandler.getSource(null, descriptor);

                    if (conf == null || conf.lastModified < resource.getLastModified()) {
                        getLogger().debug("(Re)Loading " + descriptor);
                        if (conf == null)
                            conf = new ConfigurationHelper();

                        SAXConfigurationHandler builder = new SAXConfigurationHandler();
                        resource.toSAX(builder);

                        conf.lastModified = resource.getLastModified();
                        conf.configuration = builder.getConfiguration();

                        this.cacheConfiguration(descriptor, conf);
                    } else {
                        getLogger().debug("Using cached configuration for " + descriptor);
                    }
                } catch (Exception e) {
                    getLogger().error("Could not configure Database mapping environment", e);
                    throw new ConfigurationException("Error trying to load configurations for resource: " + (resource == null ? "null" : resource.getSystemId()));
                } finally {
                    if (resource != null) resource.recycle();
                    if (sourceHandler != null) this.manager.release((Component) sourceHandler);
                }
        } else {
        getLogger().debug("Using fixed cached configuration for " + descriptor);
        }
View Full Code Here

                          + ", ns=" + ns
                          + ", prefix=" + prefix);

        // complete validity information
        if(currentCacheValidity != null ) {
            Source temp = null;
            try {
                temp = sourceResolver.resolve(src);
                currentCacheValidity.add(src, temp.getLastModified());
                getLogger().debug("currentCacheValidity: " + currentCacheValidity);
            } catch (Exception e) {
                getLogger().error("CachingCIncludeTransformer could not resolve resource:" + src,  e);
                throw new SAXException("CachingCIncludeTransformer could not resolve resource", e);
            } finally {
                if (temp != null) temp.recycle();
            }
        }

        if (!"".equals(element)) {
            AttributesImpl attrs = new AttributesImpl();
            if (!ns.equals("")) {
                super.startPrefixMapping(prefix, ns);
            }
            super.startElement(ns,
                               element,
                               (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element),
                               attrs);
        }

        Source source = null;
        try {
            source = this.sourceResolver.resolve(src);
            source.toSAX(getConsumer());
        } catch (Exception e) {
            getLogger().error("CachingCIncludeTransformer", e);
            throw new SAXException("CachingCIncludeTransformer could not read resource", e);
        } finally {
            if (source != null) source.recycle();
        }

        if (!"".equals(element)) {
            super.endElement(ns, element, (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element));
            if (!ns.equals("")) {
View Full Code Here

            long key = HashUtil.hash("CA(" +
                                     this.rootElement.prefix +
                                     ':' +
                                     this.rootElement.name +
                                     '<' + this.rootElement.namespace + ">)");
            Source current;
            for (int i = 0; i < this.parts.size(); i++) {
                final Part part = (Part)this.parts.get(i);
                current = part.source;
                if (current.getLastModified() == 0) {
                        return 0;
                } else {
                    if (part.element == null) {
                        key += HashUtil.hash("P=" +
                                         part.stripRootElement + ':' +
                                         current.getSystemId() + ';');
                    } else {
                        key += HashUtil.hash("P=" +
                                         part.element.prefix +
                                         ':' +
                                         part.element.name +
                                         '<' + part.element.namespace + ">:" +
                                         part.stripRootElement + ':' +
                                         current.getSystemId() + ';');
                    }
                }
            }
            return key;
        } catch (Exception e) {
View Full Code Here

     *         component is currently not cacheable.
     */
    public CacheValidity generateValidity() {
        try {
            AggregatedCacheValidity v = new AggregatedCacheValidity();
            Source current;
            for (int i = 0; i < this.parts.size(); i++) {
                current = ((Part)this.parts.get(i)).source;
                if (current.getLastModified() == 0) {
                        return null;
                } else {
                    v.add(new TimeStampCacheValidity(current.getLastModified()));
                }
            }
            return v;
        } catch (Exception e) {
            getLogger().error("ContentAggregator: could not generateKey", e);
View Full Code Here

            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.setConsumer(this.xmlConsumer);
            parser.parse(input);
        } 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) {
            getLogger().debug("SAXException JspGenerator.generate()", e);
            getLogger().debug("Embedded SAXException JspGenerator.generate()", e.getException());
            throw new ProcessingException("SAXException JspGenerator.generate()",e.getException());
        } catch (IOException e) {
            getLogger().debug("IOException in JspGenerator.generate()", e);
            throw new ProcessingException("IOException JspGenerator.generate()",e);
        } catch (ProcessingException e) {
            throw e;
        } catch (Exception e) {
            getLogger().debug("Exception in JspGenerator.generate()", e);
            throw new ProcessingException("Exception JspGenerator.generate()",e);
        } finally {
            if (src != null) src.recycle();
            if (parser != null) this.manager.release(parser);
            if (engine != null) this.manager.release(engine);
        }
    }
View Full Code Here

*/
public class ResourceExistsAction extends ComposerAction implements ThreadSafe {

    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
        String urlstring = parameters.getParameter("url",null);
        Source src = null;
        try {
            src = resolver.resolve(urlstring);
            src.getInputStream();
        } catch (Exception e) {
            getLogger().debug("ResourceExistsAction: exception: ",e);
            return null;
        } finally {
            if (src != null) src.recycle();
        }
        return EMPTY_MAP;
    }
View Full Code Here

     *      filesystem
     */
    public void generate()
    throws SAXException, ProcessingException {
        String directory = super.source;
        Source inputSource = null;
        try {
            inputSource = this.resolver.resolve(directory);
            String systemId = inputSource.getSystemId();
            if (!systemId.startsWith(FILE)) {
              throw new ResourceNotFoundException(systemId + " does not denote a directory");
            }
            // This relies on systemId being of the form "file://..."
            File directoryFile = new File(new URL(systemId).getFile());
            if (!directoryFile.isDirectory()) {
                throw new ResourceNotFoundException(directory + " is not a directory.");
            }

            this.contentHandler.startDocument();
            this.contentHandler.startPrefixMapping(PREFIX,URI);

            Stack ancestors = getAncestors(directoryFile);
            addPathWithAncestors(directoryFile, ancestors);

            this.contentHandler.endPrefixMapping(PREFIX);
            this.contentHandler.endDocument();
        } catch (IOException ioe) {
            getLogger().warn("Could not read directory " + directory, ioe);
            throw new ResourceNotFoundException("Could not read directory "
                + directory, ioe);
        } finally {
            if (inputSource != null) inputSource.recycle();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.environment.Source

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.