List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java
public CommandResponse actionCreateFolder(CommandRequest request) throws FileSystemException { if (createFolderAllowed || getUserStatus().isRootUser()) { FileObject currentDir = getCurrentDir(); if (currentDir != null && currentDir.isWriteable()) { String folderName = request.getRequestObject().getParameter("folderName"); FileObject fileObject = getCurrentDir().resolveFile(folderName); if (!fileObject.exists()) { fileObject.createFolder(); openPaths.add(currentPath); currentPath = fileObject.getName().getPath(); selectedFile = null;//ww w . j a v a 2 s . c om return getCommonResponse(request); } else { //TODO: Deal with errors } } } //TODO: Deal with permission error return getCommonResponse(request); }
From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java
public CommandResponse actionUploadFile(CommandRequest request) throws IOException { if (uploadFileAllowed || getUserStatus().isRootUser()) { FileObject currentDir = getCurrentDir(); if (currentDir != null && currentDir.isWriteable()) { File file = (File) request.getFilesByParamName().get("file"); if (file != null) { String fileName = file.getName(); FileObject fileObject = currentDir.resolveFile(fileName); if (!fileObject.exists()) { fileObject.createFile(); OutputStream os = fileObject.getContent().getOutputStream(true); InputStream is = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(is, os); is.close();/*from w ww. ja v a 2 s . co m*/ os.close(); currentFilePath = fileObject.getName().getPath(); return getCommonResponse(request); } else { //TODO: Deal with errors } } } } //TODO: Deal with permission error return getCommonResponse(request); }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationActionsFormatter.java
protected void renderDeleteFile() throws FileSystemException { if (fileNavigationHandler.isDeleteFileAllowed() || fileNavigationHandler.getUserStatus().isRootUser()) { FileObject currentFile = fileNavigationHandler.getCurrentFile(); if (currentFile != null && currentFile.isWriteable()) { FileObject parentDir = currentFile.getParent(); if (parentDir != null && parentDir.isWriteable()) { //setAttribute("folderName", parentDir.getName().getBaseName()); setAttribute("fileName", currentFile.getName().getBaseName()); renderFragment("deleteFile"); }//w w w . ja va 2 s.c o m } } }
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"); }//from w w w.j av a2s. c o m } } } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationActionsFormatter.java
protected void renderCreateFile() throws FileSystemException { if (fileNavigationHandler.isUploadFileAllowed() || fileNavigationHandler.getUserStatus().isRootUser()) { FileObject currentDir = fileNavigationHandler.getCurrentDir(); if (currentDir != null && currentDir.isWriteable()) { setAttribute("folderName", currentDir.getName().getBaseName()); renderFragment("uploadFileInput"); }// ww w . j av a 2s .c om } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationActionsFormatter.java
protected void renderCreateFolder() throws FileSystemException { if (fileNavigationHandler.isCreateFolderAllowed() || fileNavigationHandler.getUserStatus().isRootUser()) { FileObject currentDir = fileNavigationHandler.getCurrentDir(); if (currentDir != null && currentDir.isWriteable()) { setAttribute("folderName", currentDir.getName().getBaseName()); renderFragment("createFolderInput"); }//w w w . java2s. c o m } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationFileListFormatter.java
protected boolean matchesPattern(FileObject child, String currentFilter) { if (!StringUtils.isBlank(currentFilter)) { String search = currentFilter; search = StringUtils.replace(search, "?", "."); search = StringUtils.replace(search, "*", ".*"); try {/* w ww .ja v a2 s. co m*/ return child.getName().getBaseName().matches(search); } catch (PatternSyntaxException pse) { return false; } } return true; }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationFileListFormatter.java
protected void renderFiles(List sortedChildren) throws FileSystemException { if (!sortedChildren.isEmpty()) { renderFragment("outputStart"); for (int i = 0; i < sortedChildren.size(); i++) { FileObject fileObject = (FileObject) sortedChildren.get(i); FileContent content = fileObject.getContent(); setAttribute("fileObject", fileObject); setAttribute("name", fileObject.getName().getBaseName()); setAttribute("fileSize", content.getSize()); String path = fileObject.getName().getPath(); setAttribute("path", path); setAttribute("current", path.equals(getFileNavigationHandler().getCurrentFilePath())); String contentType = content.getContentInfo().getContentType(); String extension = fileObject.getName().getExtension(); if (contentType == null) { contentType = extension; }//from w w w.j av a2 s .com setAttribute("contentType", contentType); setAttribute("imageURL", getFileNavigationHandler().getFilesystemManager().getThumbnailPath(extension)); renderFragment("output"); } renderFragment("outputEnd"); } }
From source file:org.jboss.dashboard.ui.formatters.FileNavigationFilePreviewFormatter.java
public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException { try {//from w w w . j a v a 2 s.com FileObject currentFile = getFileNavigationHandler().getCurrentFile(); if (currentFile != null) { String contentType = currentFile.getContent().getContentInfo().getContentType(); if (contentType != null && contentType.startsWith("image")) { String imageUrl = getImageUrl(currentFile); setAttribute("imageUrl", imageUrl); renderFragment("outputAsImage"); } else { String extension = currentFile.getName().getExtension(); String imageUrl = getFileNavigationHandler().getFilesystemManager().getLargeIconPath(extension); setAttribute("imageUrl", imageUrl); setAttribute("url", getFileNavigationHandler().getFilesystemManager().getURI(currentFile)); setAttribute("fileName", currentFile.getName().getBaseName()); renderFragment("outputAsFile"); } } } 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); }//ww w. j a v a 2 s. c o 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"); } } }