List of usage examples for org.apache.commons.vfs2 NameScope DESCENDENT
NameScope DESCENDENT
To view the source code for org.apache.commons.vfs2 NameScope DESCENDENT.
Click Source Link
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java
/** * //from www . j a va 2 s . c om * * @param root * * @param path * * @return * @throws FileSystemException */ protected FileObject getTargetFileObject(FileObject root, String path) throws FileSystemException { FileObject out = root.resolveFile(path, NameScope.DESCENDENT); if (!out.exists()) { out.createFile(); } return out; }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
private FileObject getChild(String path) throws IOException { // VFS doesn't properly resolve the child if we don't remove the leading slash, even though that's inconsistent // with its other methods if (path.startsWith("/")) { path = path.substring(1);//from w w w .ja v a 2 s . c o m } return remoteDir.resolveFile(path, NameScope.DESCENDENT); }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * AJAX tree functions/* w w w . ja va 2 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.streamsets.pipeline.lib.remote.FTPRemoteConnector.java
protected FileObject resolveChild(String path) throws IOException { // VFS doesn't properly resolve the child if we don't remove the leading slash, even though that's inconsistent // with its other methods if (path.startsWith("/")) { path = path.substring(1);/*from ww w. j a v a2s. c om*/ } return remoteDir.resolveFile(path, NameScope.DESCENDENT); }