List of usage examples for org.apache.commons.vfs FileObject getChildren
public FileObject[] getChildren() throws FileSystemException;
From source file:org.bibalex.gallery.storage.BAGStorage.java
public static List<String> listChildren(String dirUrlStr, FileType childrenType, int timeout) throws BAGException { try {//w w w. j ava 2 s .c o m List<String> result; if (new URI(dirUrlStr).getScheme().startsWith("http")) { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeout); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); try { result = listChildrenApacheHttpd(dirUrlStr, childrenType, httpClient); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpClient.getConnectionManager().shutdown(); } } else { result = new ArrayList<String>(); FileSystemManager fsMgr = VFS.getManager(); FileObject dir = fsMgr.resolveFile(dirUrlStr); final FileObject[] children = dir.getChildren(); for (final FileObject child : children) { if ((childrenType == FileType.FILE_OR_FOLDER) || (child.getType() == childrenType)) { result.add(child.getName().getBaseName()); } } } // TODO define a comparator that orders the files properly as in // http://forums.sun.com/thread.jspa?threadID=5289401 Collections.sort(result); return result; } catch (FileSystemException e) { throw new BAGException(e); } catch (URISyntaxException e) { throw new BAGException(e); } }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Gets a directory listing/*from w w w . j ava 2 s .c om*/ * * @param file the directory to be listed * @return an array of files this directory contains, may be empty but not null */ private FileObject[] getDirectoryList(FileObject file) throws FileSystemException { FileObject[] list = file.getChildren(); if (list == null) { return new FileObject[0]; } VFSUtil.sortFiles(list); return list; }
From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileSystem.java
/** * Import the given file with the name relative to the given root. * * @param _fo file object//from w w w . ja va2 s. c o m * @param _root root file object * @throws FileSystemException if file object could not be imported */ void toRamFileObject(final FileObject _fo, final FileObject _root) throws FileSystemException { final RamFileObject memFo = (RamFileObject) this .resolveFile(_fo.getName().getPath().substring(_root.getName().getPath().length())); if (_fo.getType().hasChildren()) { // Create Folder memFo.createFolder(); // Import recursively final FileObject[] fos = _fo.getChildren(); for (int i = 0; i < fos.length; i++) { final FileObject child = fos[i]; this.toRamFileObject(child, _root); } } else if (_fo.getType().equals(FileType.FILE)) { // Read bytes try { final InputStream is = _fo.getContent().getInputStream(); try { final OutputStream os = new BufferedOutputStream(memFo.getOutputStream(), 512); int i; while ((i = is.read()) != -1) { os.write(i); } os.flush(); os.close(); } finally { try { is.close(); } catch (final IOException e) { // ignore on close exception } } } catch (final IOException e) { throw new FileSystemException(e.getClass().getName() + " " + e.getMessage()); } } else { throw new FileSystemException("File is not a folder nor a file " + memFo); } }
From source file:org.jahia.configuration.configurators.JahiaGlobalConfigurator.java
public FileObject findVFSFile(String parentPath, String fileMatchingPattern) { Pattern matchingPattern = Pattern.compile(fileMatchingPattern); try {//from ww w . ja va 2 s . c o m FileSystemManager fsManager = VFS.getManager(); FileObject parentFileObject = fsManager.resolveFile(parentPath); FileObject[] children = parentFileObject.getChildren(); for (FileObject child : children) { Matcher matcher = matchingPattern.matcher(child.getName().getBaseName()); if (matcher.matches()) { return child; } } } catch (FileSystemException e) { logger.debug("Couldn't find file matching pattern " + fileMatchingPattern + " at path " + parentPath); } return null; }
From source file:org.jahia.services.content.impl.external.vfs.VFSDataSource.java
public List<String> getChildren(String path) { try {/* w w w . j a v a 2s.c o m*/ if (!path.endsWith("/" + Constants.JCR_CONTENT)) { FileObject fileObject = getFile(path); if (fileObject.getType() == FileType.FILE) { return Arrays.asList(Constants.JCR_CONTENT); } else if (fileObject.getType() == FileType.FOLDER) { List<String> children = new ArrayList<String>(); for (FileObject object : fileObject.getChildren()) { children.add(object.getName().getBaseName()); } return children; } else { logger.warn("Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType()); } } } catch (FileSystemException e) { logger.error("Cannot get node children", e); } return new ArrayList<String>(); }
From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java
public CommandResponse actionDeleteFolder(CommandRequest request) throws FileSystemException { if (isDeleteFolderAllowed() || getUserStatus().isRootUser()) { if (!getCurrentPath().equals(getBaseDirPath())) { FileObject currentDir = getCurrentDir(); if (currentDir != null && currentDir.isWriteable() && (currentDir.getChildren() == null || currentDir.getChildren().length == 0)) { FileObject parentDir = currentDir.getParent(); if (parentDir != null && parentDir.isWriteable()) { if (currentDir.delete()) { currentPath = currentPath.substring(0, currentPath.lastIndexOf("/")); }// w w w . j a v a2 s . c o m } } } } return getCommonResponse(request); }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationActionsFormatter.java
protected void renderDeleteFolder() throws FileSystemException { if (fileNavigationHandler.isDeleteFolderAllowed() || fileNavigationHandler.getUserStatus().isRootUser()) { if (!fileNavigationHandler.getCurrentPath().equals(fileNavigationHandler.getStartingPath())) { FileObject currentDir = fileNavigationHandler.getCurrentDir(); if (currentDir != null && currentDir.isWriteable() && (currentDir.getChildren() == null || currentDir.getChildren().length == 0)) { FileObject parentDir = currentDir.getParent(); if (parentDir != null && parentDir.isWriteable()) { setAttribute("folderName", currentDir.getName().getBaseName()); renderFragment("deleteFolder"); }/* w w w . j av a 2 s.c om*/ } } } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationFileListFormatter.java
public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException { try {/*from ww w . ja v a2s. com*/ FileObject currentPath = getFileNavigationHandler().getCurrentDir(); if (currentPath != null) { FileObject[] children = currentPath.getChildren(); List sortedChildren = new ArrayList(); for (int i = 0; i < children.length; i++) { FileObject child = children[i]; if (child.getType().equals(FileType.FILE) && child.isReadable() && !child.isHidden()) { if (matchesPattern(child, getFileNavigationHandler().getCurrentFilter())) sortedChildren.add(child); } } sortFiles(sortedChildren); renderFiles(sortedChildren); } } catch (FileSystemException e) { log.error("Error: ", e); } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationTreeFormatter.java
protected void renderDirectory(FileObject currentDir) throws FileSystemException { String dirName = currentDir.getName().getBaseName(); setAttribute("dirName", StringUtils.defaultIfEmpty(dirName, "/")); setAttribute("path", currentDir.getName().getPath()); FileObject[] children = currentDir.getChildren(); List childDirectories = new ArrayList(); boolean hasChildDirectories = false; if (children != null) for (int i = 0; i < children.length; i++) { FileObject child = children[i]; if (child.getType().equals(FileType.FOLDER) && !child.isHidden() && child.isReadable()) { hasChildDirectories = true; childDirectories.add(child); }//from w w w . j ava 2s.co m } setAttribute("hasChildrenDirectories", hasChildDirectories); String directoryPath = currentDir.getName().getPath(); boolean isOpen = getFileNavigationHandler().getOpenPaths().contains(directoryPath); setAttribute("isOpen", isOpen); setAttribute("isCurrent", getFileNavigationHandler().getCurrentPath().equals(directoryPath)); renderFragment("outputDirectory"); if (childDirectories.size() > 0) { sortDirectories(childDirectories); if (isOpen) { renderFragment("beforeChildren"); for (int i = 0; i < childDirectories.size(); i++) { FileObject child = (FileObject) childDirectories.get(i); renderDirectory(child); } renderFragment("afterChildren"); } } }
From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java
private void processDir(FileObject dir, boolean recursive) throws Exception { //recursively traverse directories FileObject[] children = dir.getChildren(); for (FileObject subfile : children) { if (subfile.getType() == FileType.FOLDER) { if (recursive) processDir(subfile, recursive); } else {/*from w w w . j a v a 2s. co m*/ getInstaller().installComponent(createArtifact(subfile.getParent().getURL().toString(), JOSSOScope.AGENT, subfile.getName().getBaseName()), true); } } }