List of usage examples for org.apache.commons.vfs FileObject isWriteable
public boolean isWriteable() throws FileSystemException;
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 . j av a 2 s .c om } } }
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"); }/* w w w.j a v a 2 s . com*/ } } } }
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"); }/*from ww w. j a v a 2 s . com*/ } }
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"); }//from w w w . j a va 2 s . c o m } }
From source file:org.pentaho.di.ui.repository.dialog.RepositoryExportProgressDialog.java
/** * Check if file is empty, writable, and return message dialogue box if file not empty, null otherwise. * //from w w w . j av a2 s.c o m * @param shell * @param log * @param filename * @return */ public static MessageBox checkIsFileIsAcceptable(Shell shell, LogChannelInterface log, String filename) { MessageBox box = null; // check if file is exists try { // check if file is not empty FileObject output = KettleVFS.getFileObject(filename); if (output.exists()) { if (!output.isWriteable()) { box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.OK | SWT.CANCEL); box.setText(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.AreadyExists")); box.setMessage(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.NoWritePermissions")); return box; } box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.OK | SWT.CANCEL); box.setText(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.AreadyExists")); box.setMessage( BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.Overwrite")); } // in case of exception - anyway we will not be able to write into this file. } catch (KettleFileException e) { log.logError("Can't access file: " + filename); } catch (FileSystemException e) { log.logError("Can't check if file exists/file permissions: " + filename); } return box; }
From source file:org.pentaho.platform.plugin.outputs.ApacheVFSOutputHandler.java
@Override public IContentItem getFileOutputContentItem() { String contentRef = getContentRef(); try {//from w ww . ja v a 2 s.c o m String contentName = getHandlerId().substring(4) + ":" + contentRef; //$NON-NLS-1$ FileSystemManager fsManager = VFS.getManager(); if (fsManager == null) { Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0001_CANNOT_GET_VFSMGR")); //$NON-NLS-1$ return null; } FileObject file = fsManager.resolveFile(contentName); if (file == null) { Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance() .getString("ApacheVFSOutputHandler.ERROR_0002_CANNOT_GET_VF", contentName)); //$NON-NLS-1$ return null; } if (!file.isWriteable()) { Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance() .getString("ApacheVFSOutputHandler.ERROR_0003_CANNOT_WRITE", contentName)); //$NON-NLS-1$ return null; } FileContent fileContent = file.getContent(); if (fileContent == null) { Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance() .getString("ApacheVFSOutputHandler.ERROR_0004_CANNOT_GET_CTX", contentName)); //$NON-NLS-1$ return null; } OutputStream outputStream = fileContent.getOutputStream(); SimpleContentItem content = new SimpleContentItem(outputStream); return content; } catch (Throwable t) { Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance() .getString("ApacheVFSOutputHandler.ERROR_0005_CANNOT_GET_HANDLER", contentRef), t); //$NON-NLS-1$ } return null; }
From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo();/*from ww w. j a v a 2 s. c om*/ FileObject file = resolveFile(context, path); io.println("URL: {}", file.getURL()); io.println("Name: {}", file.getName()); io.println("BaseName: {}", file.getName().getBaseName()); io.println("Extension: {}", file.getName().getExtension()); io.println("Path: {}", file.getName().getPath()); io.println("Scheme: {}", file.getName().getScheme()); io.println("URI: {}", file.getName().getURI()); io.println("Root URI: {}", file.getName().getRootURI()); io.println("Parent: {}", file.getName().getParent()); io.println("Type: {}", file.getType()); io.println("Exists: {}", file.exists()); io.println("Readable: {}", file.isReadable()); io.println("Writeable: {}", file.isWriteable()); io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { FileContent content = file.getContent(); FileContentInfo contentInfo = content.getContentInfo(); io.println("Content type: {}", contentInfo.getContentType()); io.println("Content encoding: {}", contentInfo.getContentEncoding()); try { // noinspection unchecked Map<String, Object> attrs = content.getAttributes(); if (attrs != null && !attrs.isEmpty()) { io.println("Attributes:"); for (Map.Entry<String, Object> entry : attrs.entrySet()) { io.println(" {}='{}'", entry.getKey(), entry.getValue()); } } } catch (FileSystemException e) { io.println("File attributes are NOT supported"); } try { Certificate[] certs = content.getCertificates(); if (certs != null && certs.length != 0) { io.println("Certificate:"); for (Certificate cert : certs) { io.println(" {}", cert); } } } catch (FileSystemException e) { io.println("File certificates are NOT supported"); } if (file.getType().equals(FileType.FILE)) { io.println("Size: {} bytes", content.getSize()); } else if (file.getType().hasChildren() && file.isReadable()) { FileObject[] children = file.getChildren(); io.println("Directory with {} files", children.length); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { io.println("#{}:{}", iterChildren, children[iterChildren].getName()); if (iterChildren > 5) { break; } } } io.println("Last modified: {}", DateFormat.getInstance().format(new Date(content.getLastModifiedTime()))); } else { io.println("The file does not exist"); } FileObjects.close(file); return Result.SUCCESS; }
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryAccess.java
public boolean canWrite(String file) { try {/* ww w . j a va 2 s . c o m*/ FileObject f = resolveFile(repo, file); return (f != null && f.isWriteable()); } catch (Exception e) { log.error("Cannot check canWrite for " + file, e); } return false; }
From source file:r.base.Files.java
/** * Gets the type or storage mode of an object. /*from w w w .j a v a2 s. com*/ * @return unix-style file mode integer */ private static int mode(FileObject file) throws FileSystemException { int access = 0; if (file.isReadable()) { access += 4; } if (file.isWriteable()) { access += 2; } if (file.getType() == FileType.FOLDER) { access += 1; } // i know this is braindead but i can't be bothered // to do octal math at the moment String digit = Integer.toString(access); String octalString = digit + digit + digit; return Integer.parseInt(octalString, 8); }
From source file:rsc.backend.modules.ips.IPS.java
public void connectionConnect() { try {//ww w . ja v a2 s. c om Connection c = host.getConnection(); FileObject fo = c.getFileSystem().resolveFile(snortConf); if (!fo.isWriteable() && fo.isReadable()) { JOptionPane.showMessageDialog(null, "cant write to snort.conf - your changes might be lost", "snort configuration", JOptionPane.INFORMATION_MESSAGE); } if (!fo.isReadable()) { JOptionPane.showMessageDialog(null, "cant read snort.conf", "snort configuration error", JOptionPane.ERROR_MESSAGE); } conf = SnortFactoryParser.createInstance(fo.getContent().getInputStream());//new Snortconf(fo.getContent().getInputStream()); fireChangeEvent(); } catch (ConfigurationException ex) { IPS.log(Level.SEVERE, "cant configure ips-configuration", ex); } catch (FileSystemException ex) { IPS.log(Level.SEVERE, "cant read ips-configuration", ex); } catch (Exception ex) { Logger.getLogger(IPS.class.getName()).log(Level.SEVERE, null, ex); } }