Package com.xmlcalabash.io

Examples of com.xmlcalabash.io.DataStore


    }

    private List<String> getAllEntries(final String href, String base)
            throws MalformedURLException, FileNotFoundException, IOException {
        final List<String> entries = new ArrayList<String>();
        DataStore store = runtime.getDataStore();
        store.listEachEntry(href, base, "*/*", new DataStore.DataInfo() {
            public void list(URI id, String media, long lastModified)
                    throws IOException {
                String entry = id.toASCIIString();
                try {
                    entries.addAll(getAllEntries(entry, entry));
View Full Code Here


        }

        RuntimeValue href = getOption(_href);

        try {
            final DataStore store = runtime.getDataStore();
            String base = href.getBaseURI().toASCIIString();
            store.readEntry(href.getString(), base, "*/*", null, new DataReader() {
                public void load(URI id, String media, final InputStream src, long len)
                        throws IOException {
                    RuntimeValue target = getOption(_target);
                    URI uri = store.writeEntry(target.getString(), target.getBaseURI().toASCIIString(), media, new DataWriter() {
                        public void store(OutputStream dst) throws IOException {
                            byte[] buffer = new byte[bufsize];
                            int read = src.read(buffer, 0, bufsize);
                            while (read >= 0) {
                                dst.write(buffer, 0, read);
                                read = src.read(buffer, 0, bufsize);
                            }
                        }
                    });

                    TreeWriter tree = new TreeWriter(runtime);
                    tree.startDocument(step.getNode().getBaseURI());
                    tree.addStartElement(XProcConstants.c_result);
                    tree.startContent();

                    tree.addText(uri.toASCIIString());

                    tree.addEndElement();
                    tree.endDocument();

                    result.write(tree.getResult());
                }
            });

            store.deleteEntry(href.getString(), base);

        } catch (FileNotFoundException fnfe) {
            URI uri = href.getBaseURI().resolve(href.getString());
            throw new XProcException(step.getNode(), "Cannot copy: file does not exist: " + uri.toASCIIString());
        } catch (IOException ioe) {
View Full Code Here

        String href = getOption(_href).getString();
        String base = getOption(_href).getBaseURI().toASCIIString();

        try {
            DataStore store = runtime.getDataStore();
            URI id = store.writeEntry(href, base, contentType, new DataWriter() {
                public void store(OutputStream out) throws IOException {
                    try {
                        provider.format(source.read(),out,contentType);
                    } catch(SaxonApiException e) {
                        throw new IOException(e);
View Full Code Here

        tree.startDocument(step.getNode().getBaseURI());
        tree.addStartElement(XProcConstants.c_result);
        tree.startContent();

        try {
            DataStore store = runtime.getDataStore();
            URI uri = store.createList(href.getString(), href.getBaseURI().toASCIIString());
            tree.addText(uri.toASCIIString());
        } catch (FileNotFoundException e) {
            throw new XProcException(step.getNode(), "Cannot mkdir: file exists: " + href.getString());
        } catch (IOException e) {
            throw new XProcException(step.getNode(), "Mkdir failed for: " + href.getString());
View Full Code Here

            charset = getOption(_charset).getString();
        }

        try {
            final DatatypeFactory dfactory = DatatypeFactory.newInstance();
            DataStore store = runtime.getDataStore();
            String base = zipURI.toASCIIString();
            store.readEntry(zipFn, base, ACCEPT_ZIP, null, new DataReader() {
                public void load(URI id, String media, InputStream content,
                        long len) throws IOException {
                    unzip(dfactory, id.toASCIIString(), content);
                }
            });
View Full Code Here

        tree.addStartElement(c_directory);
        tree.addAttribute(_name, getName(uri));
        tree.addAttribute(XProcConstants.xml_base, uri.toASCIIString());
        tree.startContent();

        final DataStore store = runtime.getDataStore();
        try {
            store.listEachEntry(path, "file:///", "*/*", new DataInfo() {
                public void list(URI id, String media, long lastModified) throws IOException {
                    boolean use = true;
                    String filename = getName(id);

                    logger.trace(MessageFormatter.nodeMessage(step.getNode(), "name: " + filename));
View Full Code Here

  }

  boolean isFile(URI id) throws IOException {
    final String entry = id.toASCIIString();
    final List<String> entries = new ArrayList<String>();
    DataStore store = runtime.getDataStore();
    store.infoEntry(entry, entry, "*/*", new DataInfo() {
      public void list(URI id, String media, long lastModified)
          throws IOException {
        if (media != null) {
          entries.add(media);
        }
View Full Code Here

        tree.startDocument(step.getNode().getBaseURI());
        tree.addStartElement(XProcConstants.c_result);
        tree.startContent();

        try {
            DataStore store = runtime.getDataStore();
            String base = href.getBaseURI().toASCIIString();
            try {
                store.infoEntry(href.getString(), base, "*/*", new DataInfo() {
                    public void list(URI id, String media, long lastModified)
                            throws IOException {
                        // file already exists
                        tree.addText(id.toASCIIString());
                    }
                });
            } catch (FileNotFoundException e) {
                URI uri = store.writeEntry(href.getString(), base, "text/plain", new DataWriter() {
                    public void store(OutputStream content) throws IOException {
                        // empty file
                    }
                });
                tree.addText(uri.toASCIIString());
View Full Code Here

        tree.startDocument(step.getNode().getBaseURI());
        tree.addStartElement(XProcConstants.c_result);
        tree.startContent();

        try {
            DataStore store = runtime.getDataStore();
            store.readEntry(href.getString(), href.getBaseURI().toASCIIString(), "text/*, */*", null, new DataReader() {
                public void load(URI id, String media, InputStream content, long len)
                        throws IOException {
                    Reader rdr = new InputStreamReader(content);
                    BufferedReader brdr = new BufferedReader(rdr);
                    try {
View Full Code Here

    private void readText(final String href, final XdmNode node,
            String base, final XPointer xpointer, final TreeWriter matcher) {
        logger.trace("XInclude read text: " + href + " (" + base + ")");

        DataStore store = runtime.getDataStore();
        try {
            store.readEntry(href, base, "text/plain, text/*, */*", null, new DataReader() {
                public void load(URI id, String media, InputStream content,
                        long len) throws IOException {
                    String text = readText(node, xpointer, media, content, len);
                    if (text == null) {
                        logger.trace(MessageFormatter.nodeMessage(node, "XInclude text parse failed: " + href));
View Full Code Here

TOP

Related Classes of com.xmlcalabash.io.DataStore

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.