List of usage examples for org.apache.commons.vfs2 FileObject getChildren
FileObject[] getChildren() throws FileSystemException;
From source file:org.helios.ember.api.SFTPService.java
/** * Returns a file listing for the current SFTP context. If there is no current context, will list the root. * @param request The Http request//from www. j a va2 s . c om * @param path The path to list * @return A direcotry listing */ @GET @Produces({ "application/json" }) @Path("/list/{path}") public FileObjectWrapperCollection listPath(@Context HttpServletRequest request, @PathParam("path") String path) { if (path == null || path.trim().isEmpty()) { path = "."; } HttpSession session = request.getSession(); boolean newSession = session.isNew(); SessionLogin sessionLogin = (SessionLogin) securityContext.getUserPrincipal(); if (newSession) { session.setAttribute("auth", sessionLogin); } try { FileObject fo = getFileObject(sessionLogin, path); return FileObjectWrapper.wrap(fo, fo.getChildren()); } catch (FileSystemException e) { log.error("Failed to list into [" + path + "]", e); throw new WebApplicationException(e, new ResponseBuilderImpl().status(Status.INTERNAL_SERVER_ERROR).entity( new GenericEntity<String>("{err:'Failed to list into " + path + "'}", String.class)) .build()); } }
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
public List<String> getChildren(String path) throws RepositoryException { try {/*from www . j av a 2 s . co m*/ if (!path.endsWith(JCR_CONTENT_SUFFIX)) { FileObject fileObject = getFile(path); if (fileObject.getType() == FileType.FILE) { return JCR_CONTENT_LIST; } else if (fileObject.getType() == FileType.FOLDER) { FileObject[] files = fileObject.getChildren(); if (files.length > 0) { List<String> children = new LinkedList<String>(); for (FileObject object : files) { if (getSupportedNodeTypes().contains(getDataType(object))) { children.add(object.getName().getBaseName()); } } return children; } else { return Collections.emptyList(); } } else { if (fileObject.exists()) { logger.warn("Found non file or folder entry at path {}, maybe an alias. VFS file type: {}", fileObject, fileObject.getType()); } else { throw new PathNotFoundException(path); } } } } catch (FileSystemException e) { logger.error("Cannot get node children", e); } return Collections.emptyList(); }
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
@Override public List<ExternalData> getChildrenNodes(String path) throws RepositoryException { try {//from w ww . ja v a 2 s .c o m if (!path.endsWith(JCR_CONTENT_SUFFIX)) { FileObject fileObject = getFile(path); if (fileObject.getType() == FileType.FILE) { final FileContent content = fileObject.getContent(); return Collections.singletonList(getFileContent(content)); } else if (fileObject.getType() == FileType.FOLDER) { fileObject.refresh(); //in case of folder, refresh because it could be changed external FileObject[] files = fileObject.getChildren(); if (files.length > 0) { List<ExternalData> children = new LinkedList<ExternalData>(); for (FileObject object : files) { if (getSupportedNodeTypes().contains(getDataType(object))) { children.add(getFile(object)); if (object.getType() == FileType.FILE) { children.add(getFileContent(object.getContent())); } } } return children; } else { return Collections.emptyList(); } } else { if (fileObject.exists()) { logger.warn("Found non file or folder entry at path {}, maybe an alias. VFS file type: {}", fileObject, fileObject.getType()); } else { throw new PathNotFoundException(path); } } } } catch (FileSystemException e) { logger.error("Cannot get node children", e); } return Collections.emptyList(); }
From source file:org.jfunktor.common.vfs.VirtualFileSystem.java
/** * Lists the contents of a given file location * It can be a URL to any location which is supported by the VFS * @param location//www .java 2 s . c o m * @return */ public static List<String> listContents(URL location) throws FileSystemException { ArrayList<String> contents = new ArrayList<>(); FileObject obj = VFS.getManager().resolveFile(location.toString()); FileObject[] children = obj.getChildren(); if (children != null && children.length > 0) { for (int i = 0; i < children.length; i++) { contents.add(children[i].getName().getBaseName()); } } return contents; }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * This function will copy one directory to another one. If the destination base directory does not exist, it will be * created./* w w w . j a v a 2 s. c o m*/ * * @param source * The source directory. * @param destination * The destination directory. * @param overwrite * If set, always overwrite existing and newer files */ public static void copyDirectoryToDirectory(final FileObject source, final FileObject destination, final boolean overwrite) throws IOException { if (!FileType.FOLDER.equals(source.getType())) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.io.VFSUtilities.3") + source.getURL()); //$NON-NLS-1$ if (destination.exists()) { if (!FileType.FOLDER.equals(destination.getType())) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.io.VFSUtilities.4") + destination.getURL()); //$NON-NLS-1$ } else { KalypsoCommonsDebug.DEBUG.printf("Creating directory '%s'...%", destination.getName()); //$NON-NLS-1$ destination.createFolder(); } final FileObject[] children = source.getChildren(); for (final FileObject child : children) { if (FileType.FILE.equals(child.getType())) { /* Need a destination file with the same name as the source file. */ final FileObject destinationFile = destination.resolveFile(child.getName().getBaseName()); /* Copy ... */ copyFileTo(child, destinationFile, overwrite); } else if (FileType.FOLDER.equals(child.getType())) { /* Need the same name for destination directory, as the source directory has. */ final FileObject destinationDir = destination.resolveFile(child.getName().getBaseName()); /* Copy ... */ KalypsoCommonsDebug.DEBUG.printf("Copy directory %s to %s ...", child.getName(), //$NON-NLS-1$ destinationDir.getName()); copyDirectoryToDirectory(child, destinationDir, overwrite); } else { KalypsoCommonsDebug.DEBUG.printf("Could not determine the file type ...%n"); //$NON-NLS-1$ } } }
From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java
private FileObject[] find2dFiles(final FileObject remoteWorking) throws IOException { final List<FileObject> resultList = new ArrayList<>(); if (remoteWorking == null) return null; final FileObject[] children = remoteWorking.getChildren(); for (final FileObject child : children) { final FileName childName = child.getName(); final String baseName = childName.getBaseName(); if (FilenameUtils.wildcardMatch(baseName, "*.2d") || FilenameUtils.wildcardMatch(baseName, "*.2d.zip")) //$NON-NLS-1$ //$NON-NLS-2$ {/*w w w . j a v a 2 s.c o m*/ resultList.add(child); } } return resultList.toArray(new FileObject[resultList.size()]); }
From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java
private FileObject findTelemacResultFile(final FileObject resultDir) { if (resultDir == null) return null; FileObject[] children = null; try {//from w w w . java 2 s. co m children = resultDir.getChildren(); } catch (FileSystemException e) { e.printStackTrace(); } for (final FileObject child : children) { final FileName childName = child.getName(); final String baseName = childName.getBaseName(); if (FilenameUtils.wildcardMatch(baseName, "*res*.slf*")) //$NON-NLS-1$ { return child; } } final IPath path = ResultMeta1d2dHelper.getSavedPathFromResultData(m_calcUnitMeta, ResultMeta1d2dHelper.TELEMAC_RAW_DATA_META_NAME); if (path != null) { try { return resultDir.getParent().resolveFile(path.toOSString()); } catch (final Exception e) { m_geoLog.formatLog(IStatus.INFO, CODE_RUNNING_FINE, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ResultManager.15"), //$NON-NLS-1$ resultDir.getName().getBaseName()); return null; } } return null; }
From source file:org.kalypso.kalypsomodel1d2d.sim.SWANKalypsoSimulation.java
private void copyFilesToWorkDir(final FileObject tmpDir, final FileObject targetDir) throws FileSystemException, IOException { final List<FileObject> lListFilesToRemove = new ArrayList<>(); final Set<String> exclusionFileNamesToMove = new HashSet<>(); exclusionFileNamesToMove.add(EXECUTE_RESPONSE_XML); // copy input files for (int i = 0; i < tmpDir.getChildren().length; i++) { final FileObject actFile = tmpDir.getChildren()[i]; if (!exclusionFileNamesToMove.contains(actFile.getName().getBaseName().toLowerCase().trim())) { VFSUtilities.copyFileTo(actFile, targetDir); lListFilesToRemove.add(actFile); }/* w ww . jav a 2 s . c om*/ } for (final FileObject actFile : lListFilesToRemove) { actFile.delete(); } }
From source file:org.kalypso.kalypsomodel1d2d.sim.TelemacKalypsoSimulation.java
private void copyFilesToWorkDir(final FileObject tmpDir, final FileObject targetDir) throws FileSystemException, IOException { List<FileObject> lListFilesToRemove = new ArrayList<FileObject>(); Set<String> exclusionFileNamesToMove = new HashSet<String>(); exclusionFileNamesToMove.add(EXECUTE_RESPONSE_XML); // copy input files for (int i = 0; i < tmpDir.getChildren().length; i++) { FileObject actFile = tmpDir.getChildren()[i]; if (!exclusionFileNamesToMove.contains(actFile.getName().getBaseName().toLowerCase().trim())) { VFSUtilities.copyFileTo(actFile, targetDir); lListFilesToRemove.add(actFile); }//from w w w . j av a 2s .c o m } for (Iterator<FileObject> iterator = lListFilesToRemove.iterator(); iterator.hasNext();) { FileObject actFile = iterator.next(); actFile.delete(); } }
From source file:org.luwrain.app.commander.InfoAndProperties.java
static public long getTotalSize(FileObject fileObj) throws org.apache.commons.vfs2.FileSystemException { NullCheck.notNull(fileObj, "fileObj"); if (!fileObj.isFolder() && !fileObj.isFile()) return 0; if (fileObj instanceof org.apache.commons.vfs2.provider.local.LocalFile && java.nio.file.Files.isSymbolicLink(java.nio.file.Paths.get(fileObj.getName().getPath()))) return 0; if (!fileObj.isFolder()) return fileObj.getContent().getSize(); long res = 0; for (FileObject child : fileObj.getChildren()) res += getTotalSize(child);/* w w w . ja va2s . co m*/ return res; }