List of usage examples for org.apache.commons.vfs2 FileObject exists
boolean exists() throws FileSystemException;
From source file:org.obiba.opal.core.service.SubjectProfileServiceImpl.java
private void ensureUserHomeExists(String username) { try {/*from www . j a va 2 s . c o m*/ if (!opalRuntime.hasFileSystem()) return; FileObject home = opalRuntime.getFileSystem().getRoot().resolveFile("/home/" + username); if (!home.exists()) { log.info("Creating user home: /home/{}", username); home.createFolder(); } } catch (FileSystemException e) { log.error("Failed creating user home.", e); } }
From source file:org.obiba.opal.shell.commands.DecryptCommand.java
private void decryptFiles(Iterable<String> encryptedFilePaths, FileObject outputDir) { for (String path : encryptedFilePaths) { try {/*from www . jav a 2 s . c om*/ FileObject encryptedFile = getEncryptedFile(path); if (encryptedFile.exists()) { getShell().printf("Decrypting input file %s\n", path); decryptFile(encryptedFile, outputDir); } else { getShell().printf("Skipping non-existent input file %s\n", path); } } catch (IOException ex) { getShell().printf("Unexpected decrypt exception: %s, skipping\n", ex.getMessage()); ex.printStackTrace(System.err); } } }
From source file:org.obiba.opal.shell.commands.EncryptCommand.java
private void encryptFiles(Iterable<String> decryptedFilePaths, FileObject outputDir) { for (String path : decryptedFilePaths) { try {//from ww w . j ava2s . co m FileObject decryptedFile = getFile(path); if (decryptedFile.exists()) { getShell().printf("Decrypting input file %s\n", path); encryptFile(decryptedFile, outputDir); } else { getShell().printf("Skipping non-existent input file %s\n", path); } } catch (IOException ex) { getShell().printf("Unexpected decrypt exception: %s, skipping\n", ex.getMessage()); ex.printStackTrace(System.err); } } }
From source file:org.obiba.opal.shell.commands.ImportCommand.java
private List<FileObject> resolveFiles(Iterable<String> filePaths) { List<FileObject> files = new ArrayList<>(); FileObject file; for (String filePath : filePaths) { try {/*from w w w.ja v a 2s .c o m*/ file = getFileToImport(filePath); if (file == null || !file.exists()) { getShell().printf("'%s' does not exist\n", filePath); continue; } addFile(files, file); } catch (FileSystemException e) { getShell().printf("Cannot resolve the following path : %s, skipping import..."); log.warn("Cannot resolve the following path : {}, skipping import...", e); } } return files; }
From source file:org.obiba.opal.shell.commands.ReportCommand.java
private void deleteFileSilently(FileObject file) { try {// w ww.j ava 2 s . c om if (file.exists()) { file.delete(); } } catch (FileSystemException ex) { log.error("Could not delete file: {}", file.getName().getPath()); } }
From source file:org.obiba.opal.web.FilesResource.java
@GET @Path("/_meta/{path:.*}") @NoAuthorization//from w ww .j a va2 s. c o m public Response getFileDetails(@PathParam("path") String path) throws FileSystemException { FileObject file = resolveFileInFileSystem(path); return file.exists() ? file.getType() == FileType.FILE ? getFileDetails(file) : getFolderDetails(file) : getPathNotExistResponse(path); }
From source file:org.obiba.opal.web.FilesResource.java
@GET @Path("/{path:.*}") @AuthenticatedByCookie/*from www .j a v a 2s.co m*/ public Response getFile(@PathParam("path") String path, @QueryParam("file") List<String> children) throws IOException { FileObject file = resolveFileInFileSystem(path); return file.exists() ? file.getType() == FileType.FILE ? getFile(file) : getFolder(file, children) : getPathNotExistResponse(path); }
From source file:org.obiba.opal.web.FilesResource.java
/** * Copy or move a file to the current folder. * * @param path/*from ww w . j a v a 2 s . c om*/ * @param action 'copy' (default) or 'move' * @param file * @return * @throws IOException */ @PUT @Path("/{path:.*}") @AuthenticatedByCookie public Response updateFile(@PathParam("path") String destinationPath, @QueryParam("action") @DefaultValue("copy") String action, @QueryParam("file") List<String> sourcesPath) throws IOException { // destination check FileObject destinationFile = resolveFileInFileSystem(destinationPath); if (!destinationFile.exists()) getPathNotExistResponse(destinationPath); if (!destinationFile.isWriteable()) return Response.status(Status.FORBIDDEN).entity("Destination file is not writable: " + destinationPath) .build(); // sources check if (sourcesPath == null || sourcesPath.isEmpty()) return Response.status(Status.BAD_REQUEST).entity("Source file is missing").build(); // filter actions: copy, move if ("move".equals(action.toLowerCase())) { return moveTo(destinationFile, sourcesPath); } if ("copy".equals(action.toLowerCase())) { return copyFrom(destinationFile, sourcesPath); } return Response.status(Status.BAD_REQUEST).entity("Unexpected file action: " + action).build(); }
From source file:org.obiba.opal.web.FilesResource.java
private Response moveTo(FileObject destinationFolder, Iterable<String> sourcesPath) throws IOException { // destination check String destinationPath = destinationFolder.getName().getPath(); if (destinationFolder.getType() != FileType.FOLDER) return Response.status(Status.BAD_REQUEST).entity("Destination must be a folder: " + destinationPath) .build();//from w ww . j a v a2s .com // sources check for (String sourcePath : sourcesPath) { FileObject sourceFile = resolveFileInFileSystem(sourcePath); if (!sourceFile.exists()) getPathNotExistResponse(sourcePath); if (!sourceFile.isReadable()) { return Response.status(Status.FORBIDDEN).entity("Source file is not readable: " + sourcePath) .build(); } if (!sourceFile.isWriteable()) { return Response.status(Status.FORBIDDEN).entity("Source file cannot be moved: " + sourcePath) .build(); } } // do action for (String sourcePath : sourcesPath) { FileObject sourceFile = resolveFileInFileSystem(sourcePath); FileObject destinationFile = resolveFileInFileSystem( destinationPath + "/" + sourceFile.getName().getBaseName()); sourceFile.moveTo(destinationFile); } return Response.ok().build(); }
From source file:org.obiba.opal.web.FilesResource.java
private Response copyFrom(FileObject destinationFolder, Iterable<String> sourcesPath) throws IOException { // destination check String destinationPath = destinationFolder.getName().getPath(); if (destinationFolder.getType() != FileType.FOLDER) return Response.status(Status.BAD_REQUEST).entity("Destination must be a folder: " + destinationPath) .build();/*ww w. ja va 2 s. c om*/ // sources check for (String sourcePath : sourcesPath) { FileObject sourceFile = resolveFileInFileSystem(sourcePath); if (!sourceFile.exists()) getPathNotExistResponse(sourcePath); if (!sourceFile.isReadable()) { return Response.status(Status.FORBIDDEN).entity("Source file is not readable: " + sourcePath) .build(); } } // do action for (String sourcePath : sourcesPath) { FileObject sourceFile = resolveFileInFileSystem(sourcePath); FileObject destinationFile = resolveFileInFileSystem( destinationPath + "/" + sourceFile.getName().getBaseName()); FileSelector selector = sourceFile.getType() == FileType.FOLDER ? Selectors.SELECT_ALL : Selectors.SELECT_SELF; destinationFile.copyFrom(sourceFile, selector); } return Response.ok().build(); }