public void listEachEntry(String href, String base, String accept, DataInfo handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { File file = URIUtils.toFile(uri); if (!file.canRead()) { throw XProcException.stepError(12); } if (file.isDirectory()) { for (File f : listAcceptableFiles(file, accept)) { String type; if (f.isDirectory()) { type = null; } else { type = getContentTypeFromName(f.getName()); } handler.list(f.toURI(), type, f.lastModified()); } } else { throw new FileNotFoundException(file.getAbsolutePath() + " is not a directory"); } } else { fallback.listEachEntry(href, base, accept, handler); } }
public void listEachEntry(String href, String base, String accept, DataInfo handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { File file = URIUtils.toFile(uri); if (!file.canRead()) { throw XProcException.stepError(12); } if (file.isDirectory()) { for (File f : listAcceptableFiles(file, accept)) { String type; if (f.isDirectory()) { type = null; } else { type = getContentTypeFromName(f.getName()); } handler.list(f.toURI(), type, f.lastModified()); } } else { throw new FileNotFoundException(file.getAbsolutePath() + " is not a directory"); } } else { fallback.listEachEntry(href, base, accept, handler); } }
public void testListAcceptableFiles() throws IOException { URI dir = store.createList("dir", tmp); final File text = File.createTempFile("test", ".txt", new File(dir)); final File xml = File.createTempFile("test", ".xml", new File(dir)); final File json = File.createTempFile("test", ".json", new File(dir)); final File zip = File.createTempFile("test", ".zip", new File(dir)); assertEquals(4, store.listAcceptableFiles(new File(dir), "*/*").length); assertEquals(Collections.singletonList(text), Arrays.asList(store.listAcceptableFiles(new File(dir), "text/plain"))); assertEquals(Collections.singletonList(xml), Arrays.asList(store.listAcceptableFiles(new File(dir), "application/xml"))); assertEquals(Collections.singletonList(json), Arrays.asList(store.listAcceptableFiles(new File(dir), "application/json"))); assertEquals(Collections.singletonList(zip), Arrays.asList(store.listAcceptableFiles(new File(dir), "application/zip"))); zip.delete(); json.delete(); xml.delete(); text.delete(); new File(dir).delete(); }