Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


        if (uri == null || uri.trim().length() == 0) {
            throw new IllegalArgumentException("getContentFromURI: URI is required");
        }

        long startTime = System.currentTimeMillis();
        Source input = null;
        try {
            input = this.getSource(uri, typeParameters, resourceParameters);
            InputSource source = input.getInputSource();
            InputStream stream = source.getByteStream();
            StringBuffer buffer = new StringBuffer();
            String encoding = source.getEncoding();
            int available;
            byte[] data;
            do {
                available = 1024;
                data = new byte[available];
                available = stream.read(data, 0, available);
                if (available > 0) {
                    if (encoding == null) {
                        buffer.append(new String(data, 0, available));
                    } else {
                        buffer.append(new String(data, 0, available, encoding));
                    }
                }
            } while (available > 0);
            content = buffer.toString();
        } finally {
            if (input != null) input.recycle();
            input = null;
        }

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("END getContentFromURI content="+content);
View Full Code Here


           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

     */
    private Source getSource(String             uri,
                             Parameters         typeParameters,
                             SourceParameters resourceParameters)
    throws IOException, SAXException, ProcessingException {
        Source input;

        // Test: local uri (= same servlet/cocoon) ?
        if (uri.startsWith("/") == true) {
            // server-absolute url is transformed to absolute url
            Request request = ObjectModelHelper.getRequest(objectModel);
View Full Code Here

                                                   builder);
            filter = new IncludeXMLConsumer(consumer, consumer);
        } else {
            filter = new IncludeXMLConsumer(builder, builder);
        }
        Source input = null;
        try {
            input = this.getSource(uri, typeParameters, resourceParameters);

            if (input != null) {
                input.toSAX(filter);
            }
        } finally {
            if (input != null) input.recycle();
            input = null;
        }

        builder.endElement("", "sunShine", "sunShine");
        builder.endDocument();
View Full Code Here

        }
        DocumentFragment frag = null;

        long startTime = System.currentTimeMillis();

        Source input = null;
        try {
            input = this.resolver.resolve(fileName);

            DOMBuilder builder = new DOMBuilder();
            builder.startDocument();
            builder.startElement("", "sunShine", "sunShine", this.emptyAttributes);

            IncludeXMLConsumer filter = new IncludeXMLConsumer(builder, builder);
            input.toSAX(filter);

            builder.endElement("", "sunShine", "sunShine");
            builder.endDocument();

            // Create Document Fragment
            final Document doc = builder.getDocument();
            frag = doc.createDocumentFragment();
            final Node root = doc.getDocumentElement();
            Node child;
            while (root.hasChildNodes() == true) {
                child = root.getFirstChild();
                child.normalize();
                root.removeChild(child);
                frag.appendChild(child);
            }
        } finally {
            if (input != null) input.recycle();
            input = null;
        }


        if (this.getLogger().isDebugEnabled() == true) {
View Full Code Here

                        }
                    }
                }
            }

            Source input = null;
            try {
                Properties format = XMLUtil.defaultSerializeToXMLFormat(false);
                this.setOutputKeys(format, typeParameters);
                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()));
                if (file.exists() == false) {
                    File directory = file.getParentFile();
                    if (directory.exists() == false) {
                        directory.mkdirs();
                    }
                    file.createNewFile();
                }
                String xml = XMLUtil.serializeNode(fragment, format);
                Writer writer = new BufferedWriter(new FileWriter(file));;
                writer.write(xml);
                writer.flush();
                writer.close();
                writer = null;
            } finally {
                if (input != null) input.recycle();
                input = null;
            }

        } catch (IOException ioe) {
            throw new ProcessingException("saveXMLToFile: IOException: " + ioe, ioe);
View Full Code Here

                              ", typeParams="+typeParameters+
                              ", file=" + fileName +
                              ", params="+resourceParameters);
        }
        try {
            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()));
                if (file.exists() == false) {
                    File directory = file.getParentFile();
                    if (directory.exists() == false) {
                        directory.mkdirs();
                    }
                    file.createNewFile();
                }
                Writer writer = new BufferedWriter(new FileWriter(file));
                writer.write(content);
                writer.flush();
                writer.close();
                writer = null;
            } finally {
                if (input != null) input.recycle();
                input = null;
            }

        } catch (IOException ioe) {
            throw new ProcessingException("saveContentToFile: IOException: " + ioe, ioe);
View Full Code Here

            this.getLogger().debug("BEGIN streamXMLFromFile fileName=" + fileName +
                              ", typeParams="+typeParameters+
                              ", parameters="+resourceParameters);
        }
        long startTime = System.currentTimeMillis();
        Source input = null;
        try {
            input = this.resolver.resolve(fileName);

            IncludeXMLConsumer filter = new IncludeXMLConsumer(contentHandler, lexicalHandler);
            input.toSAX(filter);

        } catch (SAXException sax) {
            throw new ProcessingException("SAXException: " + sax, sax);
        } catch (IOException ioe) {
            throw new ProcessingException("IOException: " + ioe, ioe);
        } finally {
            if (input != null) input.recycle();
            input = null;
        }

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("END streamXMLFromFile");
View Full Code Here

            contentHandler = consumer;
            lexicalHandler = consumer;
        }
        IncludeXMLConsumer filter = new IncludeXMLConsumer(contentHandler, lexicalHandler);

        Source input = null;
        try {
            input = this.getSource(uri, typeParameters, resourceParameters);
            input.toSAX(filter);
        } finally {
            if (input != null) input.recycle();
            input = null;
        }

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("END streamXMLFromURI");
View Full Code Here

        if (uri == null || uri.trim().length() == 0) {
            throw new IllegalArgumentException("getContentFromURI: URI is required");
        }

        long startTime = System.currentTimeMillis();
        Source input = null;
        try {
            input = this.getSource(uri, typeParameters, resourceParameters);
            InputSource source = input.getInputSource();
            InputStream stream = source.getByteStream();
            StringBuffer buffer = new StringBuffer();
            String encoding = source.getEncoding();
            int available;
            byte[] data;
            do {
                available = 1024;
                data = new byte[available];
                available = stream.read(data, 0, available);
                if (available > 0) {
                    if (encoding == null) {
                        buffer.append(new String(data, 0, available));
                    } else {
                        buffer.append(new String(data, 0, available, encoding));
                    }
                }
            } while (available > 0);
            content = buffer.toString();
        } finally {
            if (input != null) input.recycle();
            input = null;
        }

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("END getContentFromURI content="+content);
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.