Package org.apache.excalibur.source

Examples of org.apache.excalibur.source.ModifiableSource


            TransformerFactory tf = TransformerFactory.newInstance();

            if (docTarget instanceof ModifiableSource
                && tf.getFeature(SAXTransformerFactory.FEATURE)) {

                ModifiableSource ws = (ModifiableSource) docTarget;
                os = ws.getOutputStream();
                SAXTransformerFactory stf = (SAXTransformerFactory) tf;
                TransformerHandler th = stf.newTransformerHandler();
                Transformer t = th.getTransformer();
                t.setOutputProperty(OutputKeys.INDENT, "true");
                t.setOutputProperty(OutputKeys.METHOD, "xml");
View Full Code Here


        assertEquals(anotherText, read(source));
    }

    public void testDeleteFile() throws Exception {
        String text = "Yeah! Some content!";
        ModifiableSource source = (ModifiableSource)resolver.resolveURI("jcr://yet/another/deep/file");

        assertFalse(source.exists());
        write(source, text);

        // Lookup a fresh source
        source = (ModifiableSource)resolver.resolveURI("jcr://yet/another/deep/file");
        assertTrue(source.exists());
        source.delete();
        assertFalse(source.exists());

        // Lookup again to check it was really deleted
        source = (ModifiableSource)resolver.resolveURI("jcr://yet/another/deep/file");
        assertFalse(source.exists());
    }
View Full Code Here

                this.sendBrokenLinkWarning(target.getSourceURI(),
                    DefaultNotifyingBuilder.getRootCause(pe).getMessage());
            } finally {
                if (output != null && status != -1) {

                    ModifiableSource source = getSource(target);
                    try {
                        pageSize = output.size();
                       
                        if (this.checksumsURI == null || !isSameContent(output, target)) {
                            OutputStream stream = source.getOutputStream();
                            output.setFileOutputStream(stream);
                            output.flush();
                            output.close();
                            pageGenerated(target.getSourceURI(),
                                          target.getAuthlessDestURI(),
View Full Code Here

            n.setMessage("Page Not Available.");
            n.setDescription("The requested resource couldn't be found.");
            n.addExtraDescription(Notifying.EXTRA_REQUESTURI, target.getSourceURI());
            n.addExtraDescription("missing-file", target.getSourceURI());

            ModifiableSource source = getSource(target);
            try {
                OutputStream stream = source.getOutputStream();

                PrintStream out = new PrintStream(stream);
                Notifier.notify(n, out, "text/html");
                out.flush();
                out.close();
View Full Code Here

    private void writeChecksumFile() throws Exception {
        Source checksumSource = sourceResolver.resolveURI(checksumsURI);
        if (!(checksumSource instanceof ModifiableSource)) {
            throw new ProcessingException("Checksum file is not Modifiable:" + checksumSource);
        }
        ModifiableSource source = (ModifiableSource) checksumSource;
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(source.getOutputStream()));
        Iterator i = checksums.keySet().iterator();
        while (i.hasNext()){
            String key = (String) i.next();
            String checksum = (String) checksums.get(key);
            writer.println(key + "\t" + checksum);
View Full Code Here

                    dest = trDest.getChild(((PartSource)src).getPart().getFileName());
                }
            }
        }
       
        ModifiableSource wdest = (ModifiableSource)dest;
       
        // Get streams
        InputStream is = src.getInputStream();
        OutputStream os = wdest.getOutputStream();
       
        // And transfer all content.
        try {
            byte[] buffer = new byte[1024];
            int len;
            while ((len = is.read(buffer, 0, buffer.length)) > 0) {
                os.write(buffer, 0, len);
            }
            os.close();
        } catch(Exception e) {
            if (wdest.canCancel(os)) {
                wdest.cancel(os);
            }
        } finally {
            is.close();
        }
        // Success !
View Full Code Here

        try {
            source = this.resolver.resolveURI(systemID);
            if (! (source instanceof ModifiableSource)) {
                throw new ProcessingException("Source '" + systemID + "' is not writeable.");
            }
            ModifiableSource ws = (ModifiableSource) source;
            exists = ws.exists();
            target = source.getURI();

            // Insert?
            if (exists && this.state == STATE_INSERT) {
                message = "content inserted at: " + path;
                resource = SourceUtil.toDOM(source);
                // import the fragment
                Node importNode = resource.importNode(fragment, true);
                // get the node
                Node parent = DOMUtil.selectSingleNode(resource, path, this.xpathProcessor);

                // replace?
                if (replacePath != null) {
                    try {
                        Node replaceNode = DOMUtil.getSingleNode(parent, replacePath, this.xpathProcessor);
                        // now get the parent of this node until it is the parent node for insertion
                        while (replaceNode != null && !replaceNode.getParentNode().equals(parent)) {
                           replaceNode = replaceNode.getParentNode();
                        }

                        if (replaceNode != null) {
                            if (overwrite) {
                                if (parent.getNodeType() == Node.DOCUMENT_NODE) {
                                    // replacing of the document element is not allowed
                                    resource = newDocument();
                                    resource.appendChild(resource.importNode(importNode, true));
                                    parent = resource;
                                    replaceNode = resource.importNode(replaceNode, true);
                                } else {
                                    parent.replaceChild(importNode, replaceNode);
                                }
                                message += ", replacing: " + replacePath;
                                if (reinsertPath != null) {
                                    Node insertAt = DOMUtil.getSingleNode(parent, reinsertPath, this.xpathProcessor);
                                    if (insertAt != null) {
                                        while (replaceNode.hasChildNodes()) {
                                            insertAt.appendChild(replaceNode.getFirstChild());
                                        }
                                    } else { // reinsert point null
                                        message = "replace failed, could not find your reinsert path: " + reinsertPath;
                                        resource = null;
                                    }
                                }
                            } else { // overwrite was false
                                message = "replace failed, no overwrite allowed.";
                                resource = null;
                            }
                        } else { // specified replaceNode was not found
                            parent.appendChild(importNode);
                        }
                    } catch (javax.xml.transform.TransformerException sax) {
                        throw new ProcessingException("TransformerException: " + sax, sax);
                    }
                } else { // no replace path, just do an insert at end
                    parent.appendChild(importNode);
                }

            // Create?
            } else if (create) {
                // Create new document
                resource = newDocument();

                // Import the fragment
                Node importNode = resource.importNode(fragment, true);

                if (path.equals("")) {
                    // Parent node is document itself
                    NodeList nodes = importNode.getChildNodes();
                    for (int i = 0; i < nodes.getLength();) {
                        Node node = nodes.item(i);
                        switch (node.getNodeType()) {
                            case Node.ELEMENT_NODE:
                                // May throw exception if fragment has more than one element
                                resource.appendChild(node);
                                break;

                            case Node.DOCUMENT_TYPE_NODE:
                            case Node.PROCESSING_INSTRUCTION_NODE:
                            case Node.COMMENT_NODE:
                                resource.appendChild(node);
                                break;

                            default:
                                // Ignore all other nodes
                                i++;
                                break;
                        }
                    }
                    message = "entire source overwritten";

                } else {
                    // Get the parent node
                    Node parent = DOMUtil.selectSingleNode(resource, path, this.xpathProcessor);
                    // Add a fragment
                    parent.appendChild(importNode);
                    message = "content appended to: " + path;
                }

            // Oops: Document does not exist and create is not allowed.
            } else {
                message = "create not allowed";
                resource = null;/**/
            }


            // Write source
            if (resource != null) {
                resource.normalize();
                // use serializer
                if (localSerializer == null) {
                    localSerializer = this.configuredSerializerName;
                }

                if (localSerializer != null) {
                    // Lookup the Serializer
                    ServiceSelector selector = null;
                    Serializer serializer = null;
                    OutputStream oStream = null;
                    try {
                        selector = (ServiceSelector)manager.lookup(Serializer.ROLE + "Selector");
                        serializer = (Serializer)selector.select(localSerializer);
                        oStream = ws.getOutputStream();
                        serializer.setOutputStream(oStream);
                        DOMStreamer streamer = new DOMStreamer(serializer);
                        streamer.stream(resource);
                    } finally {
                        if (oStream != null) {
View Full Code Here

                this.sendBrokenLinkWarning(target.getSourceURI(),
                    DefaultNotifyingBuilder.getRootCause(pe).getMessage());
            } finally {
                if (output != null && status != -1) {

                    ModifiableSource source = getSource(target);
                    try {
                        pageSize = output.size();
                       
                        if (this.checksumsURI == null || !isSameContent(output, target)) {
                            OutputStream stream = source.getOutputStream();
                            output.setFileOutputStream(stream);
                            output.flush();
                            output.close();
                            pageGenerated(target.getSourceURI(),
                                          target.getAuthlessDestURI(),
View Full Code Here

            n.setMessage("Page Not Available.");
            n.setDescription("The requested resource couldn't be found.");
            n.addExtraDescription(Notifying.EXTRA_REQUESTURI, target.getSourceURI());
            n.addExtraDescription("missing-file", target.getSourceURI());

            ModifiableSource source = getSource(target);
            OutputStream stream = null;
            PrintStream out = null;
            try {
                stream = source.getOutputStream();
                out = new PrintStream(stream);
                Notifier.notify(n, out, "text/html");
            } finally {
                if (out != null) out.close();
                if (stream != null) stream.close();
View Full Code Here

    private void writeChecksumFile() throws Exception {
        Source checksumSource = sourceResolver.resolveURI(checksumsURI);
        if (!(checksumSource instanceof ModifiableSource)) {
            throw new ProcessingException("Checksum file is not Modifiable:" + checksumSource);
        }
        ModifiableSource source = (ModifiableSource) checksumSource;
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(source.getOutputStream()));
        Iterator i = checksums.keySet().iterator();
        while (i.hasNext()){
            String key = (String) i.next();
            String checksum = (String) checksums.get(key);
            writer.println(key + "\t" + checksum);
View Full Code Here

TOP

Related Classes of org.apache.excalibur.source.ModifiableSource

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.