diff --git a/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java b/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java index a77eadd0..de3b6624 100644 --- a/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java +++ b/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java @@ -14,6 +14,7 @@ import com.xmlcalabash.util.MessageFormatter; import com.xmlcalabash.util.TreeWriter; import com.xmlcalabash.util.S9apiUtils; +import com.xmlcalabash.util.URIUtils; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -97,7 +98,7 @@ public void run() throws SaxonApiException { tree.startDocument(step.getNode().getBaseURI()); if ("file".equals(uri.getScheme())) { - File file = new File(uri.getPath()); + File file = URIUtils.toFile(uri); if (!file.exists()) { if (failOnError) { diff --git a/src/main/java/com/xmlcalabash/extensions/fileutils/Tempfile.java b/src/main/java/com/xmlcalabash/extensions/fileutils/Tempfile.java index 36bb0713..a30932c2 100644 --- a/src/main/java/com/xmlcalabash/extensions/fileutils/Tempfile.java +++ b/src/main/java/com/xmlcalabash/extensions/fileutils/Tempfile.java @@ -9,6 +9,7 @@ import com.xmlcalabash.runtime.XAtomicStep; import com.xmlcalabash.model.RuntimeValue; import com.xmlcalabash.util.TreeWriter; +import com.xmlcalabash.util.URIUtils; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -79,7 +80,7 @@ public void run() throws SaxonApiException { if (!"file".equals(uri.getScheme())) { throw new XProcException(step.getNode(), "Only file: scheme URIs are supported by the tempfile step."); } else { - file = new File(uri.getPath()); + file = URIUtils.toFile(uri); } if (!file.isDirectory()) { diff --git a/src/main/java/com/xmlcalabash/io/FileDataStore.java b/src/main/java/com/xmlcalabash/io/FileDataStore.java index 05d367c1..a44de29d 100644 --- a/src/main/java/com/xmlcalabash/io/FileDataStore.java +++ b/src/main/java/com/xmlcalabash/io/FileDataStore.java @@ -21,6 +21,7 @@ package com.xmlcalabash.io; import com.xmlcalabash.core.XProcException; +import com.xmlcalabash.util.URIUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,7 +68,7 @@ public URI writeEntry(String href, String base, String media, URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); String suffix = getFileSuffixFromType(media); if (file.isDirectory() || uri.getPath().endsWith("/")) { if (!file.isDirectory() && !file.mkdirs()) { @@ -114,7 +115,7 @@ public void readEntry(String href, String base, String accept, URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); String type = getContentTypeFromName(file.getName()); if (overrideContentType != null) { type = overrideContentType; @@ -136,7 +137,7 @@ public void infoEntry(String href, String base, String accept, URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); String type; if (file.isFile()) { type = getContentTypeFromName(file.getName()); @@ -157,7 +158,7 @@ public void listEachEntry(String href, String base, String accept, URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); if (!file.canRead()) { throw XProcException.stepError(12); @@ -186,7 +187,7 @@ public URI createList(String href, String base) URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); if (file.isDirectory()) { return file.toURI(); } else if (file.exists()) { @@ -209,7 +210,7 @@ public void deleteEntry(String href, String base) URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { - File file = new File(uri); + File file = URIUtils.toFile(uri); if (!file.exists()) { throw new FileNotFoundException(file.toURI().toASCIIString()); } else if (!file.delete()) { diff --git a/src/main/java/com/xmlcalabash/util/URIUtils.java b/src/main/java/com/xmlcalabash/util/URIUtils.java index e5221a2c..a25da728 100644 --- a/src/main/java/com/xmlcalabash/util/URIUtils.java +++ b/src/main/java/com/xmlcalabash/util/URIUtils.java @@ -100,4 +100,16 @@ public static URI makeAbsolute(String localFn) { URI cwd = cwdAsURI(); return cwd.resolve(encode(localFn)); } + + public static File toFile(URI uri) { + if (!"file".equalsIgnoreCase(uri.getScheme())) { + throw new IllegalStateException("Expecting a file URI: " + uri.toASCIIString()); + } + + if (uri.getAuthority() != null && uri.getAuthority().length() > 0) { + return new File("//"+uri.getAuthority()+uri.getPath()); + } else { + return new File(uri.getPath()); + } + } }