List of usage examples for org.apache.commons.vfs2 FileObject getType
FileType getType() throws FileSystemException;
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does an 'ls' command.//from w ww.j av a 2s. c o m * * @param cmd * @throws org.apache.commons.vfs2.FileSystemException */ public void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } switch (file.getType()) { case FOLDER: // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); break; case FILE: // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); break; case IMAGINARY: System.out.println(String.format("File '%s' is IMAGINARY", file.getName())); break; default: log.error(String.format("Unkown type '%d' on '%s'", file.getType(), file.getName())); break; } }
From source file:com.app.server.JarDeployer.java
/** * This method obtains the class name for each of the executor services * @param jarFile// ww w .j av a 2 s. c o m * @param classList * @throws FileSystemException */ public void getChildren(FileObject jarFile, CopyOnWriteArrayList classList) throws FileSystemException { if (jarFile.getType() == FileType.FILE) return; FileObject[] children = jarFile.getChildren(); //log.info( "Children of " + jarFile.getName().getURI() ); if (children == null) return; for (int i = 0; i < children.length; i++) { //log.info(children[i].+" "+ children[i].getName().getBaseName() ); if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class")) classList.add(children[i].toString().substring(children[i].toString().indexOf('!') + 2)); getChildren(children[i], classList); children[i].close(); //fsManager.closeFileSystem(children[i].getFileSystem()); } }
From source file:com.web.server.JarDeployer.java
/** * This method obtains the class name for each of the executor services * @param jarFile/*from ww w. j a va 2s .com*/ * @param classList * @throws FileSystemException */ public void getChildren(FileObject jarFile, CopyOnWriteArrayList classList) throws FileSystemException { if (jarFile.getType() == FileType.FILE) return; FileObject[] children = jarFile.getChildren(); //System.out.println( "Children of " + jarFile.getName().getURI() ); if (children == null) return; for (int i = 0; i < children.length; i++) { //System.out.println(children[i].+" "+ children[i].getName().getBaseName() ); if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class")) classList.add(children[i].toString().substring(children[i].toString().indexOf('!') + 2)); getChildren(children[i], classList); children[i].close(); //fsManager.closeFileSystem(children[i].getFileSystem()); } }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * It transforms FileObject into JsTreeNodeData. * @param file the file whose information will be encapsulated in the node data structure. * @return The node data structure which presents the file. * @throws FileSystemException /* ww w . java 2 s. c o m*/ */ protected JsTreeNodeData populateTreeNodeData(FileObject file, boolean noChild, String relativePath) throws FileSystemException { JsTreeNodeData node = new JsTreeNodeData(); String baseName = file.getName().getBaseName(); FileContent content = file.getContent(); FileType type = file.getType(); node.setData(baseName); Map<String, Object> attr = new HashMap<String, Object>(); node.setAttr(attr); attr.put("id", relativePath); attr.put("rel", type.getName()); attr.put("fileType", type.getName()); if (content != null) { long fileLastModifiedTime = file.getContent().getLastModifiedTime(); attr.put("fileLastModifiedTime", fileLastModifiedTime); attr.put("fileLastModifiedTimeForDisplay", DateFormat.getDateTimeInstance().format(new Date(fileLastModifiedTime))); if (file.getType() != FileType.FOLDER) { attr.put("fileSize", content.getSize()); attr.put("fileSizeForDisplay", FileUtils.byteCountToDisplaySize(content.getSize())); } } // these fields should not appear in JSON for leaf nodes if (!noChild) { node.setState(JsTreeNodeData.STATE_CLOSED); } return node; }
From source file:de.unioninvestment.portal.explorer.view.vfs.TableView.java
private void addTableItem(Table table, FileObject file) throws FileSystemException { if (file.getType() == FileType.FILE) { Item item = table.addItem(file.getName()); item.getItemProperty(TABLE_PROP_FILE_NAME).setValue(file.getName().toString()); item.getItemProperty(TABLE_PROP_FILE_SIZE).setValue(file.getContent().getSize()); item.getItemProperty(TABLE_PROP_FILE_DATE).setValue(new Date(file.getContent().getLastModifiedTime())); }//from www. j a va 2s . c o m }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Appends the specified FileObjects to the list of FileObjects to search * for classes and resources./*from w w w . j a v a2 s.c om*/ * * @param manager The FileSystemManager. * @param files the FileObjects to append to the search path. * @throws FileSystemException if an error occurs. */ private void addFileObjects(final FileSystemManager manager, final FileObject[] files) throws FileSystemException { for (int i = 0; i < files.length; i++) { FileObject file = files[i]; if (!file.exists()) { // Does not exist - skip continue; } // TODO - use federation instead if (file.getType().hasContent() && manager.canCreateFileSystem(file)) { // Use contents of the file file = manager.createFileSystem(file); } resources.add(file); } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
private static void determineChangedResources(int resourceType, FileObject categoryFolder, FileObject source, FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding, OverlayStatus status, Logger log, DesignFileValidator validator) throws WGDesignSyncException, NoSuchAlgorithmException, IOException { for (FileObject sourceFile : source.getChildren()) { if (!isValidDesignFile(sourceFile, validator)) { continue; }//from w w w . j av a2s . co m FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName()); String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName()); if (sourceFile.getType().equals(FileType.FOLDER)) { if (!targetFile.exists()) { status.getNewFolders().add(targetFile.getName().getPath()); } else if (targetFile.getType().equals(FileType.FILE)) { throw new WGDesignSyncException("Unable to apply overlay. Folder '" + baseFolder.getName().getRelativeName(targetFile.getName()) + " already exists as file. Delete it to enable overlay management again"); } determineChangedResources(resourceType, categoryFolder, sourceFile, targetFile, baseFolder, sourceEncoding, targetEncoding, status, log, validator); } else if (sourceFile.getType().equals(FileType.FILE)) { // File does not exist. if (!targetFile.exists()) { // Was it once deployed? ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { // No, so it must be new in base status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.NEW, resourcePath, null); } else { // Yes, Check if the base file changed since deployment String newHash = MD5HashingInputStream .getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { // Nope. So this is no change. The overlay just chose not to use the file continue; } else { // Yes, so it is indeed a conflict status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } } } // File does exist: Determine if is updated in base since the overlay file was deployed else { ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { if (!status.isUpdatedBaseDesign()) { log.info("There is no information about the original deployment state of resource " + resourcePath + ". Setting original deployment state now to the current base version."); OverlayData.ResourceData resource = new OverlayData.ResourceData(); resource.setMd5Hash( MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream())); status.getOverlayData().setOverlayResource(resourcePath, resource); } else { log.info("Cannot update overlay resource " + resourcePath + " as there is no information of its original deployment state."); } continue; } // First determine if the resource really changed from what was distributed String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { continue; } // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict String currentHash = MD5HashingInputStream .getStreamHash(targetFile.getContent().getInputStream()); if (!currentHash.equals(originalHash.getMd5Hash())) { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } // It is a normal change else { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CHANGED, resourcePath, null); } } } } }
From source file:net.sourceforge.fullsync.ui.FileObjectChooser.java
private void populateList() throws FileSystemException { FileObject[] children = activeFileObject.getChildren(); Arrays.sort(children, (o1, o2) -> { try {//from w w w .j a va2s . co m if ((o1.getType() == FileType.FOLDER) && (o2.getType() == FileType.FILE)) { return -1; } else if ((o1.getType() == FileType.FILE) && (o2.getType() == FileType.FOLDER)) { return 1; } return o1.getName().getBaseName().compareTo(o2.getName().getBaseName()); } catch (FileSystemException fse) { fse.printStackTrace(); return 0; } }); DateFormat df = DateFormat.getDateTimeInstance(); for (int i = 0; i < children.length; i++) { FileObject data = children[i]; TableItem item; if (tableItems.getItemCount() <= i) { item = new TableItem(tableItems, SWT.NULL); } else { item = tableItems.getItem(i); } item.setText(0, data.getName().getBaseName()); String type = data.getType().getName(); //FIXME: translate type name {file,folder} if (data.getType().hasContent()) { FileContent content = data.getContent(); String contentType = content.getContentInfo().getContentType(); if (null != contentType) { type += " (" + contentType + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } item.setText(1, String.valueOf(content.getSize())); item.setText(3, df.format(new Date(content.getLastModifiedTime()))); } else { item.setText(1, ""); //$NON-NLS-1$ item.setText(3, ""); //$NON-NLS-1$ } item.setText(2, type); if (data.getType() == FileType.FOLDER) { item.setImage(imageRepository.getImage("FS_Folder_Collapsed.gif")); //$NON-NLS-1$ } else { item.setImage(imageRepository.getImage("FS_File_text_plain.gif")); //$NON-NLS-1$ } item.setData(data); } tableItems.setItemCount(children.length); }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
public Properties readStartProperties(FileObject serviceRoot) throws FileSystemException, LocalizedRuntimeException, IOException { /*//w ww.j a va 2 s . c om Read the start.properties file. */ FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES); if (startProperties == null || !startProperties.getType().equals(FileType.FILE) || !startProperties.isReadable()) { throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, MessageNames.CANT_READ_START_PROPERTIES, new Object[] { Strings.START_PROPERTIES, serviceRoot.getName().getBaseName() }); } Properties startProps = propertiesFileReader.getProperties(startProperties); return startProps; }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does a 'cp' command./*from w w w . j a va 2 s . c o m*/ * * @param cmd * @throws SimpleShellException */ public void cp(String[] cmd) throws SimpleShellException { if (cmd.length < 3) { throw new SimpleShellException("USAGE: cp <src> <dest>"); } FileObject src = null; try { src = mgr.resolveFile(cwd, cmd[1]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving source file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } FileObject dest = null; try { dest = mgr.resolveFile(cwd, cmd[2]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving destination file '%s'", cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } } catch (FileSystemException ex) { String errMsg = String.format("Error resolving folder '%s'", cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { dest.copyFrom(src, Selectors.SELECT_ALL); } catch (FileSystemException ex) { String errMsg = String.format("Error copyFrom() file '%s' to '%s'", cmd[1], cmd[2]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } }