List of usage examples for org.apache.commons.vfs FileObject equals
public boolean equals(Object obj)
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Returns whether a folder contains a given file * @param folder A folder//from w ww .java 2 s . c o m * @param file A file * @return whether a folder contains a given file */ public static boolean isParent(FileObject folder, FileObject file) { try { FileObject parent = file.getParent(); if (parent == null) { return false; } return parent.equals(folder); } catch (FileSystemException ex) { return false; } }
From source file:com.panet.imeta.core.playlist.FilePlayListReplay.java
private void initializeCurrentIfNeeded(FileObject file, String filePart) throws KettleException { if (!(file.equals(getCurrentProcessingFile()) && filePart.equals(getCurrentProcessingFilePart()))) initializeCurrent(file, filePart); }
From source file:com.thinkberg.moxo.dav.CopyMoveBase.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean overwrite = getOverwrite(request); FileObject object = getResourceManager().getFileObject(request.getPathInfo()); FileObject targetObject = getDestination(request); try {//from w w w . j a v a 2 s .c o m // check that we can write the target LockManager.getInstance().checkCondition(targetObject, getIf(request)); // if we move, check that we can actually write on the source if ("MOVE".equals(request.getMethod())) { LockManager.getInstance().checkCondition(object, getIf(request)); } } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } if (null == targetObject) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (object.equals(targetObject)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (targetObject.exists()) { if (!overwrite) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { FileObject targetParent = targetObject.getParent(); if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); } response.setStatus(HttpServletResponse.SC_CREATED); } copyOrMove(object, targetObject, getDepth(request)); }
From source file:com.thinkberg.webdav.CopyMoveBase.java
/** * Handle a COPY or MOVE request.//from w w w .ja va 2 s.c o m * * @param request the servlet request * @param response the servlet response * @throws IOException if there is an error executing this request */ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean overwrite = getOverwrite(request); FileObject object = VFSBackend.resolveFile(request.getPathInfo()); FileObject targetObject = getDestination(request); try { final LockManager lockManager = LockManager.getInstance(); LockManager.EvaluationResult evaluation = lockManager.evaluateCondition(targetObject, getIf(request)); if (!evaluation.result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if ("MOVE".equals(request.getMethod())) { evaluation = lockManager.evaluateCondition(object, getIf(request)); if (!evaluation.result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (null == targetObject) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (object.equals(targetObject)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (targetObject.exists()) { if (!overwrite) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { FileObject targetParent = targetObject.getParent(); if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); } response.setStatus(HttpServletResponse.SC_CREATED); } // delegate the actual execution to a sub class copyOrMove(object, targetObject, getDepth(request)); }
From source file:net.sf.vfsjfilechooser.filepane.VFSFilePane.java
public Action getNewFolderAction() { if (!readOnly && (newFolderAction == null)) { newFolderAction = new AbstractAction(newFolderActionLabelText) { private Action basicNewFolderAction; {//from www . j ava 2s . c o m putValue(Action.ACTION_COMMAND_KEY, VFSFilePane.ACTION_NEW_FOLDER); FileObject currentDirectory = getFileChooser().getCurrentDirectory(); if (currentDirectory != null) { setEnabled(canWrite(currentDirectory)); } } public void actionPerformed(ActionEvent ev) { if (basicNewFolderAction == null) { basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction(); } VFSJFileChooser fc = getFileChooser(); FileObject oldFile = fc.getSelectedFile(); basicNewFolderAction.actionPerformed(ev); FileObject newFile = fc.getSelectedFile(); if ((newFile != null) && !newFile.equals(oldFile) && VFSUtils.isDirectory(newFile)) { newFolderFile = newFile; } } }; } return newFolderAction; }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Notifies the application components that a new current directory has been selected * /*from ww w . j a va 2s. com*/ * @param dir the directory that was selected, null is ignored */ public void notifySelectedDirectory(FileObject dir, String connectionId) throws FileSystemException { if (dir == null || connectionId == null) return; if (getCurrentDirectory() != null && dir.equals(getCurrentDirectory())) return; setCurrentDirectory(dir); setCurrentConnectionId(connectionId); //System.err.println("notifySelectedDirectory currentDirectory:" // + currentDirectory + " notify dir:" + dir ); // Processing... VFSUtil.setUiStateListContents(shell, getCurrentDirectory().getName().toString()); notifySelectedFiles(null); /* Table view: * Displays the contents of the selected directory. */ workerUpdate(dir, connectionId, false); /* Combo view: * Sets the combo box to point to the selected directory. */ final FileObject[] comboRoots = (FileObject[]) combo.getData(COMBODATA_ROOTS); int comboEntry = -1; if (comboRoots != null) { for (int i = 0; i < comboRoots.length; ++i) { if (dir.equals(comboRoots[i])) { comboEntry = i; break; } } } if (comboEntry == -1) combo.setText(dir.getName().toString()); else combo.select(comboEntry); /* Tree view: * If not already expanded, recursively expands the parents of the specified * directory until it is visible. */ Vector /* of FileObject */ path = new Vector(); // Build a stack of paths from the root of the tree while (dir != null) { path.add(dir); //dir = dir.getParentFile(); try { dir = dir.getParent(); } catch (Exception e) { System.err.println("notifySelectedDirectory:" + e); } } //System.out.println("notifySelectedDirectory currentDirectory:" // + currentDirectory + " dir:" + dir + " tree path:" + path); // Recursively expand the tree to get to the specified directory TreeItem[] items = tree.getItems(); TreeItem lastItem = null; String destConnectionId = null; TreeItem item = null; // filter by connection first for (int k = 0; k < items.length; ++k) { item = items[k]; destConnectionId = (String) item.getData(TREEITEMDATA_CONNECTIONID); if (connectionId.equals(connectionId)) { items = items[k].getItems(); } } for (int i = path.size() - 1; i >= 0; --i) { final FileObject pathElement = (FileObject) path.elementAt(i); // Search for a particular FileObject in the array of tree items // No guarantee that the items are sorted in any recognizable fashion, so we'll // just sequential scan. There shouldn't be more than a few thousand entries. item = null; for (int k = 0; k < items.length; ++k) { item = items[k]; if (item.isDisposed()) continue; final String fileURI = ((String) item.getData(TREEITEMDATA_URI)); destConnectionId = (String) item.getData(TREEITEMDATA_CONNECTIONID); // Resolving the children will attempt a server connection. This will hang the UI if the server is down // Thus perform a comparison by Host/Scheme/Path only // Cannot just compare the URI strings cuz FileObject hides the port number if (connectionId.equals(destConnectionId) && VFSUtil.compareURIs(fileURI, pathElement.toString())) break; } if (item == null) break; lastItem = item; if (i != 0 && !item.getExpanded()) { treeExpandItem(item); item.setExpanded(true); } items = item.getItems(); } if (connectionId.equals(destConnectionId)) { tree.setSelection((lastItem != null) ? new TreeItem[] { lastItem } : new TreeItem[0]); } /* Shell: * Sets the title to indicate the selected directory */ VFSUtil.setUiStateIdle(shell, VFSUtil.stripUserTokens(getCurrentDirectory().toString())); }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Handles deferred Refresh notifications (due to Drag & Drop) */// w w w . j a va2s . co m void handleDeferredRefresh() throws FileSystemException { //System.out.println("handleDeferredRefresh"); if (isDragging || isDropping || !deferredRefreshRequested) return; deferredRefreshRequested = false; FileObject[] files = deferredRefreshFiles; deferredRefreshFiles = null; shell.setCursor(CFPluginImages.cursors[CFPluginImages.cursorWait]); /* Table view: * Refreshes information about any files in the list and their children. */ boolean refreshTable = false; if (files != null) { for (int i = 0; i < files.length; ++i) { final FileObject file = files[i]; if (file.equals(getCurrentDirectory())) { refreshTable = true; break; } FileObject parentFile = file.getParent(); if ((parentFile != null) && (parentFile.equals(getCurrentDirectory()))) { refreshTable = true; break; } } } else refreshTable = true; if (refreshTable) workerUpdate(getCurrentDirectory(), getCurrentConnectionId(), true); /* Combo view: * Refreshes the list of roots */ final FileObject[] roots = getRoots(fsManager); if (files == null) { boolean refreshCombo = false; final FileObject[] comboRoots = (FileObject[]) combo.getData(COMBODATA_ROOTS); if ((comboRoots != null) && (comboRoots.length == roots.length)) { for (int i = 0; i < roots.length; ++i) { if (!roots[i].equals(comboRoots[i])) { refreshCombo = true; break; } } } else refreshCombo = true; if (refreshCombo) { combo.removeAll(); combo.setData(COMBODATA_ROOTS, roots); for (int i = 0; i < roots.length; ++i) { final FileObject file = roots[i]; combo.add(file.getName().toString()); } } } /* Tree view: * Refreshes information about any files in the list and their children. */ treeRefresh(roots); treeInsertRemoteURIs(); // Remind everyone where we are in the filesystem final FileObject dir = getCurrentDirectory(); setCurrentDirectory(null); final String con = getCurrentConnectionId(); setCurrentConnectionId(null); notifySelectedDirectory(dir, con); shell.setCursor(CFPluginImages.cursors[CFPluginImages.cursorDefault]); }
From source file:org.docx4all.ui.main.WordMLEditor.java
public void updateInternalFrame(FileObject oldFile, FileObject newFile) { if (oldFile.equals(newFile)) { return;//from w w w . j a va2s . c o m } String fileUri = oldFile.getName().getURI(); JInternalFrame iframe = _iframeMap.remove(fileUri); if (iframe != null) { fileUri = newFile.getName().getURI(); iframe.putClientProperty(WordMLDocument.FILE_PATH_PROPERTY, fileUri); iframe.setTitle(newFile.getName().getBaseName()); } }
From source file:org.efaps.webdav4vfs.handler.AbstractCopyMoveBaseHandler.java
/** * Handle a COPY or MOVE request.//w w w .j av a2 s. c o m * * @param _request HTTP servlet request * @param _response HTTP servlet response * @throws IOException if there is an error executing this request */ @Override public void service(final HttpServletRequest _request, final HttpServletResponse _response) throws IOException { boolean overwrite = getOverwrite(_request); FileObject object = VFSBackend.resolveFile(_request.getPathInfo()); FileObject targetObject = getDestination(_request); try { final LockManager lockManager = LockManager.getInstance(); LockManager.EvaluationResult evaluation = lockManager.evaluateCondition(targetObject, getIf(_request)); if (!evaluation.result) { _response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if ("MOVE".equals(_request.getMethod())) { evaluation = lockManager.evaluateCondition(object, getIf(_request)); if (!evaluation.result) { _response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } } catch (LockException e) { _response.sendError(SC_LOCKED); return; } catch (ParseException e) { _response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (null == targetObject) { _response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (object.equals(targetObject)) { _response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (targetObject.exists()) { if (!overwrite) { _response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } _response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { FileObject targetParent = targetObject.getParent(); if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) { _response.sendError(HttpServletResponse.SC_CONFLICT); } _response.setStatus(HttpServletResponse.SC_CREATED); } // delegate the actual execution to a sub class this.copyOrMove(object, targetObject, getDepth(_request)); }
From source file:org.pentaho.di.core.playlist.FilePlayListReplay.java
private void initializeCurrentIfNeeded(FileObject file, String filePart) throws KettleException { if (!(file.equals(getCurrentProcessingFile()) && filePart.equals(getCurrentProcessingFilePart()))) { initializeCurrent(file, filePart); }/* ww w .java2s. c o m*/ }