List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:org.docx4all.ui.main.WordMLApplet.java
private void openLocalFile(WordMLEditor editor, String urlParam) { ResourceMap rm = editor.getContext().getResourceMap(WordMLEditor.class); String localFileUrl = urlParam; if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { if (urlParam.startsWith("file:///")) { ;//pass } else {/*from ww w. j a v a 2 s . c o m*/ localFileUrl = "file:///" + urlParam.substring(7); } } String errMsg = null; try { FileObject fo = VFSUtils.getFileSystemManager().resolveFile(urlParam); if (fo.exists()) { Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); localFileUrl = fo.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, localFileUrl); prefs.put(Constants.LAST_OPENED_LOCAL_FILE, localFileUrl); PreferenceUtil.flush(prefs); log.info("\n\n Opening " + urlParam); editor.createInternalFrame(fo); } else { errMsg = rm.getString("Application.applet.initialisation.file.not.found.message", urlParam); } } catch (FileSystemException exc) { exc.printStackTrace(); errMsg = rm.getString("Application.applet.initialisation.file.io.error.message", urlParam); } if (errMsg != null) { String title = rm.getString("Application.applet.initialisation.Action.text"); editor.showMessageDialog(title, errMsg, JOptionPane.ERROR_MESSAGE); } }
From source file:org.docx4all.ui.main.WordMLEditor.java
private JEditorPane createEditorView(FileObject f) { String fileUri = f.getName().getURI(); WordMLTextPane editorView = new WordMLTextPane(); editorView.addFocusListener(_toolbarStates); editorView.addCaretListener(_toolbarStates); editorView.setTransferHandler(new TransferHandler()); WordMLEditorKit editorKit = (WordMLEditorKit) editorView.getEditorKit(); editorKit.addInputAttributeListener(_toolbarStates); WordMLDocument doc = null;//from ww w . ja v a 2s .c o m try { if (f.exists()) { doc = editorKit.read(f); } } catch (Exception exc) { exc.printStackTrace(); ResourceMap rm = getContext().getResourceMap(); String title = rm.getString(Constants.INIT_EDITOR_VIEW_IO_ERROR_DIALOG_TITLE); StringBuffer msg = new StringBuffer(); msg.append(rm.getString(Constants.INIT_EDITOR_VIEW_IO_ERROR_MESSAGE)); msg.append(Constants.NEWLINE); msg.append(VFSUtils.getFriendlyName(fileUri)); showMessageDialog(title, msg.toString(), JOptionPane.ERROR_MESSAGE); doc = null; } if (doc == null) { doc = (WordMLDocument) editorKit.createDefaultDocument(); } doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, fileUri); doc.addDocumentListener(_toolbarStates); doc.setDocumentFilter(new WordMLDocumentFilter()); editorView.setDocument(doc); editorView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE); if (DocUtil.isSharedDocument(doc)) { editorKit.initPlutextClient(editorView); } return editorView; }
From source file:org.docx4all.ui.menu.FileMenu.java
private RETURN_TYPE saveAsFile(String callerActionName, ActionEvent actionEvent, String fileType) { Preferences prefs = Preferences.userNodeForPackage(getClass()); WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); ResourceMap rm = editor.getContext().getResourceMap(getClass()); JInternalFrame iframe = editor.getCurrentInternalFrame(); String oldFilePath = (String) iframe.getClientProperty(WordMLDocument.FILE_PATH_PROPERTY); VFSJFileChooser chooser = createFileChooser(rm, callerActionName, iframe, fileType); RETURN_TYPE returnVal = chooser.showSaveDialog((Component) actionEvent.getSource()); if (returnVal == RETURN_TYPE.APPROVE) { FileObject selectedFile = getSelectedFile(chooser, fileType); boolean error = false; boolean newlyCreatedFile = false; if (selectedFile == null) { // Should never happen, whether the file exists or not } else {// w ww . ja v a2 s . c o m //Check selectedFile's existence and ask user confirmation when needed. try { boolean selectedFileExists = selectedFile.exists(); if (!selectedFileExists) { FileObject parent = selectedFile.getParent(); String uri = UriParser.decode(parent.getName().getURI()); if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") > -1 && parent.getName().getScheme().startsWith("file") && !parent.isWriteable() && (uri.indexOf("/Documents") > -1 || uri.indexOf("/My Documents") > -1)) { //TODO: Check whether we still need this workaround. //See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4939819 //Re: File.canWrite() returns false for the "My Documents" directory (win) String localpath = org.docx4j.utils.VFSUtils.getLocalFilePath(parent); File f = new File(localpath); f.setWritable(true, true); } selectedFile.createFile(); newlyCreatedFile = true; } else if (!selectedFile.getName().getURI().equalsIgnoreCase(oldFilePath)) { String title = rm.getString(callerActionName + ".Action.text"); String message = VFSUtils.getFriendlyName(selectedFile.getName().getURI()) + "\n" + rm.getString(callerActionName + ".Action.confirmMessage"); int answer = editor.showConfirmDialog(title, message, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer != JOptionPane.YES_OPTION) { selectedFile = null; } } // if (!selectedFileExists) } catch (FileSystemException exc) { exc.printStackTrace();//ignore log.error("Couldn't create new file or assure file existence. File = " + selectedFile.getName().getURI()); selectedFile = null; error = true; } } //Check whether there has been an error, cancellation by user //or may proceed to saving file. if (selectedFile != null) { //Proceed to saving file String selectedPath = selectedFile.getName().getURI(); if (log.isDebugEnabled()) { log.debug("saveAsFile(): selectedFile = " + VFSUtils.getFriendlyName(selectedPath)); } prefs.put(Constants.LAST_OPENED_FILE, selectedPath); if (selectedFile.getName().getScheme().equals("file")) { prefs.put(Constants.LAST_OPENED_LOCAL_FILE, selectedPath); } PreferenceUtil.flush(prefs); boolean success = false; if (EXPORT_AS_NON_SHARED_DOC_ACTION_NAME.equals(callerActionName)) { log.info("saveAsFile(): Exporting as non shared document to " + VFSUtils.getFriendlyName(selectedPath)); success = export(iframe, selectedPath, callerActionName); if (success) { prefs.put(Constants.LAST_OPENED_FILE, selectedPath); if (selectedPath.startsWith("file:")) { prefs.put(Constants.LAST_OPENED_LOCAL_FILE, selectedPath); } PreferenceUtil.flush(prefs); log.info("saveAsFile(): Opening " + VFSUtils.getFriendlyName(selectedPath)); editor.createInternalFrame(selectedFile); } } else { success = save(iframe, selectedPath, callerActionName); if (success) { if (Constants.DOCX_STRING.equals(fileType) || Constants.FLAT_OPC_STRING.equals(fileType)) { //If saving as .docx then update the document dirty flag //of toolbar states as well as internal frame title. editor.getToolbarStates().setDocumentDirty(iframe, false); editor.getToolbarStates().setLocalEditsEnabled(iframe, false); FileObject file = null; try { file = VFSUtils.getFileSystemManager().resolveFile(oldFilePath); editor.updateInternalFrame(file, selectedFile); } catch (FileSystemException exc) { ;//ignore } } else { //Because document dirty flag is not cleared //and internal frame title is not changed, //we present a success message. String title = rm.getString(callerActionName + ".Action.text"); String message = VFSUtils.getFriendlyName(selectedPath) + "\n" + rm.getString(callerActionName + ".Action.successMessage"); editor.showMessageDialog(title, message, JOptionPane.INFORMATION_MESSAGE); } } } if (!success && newlyCreatedFile) { try { selectedFile.delete(); } catch (FileSystemException exc) { log.error("saveAsFile(): Saving failure and cannot remove the newly created file = " + selectedPath); exc.printStackTrace(); } } } else if (error) { log.error("saveAsFile(): selectedFile = NULL"); String title = rm.getString(callerActionName + ".Action.text"); String message = rm.getString(callerActionName + ".Action.errorMessage"); editor.showMessageDialog(title, message, JOptionPane.ERROR_MESSAGE); } } //if (returnVal == JFileChooser.APPROVE_OPTION) return returnVal; }
From source file:org.docx4all.ui.menu.HyperlinkMenu.java
public void openLinkedDocument(FileObject sourceFile, HyperlinkML linkML, boolean autoCreateLinkedDocument) { if (autoCreateLinkedDocument && linkML.getWordprocessingMLPackage() == null) { throw new IllegalArgumentException("Invalid HyperlinkML parameter"); }/*from www . j a va 2s . c o m*/ final WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); final ResourceMap rm = editor.getContext().getResourceMap(getClass()); String title = rm.getString(OPEN_LINKED_DOCUMENT_ACTION_NAME + ".Action.text"); String errMsg = null; String targetFilePath = HyperlinkML.encodeTarget(linkML, sourceFile, false); if (targetFilePath.startsWith("file://")) { // local file try { FileObject fo = VFSUtils.getFileSystemManager().resolveFile(targetFilePath); if (!fo.exists()) { if (autoCreateLinkedDocument) { boolean success = createInFileSystem(fo, linkML.getWordprocessingMLPackage()); if (!success) { // needs not display additional error message. fo = null; } } else { fo = null; errMsg = rm.getString(OPEN_LINKED_DOCUMENT_ACTION_NAME + ".file.not.found.message", targetFilePath); } } if (fo != null) { editor.createInternalFrame(fo); final String sourceUri = sourceFile.getName().getURI(); final String targetUri = fo.getName().getURI(); SwingUtilities.invokeLater(new Runnable() { public void run() { editor.tileLayout(sourceUri, targetUri); } }); } } catch (FileSystemException exc) { exc.printStackTrace(); errMsg = rm.getString(OPEN_LINKED_DOCUMENT_ACTION_NAME + ".io.error.message", targetFilePath); } } else if (targetFilePath.startsWith("webdav://")) { try { boolean recordAsLastOpenUrl = false; WordprocessingMLPackage newPackage = createNewEmptyPackage(linkML.getWordprocessingMLPackage()); if (autoCreateLinkedDocument && newPackage == null) { //cannot create a new WordprocessingMLPackage. //This is an unlikely situation. //Avoid creating new linked document. //TODO: probably display a message ? autoCreateLinkedDocument = false; } FileObject fo = openWebdavDocument(targetFilePath, recordAsLastOpenUrl, autoCreateLinkedDocument, newPackage, OPEN_LINKED_DOCUMENT_ACTION_NAME); if (fo != null) { final String sourceUri = sourceFile.getName().getURI(); final String targetUri = fo.getName().getURI(); SwingUtilities.invokeLater(new Runnable() { public void run() { editor.tileLayout(sourceUri, targetUri); } }); } else { //Does not need to display additional error message. //openWebdavDocument() must have displayed all necessary //messages. } } catch (FileSystemException exc) { exc.printStackTrace(); errMsg = rm.getString(OPEN_LINKED_DOCUMENT_ACTION_NAME + ".io.error.message", targetFilePath); } } else { errMsg = rm.getString(OPEN_LINKED_DOCUMENT_ACTION_NAME + ".unsupported.protocol.message", targetFilePath); } if (errMsg != null) { editor.showMessageDialog(title, errMsg, JOptionPane.ERROR_MESSAGE); } }
From source file:org.docx4all.ui.menu.HyperlinkMenu.java
/** * Opens a webdav document pointed by vfsWebdavUrl parameter in its own * internal frame./*w w w . ja va 2 s . c om*/ * * vfsWebdavUrl is a VFS Webdav URL that points to a webdav document. * It may or may not contain user credentials information. * For example: * <> webdav://dev.plutext.org/alfresco/plutextwebdav/User Homes/someone/AFile.docx * <> webdav://dev.plutext.org:80/alfresco/plutextwebdav/User Homes/someone/AFile.docx * <> webdav://username:password@dev.plutext.org/alfresco/plutextwebdav/User Homes/someone/AFile.docx * * In the event that vfsWebdavUrl does not have user credentials or its user credentials * is invalid then this method will cycle through each known user credential found in * VFSJFileChooser Bookmark in order to find an authorised user. If no such user can be * found then an authentication challenge dialog will be displayed and user has three * attempts to authenticate himself. * * @param vfsWebdavUrl a VFS Webdav Url in its friendly format. * @param recordAsLastOpenUrl a boolean flag that indicates whether vfsWebdavUrl * should be recorded as the last open url. * @param createNewIfNotFound a boolean flag that indicates whether a new webdav * document at vfsWebdavUrl should be created if it has not existed. * @param newPackage a WordprocessingMLPackage that will become the content of * newly created webdav document. This parameter must be supplied when * createNewIfNotFound parameter is true. * @param callerActionName an Action name that can be used as a key to get * resource properties in relation to dialog messages. * @return FileObject of the opened document */ public FileObject openWebdavDocument(String vfsWebdavUrl, boolean recordAsLastOpenUrl, boolean createNewIfNotFound, WordprocessingMLPackage newPackage, String callerActionName) { if (!vfsWebdavUrl.startsWith("webdav://")) { throw new IllegalArgumentException("Not a webdav uri"); } if (createNewIfNotFound && newPackage == null) { throw new IllegalArgumentException("Invalid newPackage parameter"); } final WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); final ResourceMap rm = editor.getContext().getResourceMap(getClass()); VFSURIParser uriParser = new VFSURIParser(vfsWebdavUrl, false); if (uriParser.getUsername() != null && uriParser.getUsername().length() > 0 && uriParser.getPassword() != null && uriParser.getPassword().length() > 0) { //vfsWebdavUrl has user credentials. try { FileObject fo = VFSUtils.getFileSystemManager().resolveFile(vfsWebdavUrl); if (fo.exists()) { if (recordAsLastOpenUrl) { Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); String lastFileUri = fo.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, lastFileUri); PreferenceUtil.flush(prefs); } log.info("\n\n Opening " + fo.getName().getURI()); editor.createInternalFrame(fo); return fo; } } catch (FileSystemException exc) { ; } } String temp = rm.getString(Constants.VFSJFILECHOOSER_DEFAULT_WEBDAV_FOLDER_BOOKMARK_NAME); if (temp == null || temp.length() == 0) { temp = "Default Webdav Folder"; } else { temp = temp.trim(); } List<String> userCredentials = org.docx4all.vfs.VFSUtil.collectUserCredentialsFromBookmark(uriParser, temp); StringBuilder sb = new StringBuilder(); sb.append(uriParser.getHostname()); if (uriParser.getPortnumber() != null && uriParser.getPortnumber().length() > 0) { sb.append(":"); sb.append(uriParser.getPortnumber()); } sb.append(uriParser.getPath()); temp = sb.toString();//hostname[:port] and path vfsWebdavUrl = "webdav://" + temp; //Try each known userCredential to resolve a FileObject FileObject theFile = null; for (String uc : userCredentials) { sb.delete(0, sb.length()); sb.append("webdav://"); sb.append(uc); sb.append("@"); sb.append(temp); try { theFile = VFSUtils.getFileSystemManager().resolveFile(sb.toString()); if (theFile.exists()) { break; } else { theFile = null; } } catch (FileSystemException exc) { theFile = null; } } if (theFile != null) { //theFile exists if (recordAsLastOpenUrl) { Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); String lastFileUri = theFile.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, lastFileUri); PreferenceUtil.flush(prefs); } log.info("\n\n Opening " + theFile.getName().getURI()); editor.createInternalFrame(theFile); } else { //Cannot get theFile yet. //Get user to authenticate himself. String title = rm.getString(callerActionName + ".Action.text"); String errMsg = null; Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); try { theFile = AuthenticationUtil.userAuthenticationChallenge(editor, vfsWebdavUrl, title); if (theFile == null) { //user may have cancelled the authentication challenge //or unsuccessfully authenticated himself. //Because AuthenticationUtil.userAuthenticationChallenge() //has displayed authentication failure message, we do //not need to do anything here. } else if (theFile.exists()) { String lastFileUri = theFile.getName().getURI(); if (recordAsLastOpenUrl) { prefs.put(Constants.LAST_OPENED_FILE, lastFileUri); } //Record lastFileUri in bookmark. //Use file name as bookmark entry title. int idx = lastFileUri.lastIndexOf("/"); org.docx4all.vfs.VFSUtil.addBookmarkEntry(lastFileUri.substring(idx + 1), new VFSURIParser(lastFileUri, false)); log.info("\n\n Opening " + lastFileUri); editor.createInternalFrame(theFile); } else if (createNewIfNotFound) { boolean success = createInFileSystem(theFile, newPackage); if (success) { String lastFileUri = theFile.getName().getURI(); if (recordAsLastOpenUrl) { prefs.put(Constants.LAST_OPENED_FILE, lastFileUri); } //Record lastFileUri in bookmark. //Use file name as bookmark entry title. int idx = lastFileUri.lastIndexOf("/"); org.docx4all.vfs.VFSUtil.addBookmarkEntry(lastFileUri.substring(idx + 1), new VFSURIParser(lastFileUri, false)); log.info("\n\n Opening " + lastFileUri); editor.createInternalFrame(theFile); } else { theFile = null; errMsg = rm.getString(callerActionName + ".file.io.error.message", vfsWebdavUrl); } } else { theFile = null; errMsg = rm.getString(callerActionName + ".file.not.found.message", vfsWebdavUrl); } } catch (FileSystemException exc) { exc.printStackTrace(); theFile = null; errMsg = rm.getString(callerActionName + ".file.io.error.message", vfsWebdavUrl); } finally { PreferenceUtil.flush(prefs); } if (errMsg != null) { theFile = null; editor.showMessageDialog(title, errMsg, JOptionPane.ERROR_MESSAGE); } } return theFile; }
From source file:org.eclim.plugin.jdt.command.search.SearchCommand.java
/** * Creates a Position from the supplied SearchMatch. * * @param project The project searching from. * @param match The SearchMatch.//from w w w . j a v a2 s. co m * @return The Position. */ protected Position createPosition(IProject project, SearchMatch match) throws Exception { IJavaElement element = (IJavaElement) match.getElement(); IJavaElement parent = JavaUtils.getPrimaryElement(element); String file = null; String elementName = JavaUtils.getFullyQualifiedName(parent); if (parent.getElementType() == IJavaElement.CLASS_FILE) { IResource resource = parent.getResource(); // occurs with a referenced project as a lib with no source and class // files that are not archived in that project if (resource != null && resource.getType() == IResource.FILE && !isJarArchive(resource.getLocation())) { file = resource.getLocation().toOSString(); } else { IPath path = null; IPackageFragmentRoot root = (IPackageFragmentRoot) parent.getParent().getParent(); resource = root.getResource(); if (resource != null) { if (resource.getType() == IResource.PROJECT) { path = ProjectUtils.getIPath((IProject) resource); } else { path = resource.getLocation(); } } else { path = root.getPath(); } String classFile = elementName.replace('.', File.separatorChar); if (isJarArchive(path)) { file = "jar:file://" + path.toOSString() + '!' + classFile + ".class"; } else { file = path.toOSString() + '/' + classFile + ".class"; } // android injects its jdk classes, so filter those out if the project // doesn't have the android nature. if (ANDROID_JDK_URL.matcher(file).matches() && project != null && !project.hasNature(ANDROID_NATURE)) { return null; } // if a source path attachment exists, use it. IPath srcPath = root.getSourceAttachmentPath(); if (srcPath != null) { String rootPath; IProject elementProject = root.getJavaProject().getProject(); // determine if src path is project relative or file system absolute. if (srcPath.isAbsolute() && elementProject.getName().equals(srcPath.segment(0))) { rootPath = ProjectUtils.getFilePath(elementProject, srcPath.toString()); } else { rootPath = srcPath.toOSString(); } String srcFile = FileUtils.toUrl(rootPath + File.separator + classFile + ".java"); // see if source file exists at source path. FileSystemManager fsManager = VFS.getManager(); FileObject fileObject = fsManager.resolveFile(srcFile); if (fileObject.exists()) { file = srcFile; // jdk sources on osx are under a "src/" dir in the jar } else if (Os.isFamily(Os.FAMILY_MAC)) { srcFile = FileUtils .toUrl(rootPath + File.separator + "src" + File.separator + classFile + ".java"); fileObject = fsManager.resolveFile(srcFile); if (fileObject.exists()) { file = srcFile; } } } } } else { IPath location = match.getResource().getLocation(); file = location != null ? location.toOSString() : null; } elementName = JavaUtils.getFullyQualifiedName(element); return Position.fromOffset(file.replace('\\', '/'), elementName, match.getOffset(), match.getLength()); }
From source file:org.eclim.plugin.jdt.util.JavaUtils.java
/** * Attempts to locate the IClassFile for the supplied file path from the * specified project's classpath.// w w w . java 2s . co m * * @param project The project to find the class file in. * @param path Absolute path or url (jar:, zip:) to a .java source file. * @return The IClassFile. */ public static IClassFile findClassFile(IJavaProject project, String path) throws Exception { if (path.startsWith("/") || path.toLowerCase().startsWith("jar:") || path.toLowerCase().startsWith("zip:")) { FileSystemManager fsManager = VFS.getManager(); FileObject file = fsManager.resolveFile(path); if (file.exists()) { BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(file.getContent().getInputStream())); String pack = null; String line = null; while ((line = in.readLine()) != null) { Matcher matcher = PACKAGE_LINE.matcher(line); if (matcher.matches()) { pack = matcher.group(1); break; } } if (pack != null) { String name = pack + '.' + FileUtils.getFileName(file.getName().getPath()); IType type = project.findType(name); if (type != null) { return type.getClassFile(); } } } finally { IOUtils.closeQuietly(in); } } } return null; }
From source file:org.eclim.util.file.FileOffsets.java
/** * Reads the supplied file and compiles a list of offsets. * * @param filename The file to compile a list of offsets for. * @return The FileOffsets instance./* ww w . ja v a 2s .c om*/ */ public static FileOffsets compile(String filename) { try { FileSystemManager fsManager = VFS.getManager(); FileObject file = fsManager.resolveFile(filename); // disable caching (the cache seems to become invalid at some point // causing vfs errors). //fsManager.getFilesCache().clear(file.getFileSystem()); if (!file.exists()) { throw new IllegalArgumentException(Services.getMessage("file.not.found", filename)); } return compile(file.getContent().getInputStream()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.efaps.webdav4vfs.handler.AbstractCopyMoveBaseHandler.java
/** * Handle a COPY or MOVE request./*from w w w. j a v a 2 s.co 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.efaps.webdav4vfs.handler.DeleteHandler.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try {/* ww w . j a va2s . c om*/ String fragment = new URI(request.getRequestURI()).getFragment(); if (fragment != null) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } try { if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).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 (object.exists()) { int deletedObjects = object.delete(ALL_FILES_SELECTOR); LOG.debug("deleted " + deletedObjects + " objects"); if (deletedObjects > 0) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }