protected File findOwlFile(File fileOrDir) { if (fileOrDir.isFile()) { return fileOrDir; } File[] files = fileOrDir.listFiles(); if (files == null) { return null; } for (File child : files) { if (child.isDirectory()) { File found = findOwlFile(child); if (found != null) { return found; } } else if (child.getName().toLowerCase().endsWith(".owl")) { return child; } } return null; }
@Override public String guessDocumentIRIFromPackage(File file) throws IOException, ZipException { ZipFile zipped = new ZipFile(file); if (zipped.isValidZipFile()) { File tempDir = Files.createTempDir(); try { LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath()); zipped.extractAll(tempDir.getAbsolutePath()); File owlFile = findOwlFile(tempDir); return guessDocumentIRIFromFile(owlFile); } finally { FileUtils.deleteDirectory(tempDir); } } else { if (file.isDirectory()) { file = findOwlFile(file); } return guessDocumentIRIFromFile(file); } }
@Override public void writePackage(File file, IRI documentIRI, Authorizations authorizations) throws Exception { if (!file.exists()) { throw new VisalloException("OWL file does not exist: " + file.getAbsolutePath()); } if (!file.isFile()) { throw new VisalloException("OWL file is not a file: " + file.getAbsolutePath()); } ZipFile zipped = new ZipFile(file); if (zipped.isValidZipFile()) { File tempDir = Files.createTempDir(); try { LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath()); zipped.extractAll(tempDir.getAbsolutePath()); File owlFile = findOwlFile(tempDir); importFile(owlFile, documentIRI, authorizations); } finally { FileUtils.deleteDirectory(tempDir); } } else { importFile(file, documentIRI, authorizations); } }
File owlFile = findOwlFile(new File(dir)); if (owlFile == null) { throw new VisalloResourceNotFoundException(