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); } } }); return !entries.isEmpty(); } }
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); } } }); return !entries.isEmpty(); } }
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)); } catch (FileNotFoundException e) { // ignore it, we tried to recurse through a file that wasn't a directory } entries.add(entry); } }); return entries; } }
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)); } catch (FileNotFoundException e) { // ignore it, we tried to recurse through a file that wasn't a directory } entries.add(entry); } }); return entries; } }
private long readLastModified(URI uri) { if (srcManifest.containsKey(origHref)) { // If the document to be zipped is in the set of source documents, // don't try to read its timestamp from the disk or the web. // Use "now". Date date = new Date(); return date.getTime(); } final List<Long> list = new ArrayList<Long>(1); DataStore store = runtime.getDataStore(); try { store.infoEntry(uri.toASCIIString(), uri.toASCIIString(), "*/*", new DataInfo() { public void list(URI id, String media, long lastModified) throws IOException { list.add(lastModified); } }); } catch (IOException e) { throw new XProcException(e); } if (list.size() == 1) { return list.get(0); } else { return -1; } } }
private long readLastModified(URI uri) { if (srcManifest.containsKey(origHref)) { // If the document to be zipped is in the set of source documents, // don't try to read its timestamp from the disk or the web. // Use "now". Date date = new Date(); return date.getTime(); } final List<Long> list = new ArrayList<Long>(1); DataStore store = runtime.getDataStore(); try { store.infoEntry(uri.toASCIIString(), uri.toASCIIString(), "*/*", new DataInfo() { public void list(URI id, String media, long lastModified) throws IOException { list.add(lastModified); } }); } catch (IOException e) { throw new XProcException(e); } if (list.size() == 1) { return list.get(0); } else { return -1; } } }
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)); fallback(node, href); } else { logger.trace(MessageFormatter.nodeMessage(node, "XInclude text parse: " + href)); matcher.addText(text); } } }); } catch (Exception e) { logger.debug("XInclude read text failed"); mostRecentException = e; fallback(node, href); } }
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)); fallback(node, href); } else { logger.trace(MessageFormatter.nodeMessage(node, "XInclude text parse: " + href)); matcher.addText(text); } } }); } catch (Exception e) { logger.debug("XInclude read text failed"); mostRecentException = e; fallback(node, href); } }
return null; } else { DataStore store = runtime.getDataStore(); return store.writeEntry(href, base, media, new DataWriter() { public void store(OutputStream outstr) throws IOException {
return null; } else { DataStore store = runtime.getDataStore(); return store.writeEntry(href, base, media, new DataWriter() { public void store(OutputStream outstr) throws IOException {
private void doFile(String href, String base) { try { DataStore store = runtime.getDataStore(); store.readEntry(href, base, "application/xml, text/xml, */*", overrideContentType, new DataReader() { public void load(URI id, String contentType, InputStream bodyStream, long len)
final DataStore store = runtime.getDataStore(); store.readEntry(href.getString(), href.getBaseURI().toASCIIString(), "*/*", null, new DataReader() { public void load(URI id, String media, final InputStream src, long len)
final DataStore store = runtime.getDataStore(); String base = href.getBaseURI().toASCIIString(); store.readEntry(href.getString(), base, "*/*", null, new DataReader() {
DataStore store = runtime.getDataStore(); String base = zipURI.toASCIIString(); store.readEntry(zipFn, base, ACCEPT_ZIP, null, new DataReader() {
DataStore store = runtime.getDataStore(); String base = zipURI.toASCIIString(); store.readEntry(zipFn, base, ACCEPT_ZIP, null, new DataReader() {
public void run() throws SaxonApiException { super.run(); if (runtime.getSafeMode()) { throw XProcException.dynamicError(21); } RuntimeValue href = getOption(_href); TreeWriter tree = new TreeWriter(runtime); 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()); } tree.addEndElement(); tree.endDocument(); result.write(tree.getResult()); } }
DataStore store = runtime.getDataStore(); String base = href.getBaseURI().toASCIIString(); try {
private void performDelete(RuntimeValue href, String base, boolean recursive, boolean fail_on_error) { DataStore store = runtime.getDataStore(); if (recursive) { try { for (String entry : getAllEntries(href.getString(), base)) { store.deleteEntry(entry, entry); } } catch (FileNotFoundException e) { if (fail_on_error) { throw new XProcException(step.getNode(), "Cannot delete: file does not exist", e); } } catch (IOException e) { if (fail_on_error) { throw new XProcException(step.getNode(), e); } } } try { store.deleteEntry(href.getString(), base); } catch (FileNotFoundException e) { if (fail_on_error) { throw new XProcException(step.getNode(), "Cannot delete: file does not exist", e); } } catch (IOException e) { if (fail_on_error) { throw new XProcException(step.getNode(), e); } } }
public void run() throws SaxonApiException { super.run(); if (runtime.getSafeMode()) { throw XProcException.dynamicError(21); } RuntimeValue href = getOption(_href); TreeWriter tree = new TreeWriter(runtime); 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()); } tree.addEndElement(); tree.endDocument(); result.write(tree.getResult()); } }
private void performDelete(RuntimeValue href, String base, boolean recursive, boolean fail_on_error) { DataStore store = runtime.getDataStore(); if (recursive) { try { for (String entry : getAllEntries(href.getString(), base)) { store.deleteEntry(entry, entry); } } catch (FileNotFoundException e) { if (fail_on_error) { throw new XProcException(step.getNode(), "Cannot delete: file does not exist", e); } } catch (IOException e) { if (fail_on_error) { throw new XProcException(step.getNode(), e); } } } try { store.deleteEntry(href.getString(), base); } catch (FileNotFoundException e) { if (fail_on_error) { throw new XProcException(step.getNode(), "Cannot delete: file does not exist", e); } } catch (IOException e) { if (fail_on_error) { throw new XProcException(step.getNode(), e); } } }