List of usage examples for org.apache.commons.vfs2 NameScope DESCENDENT_OR_SELF
NameScope DESCENDENT_OR_SELF
To view the source code for org.apache.commons.vfs2 NameScope DESCENDENT_OR_SELF.
Click Source Link
From source file:net.sf.jabb.web.action.VfsTreeAction.java
protected List<JsTreeNodeData> getChildNodes(FileObject rootFile, String parentPath) throws FileSystemException { List<JsTreeNodeData> childNodes = new LinkedList<JsTreeNodeData>(); FileObject parent = null;//from w w w .ja v a 2 s. co m if (requestData.isRoot()) { parent = rootFile; } else { parent = rootFile.resolveFile(parentPath, NameScope.DESCENDENT_OR_SELF); } for (FileObject child : parent.getChildren()) { JsTreeNodeData childNode = populateTreeNodeData(rootFile, child); childNodes.add(childNode); } if (sortByName || folderFirst) { Collections.sort(childNodes, new Comparator<JsTreeNodeData>() { @Override public int compare(JsTreeNodeData o1, JsTreeNodeData o2) { int result = 0; if (folderFirst) { String t1 = o1.getAttr().get("rel").toString(); String t2 = o2.getAttr().get("rel").toString(); if (t1.equalsIgnoreCase(t2)) { result = 0; } else if ("file".equalsIgnoreCase(t2)) { result = -1; } else if ("file".equalsIgnoreCase(t1)) { result = 1; } else { result = t1.compareToIgnoreCase(t2); } } if (result == 0 && sortByName) { String n1 = o1.getData().toString(); String n2 = o2.getData().toString(); result = n1.compareToIgnoreCase(n2); } return result; } }); } return childNodes; }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * AJAX tree functions/* w ww.j a v a2 s. c o m*/ */ public String execute() { normalizeTreeRequest(); JsTreeResult result = new JsTreeResult(); final AllFileSelector ALL_FILES = new AllFileSelector(); FileSystemManager fsManager = null; FileObject rootFile = null; FileObject file = null; FileObject referenceFile = null; try { fsManager = VfsUtility.getManager(); rootFile = fsManager.resolveFile(rootPath, fsOptions); if (JsTreeRequest.OP_GET_CHILDREN.equalsIgnoreCase(requestData.getOperation())) { String parentPath = requestData.getId(); List<JsTreeNodeData> nodes = null; try { nodes = getChildNodes(rootFile, parentPath); if (requestData.isRoot() && rootNodeName != null) { // add root node JsTreeNodeData rootNode = new JsTreeNodeData(); rootNode.setData(rootNodeName); Map<String, Object> attr = new HashMap<String, Object>(); rootNode.setAttr(attr); attr.put("id", "."); attr.put("rel", "root"); attr.put("fileType", FileType.FOLDER.toString()); rootNode.setChildren(nodes); rootNode.setState(JsTreeNodeData.STATE_OPEN); nodes = new LinkedList<JsTreeNodeData>(); nodes.add(rootNode); } } catch (Exception e) { log.error("Cannot get child nodes for: " + parentPath, e); nodes = new LinkedList<JsTreeNodeData>(); } responseData = nodes; } else if (JsTreeRequest.OP_REMOVE_NODE.equalsIgnoreCase(requestData.getOperation())) { String path = requestData.getId(); try { file = rootFile.resolveFile(path, NameScope.DESCENDENT); boolean wasDeleted = false; if (file.getType() == FileType.FILE) { wasDeleted = file.delete(); } else { wasDeleted = file.delete(ALL_FILES) > 0; } result.setStatus(wasDeleted); } catch (Exception e) { result.setStatus(false); log.error("Cannot delete: " + path, e); } responseData = result; } else if (JsTreeRequest.OP_CREATE_NODE.equalsIgnoreCase(requestData.getOperation())) { String parentPath = requestData.getReferenceId(); String name = requestData.getTitle(); try { referenceFile = rootFile.resolveFile(parentPath, NameScope.DESCENDENT_OR_SELF); file = referenceFile.resolveFile(name, NameScope.CHILD); file.createFolder(); result.setStatus(true); result.setId(rootFile.getName().getRelativeName(file.getName())); } catch (Exception e) { result.setStatus(false); log.error("Cannot create folder '" + name + "' under '" + parentPath + "'", e); } responseData = result; } else if (JsTreeRequest.OP_RENAME_NODE.equalsIgnoreCase(requestData.getOperation())) { String path = requestData.getId(); String name = requestData.getTitle(); try { referenceFile = rootFile.resolveFile(path, NameScope.DESCENDENT); file = referenceFile.getParent().resolveFile(name, NameScope.CHILD); referenceFile.moveTo(file); result.setStatus(true); } catch (Exception e) { result.setStatus(false); log.error("Cannot rename '" + path + "' to '" + name + "'", e); } responseData = result; } else if (JsTreeRequest.OP_MOVE_NODE.equalsIgnoreCase(requestData.getOperation())) { String newParentPath = requestData.getReferenceId(); String originalPath = requestData.getId(); try { referenceFile = rootFile.resolveFile(originalPath, NameScope.DESCENDENT); file = rootFile.resolveFile(newParentPath, NameScope.DESCENDENT_OR_SELF) .resolveFile(referenceFile.getName().getBaseName(), NameScope.CHILD); if (requestData.isCopy()) { file.copyFrom(referenceFile, ALL_FILES); } else { referenceFile.moveTo(file); } result.setStatus(true); } catch (Exception e) { result.setStatus(false); log.error("Cannot move '" + originalPath + "' to '" + newParentPath + "'", e); } responseData = result; } } catch (FileSystemException e) { log.error("Cannot perform file operation.", e); } finally { VfsUtility.close(fsManager, file, referenceFile, rootFile); } return SUCCESS; }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Returns an Enumeration of all the resources in the search path * with the specified name./*from w w w . j ava2s . c o m*/ * @param name The resources to find. * @return An Enumeration of the resources associated with the name. */ @Override protected Enumeration<URL> findResources(final String name) throws IOException { ArrayList<URL> result = new ArrayList<URL>(2); final Iterator<FileObject> it = resources.iterator(); while (it.hasNext()) { final FileObject baseFile = it.next(); final FileObject file = baseFile.resolveFile(name, NameScope.DESCENDENT_OR_SELF); if (file.exists()) { result.add(new Resource(name, baseFile, file).getURL()); } } return Collections.enumeration(result); }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Searches through the search path of for the first class or resource * with specified name./*from w w w . j a v a2 s. c o m*/ * @param name The resource to load. * @return The Resource. * @throws FileSystemException if an error occurs. */ private Resource loadResource(final String name) throws FileSystemException { final Iterator<FileObject> it = resources.iterator(); while (it.hasNext()) { final FileObject baseFile = it.next(); final FileObject file = baseFile.resolveFile(name, NameScope.DESCENDENT_OR_SELF); if (file.exists()) { return new Resource(name, baseFile, file); } } return null; }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * Moves the complete content of one directory into another. * * @throws IOException/*from w w w .j a v a 2s . c o m*/ * If the move failed. */ public static void moveContents(final File sourceDir, final File dest) throws IOException { final FileSystemManager vfsManager = VFSUtilities.getManager(); final FileObject source = vfsManager.toFileObject(sourceDir); final FileObject destDir = vfsManager.toFileObject(dest); final FileObject[] findFiles = source.findFiles(new AllFileSelector()); // Might happen, if source does not exists... shouldn't we check this? if (findFiles == null) return; for (final FileObject fileObject : findFiles) { if (FileType.FILE.equals(fileObject.getType())) { final String relPath = source.getName().getRelativeName(fileObject.getName()); final FileObject destFile = destDir.resolveFile(relPath, NameScope.DESCENDENT_OR_SELF); final FileObject folder = destFile.getParent(); folder.createFolder(); fileObject.moveTo(destFile); } } }
From source file:org.obiba.opal.server.sshd.OpalFileSystemView.java
private FileObject resolve(String file) { FileObject resolved = null;// w w w. ja v a 2 s . c o m try { resolved = opalfs.getRoot().resolveFile(file, NameScope.DESCENDENT_OR_SELF); } catch (FileSystemException e) { resolved = opalfs.getRoot(); } return resolved; }