List of usage examples for org.apache.commons.vfs FileObject getChildren
public FileObject[] getChildren() throws FileSystemException;
From source file:com.vobject.appengine.java.io.File.java
/** * Lists the children of a folder./* ww w . j a v a2 s .c om*/ */ private String[] listChildrenAsStringArray(final FilenameFilter filter, final FileObject dir, final boolean recursive) throws FileSystemException { if (dir.getType() == FileType.FOLDER) { final FileObject[] children = dir.getChildren(); final List list = new ArrayList(); for (int i = 0; i < children.length; i++) { final FileObject child = children[i]; final String fileName = child.getName().getBaseName(); if (filter != null) { if (filter.accept(null, fileName)) { list.add(fileName); } } else { list.add(fileName); } if (child.getType() == FileType.FOLDER) { if (recursive) { String[] childNames = listChildrenAsStringArray(filter, child, recursive); list.addAll(Arrays.asList(childNames)); } } } return (String[]) list.toArray(new String[0]); } else { return null; } }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>// w ww . ja v a 2s. co m * ? ?? . * </p> * @param dir * <code>FileObject</code> * @param recursive * <code>boolean</code> * @param prefix * <code>String</code> * @return ? * @throws FileSystemException */ private StringBuffer listChildren(final FileObject dir, final boolean recursive, final String prefix) throws FileSystemException { StringBuffer line = new StringBuffer(); final FileObject[] children = dir.getChildren(); for (int i = 0; i < children.length; i++) { final FileObject child = children[i]; // log.info(prefix + // child.getName().getBaseName()); line.append(prefix).append(child.getName().getBaseName()); if (child.getType() == FileType.FOLDER) { // log.info("/"); line.append("/"); if (recursive) { line.append(listChildren(child, recursive, prefix + " ")); } } else { line.append(""); } } return line; }
From source file:com.panet.imeta.core.plugins.PluginLoader.java
/** * This method does the actual plugin configuration and should be called * after load()/*from w w w . j a v a2 s . com*/ * * @return a collection containing the <code>JobPlugin</code> objects * loaded. * @throws KettleConfigException */ private void doConfig() throws KettleConfigException { synchronized (locs) { String sjar = "." + JAR; for (PluginLocation plugin : locs) { // check to see if the resource type is present File base = new File(System.getProperty("user.dir")); try { FileSystemManager mgr = VFS.getManager(); FileObject fobj = mgr.resolveFile(base, plugin.getLocation()); if (fobj.isReadable()) { String name = fobj.getName().getURI(); int jindex = name.indexOf(sjar); int nlen = name.length(); boolean isJar = jindex == nlen - 4 || jindex == nlen - 6; try { if (isJar) build(fobj, true); else { // loop thru folder for (FileObject childFolder : fobj.getChildren()) { boolean isAlsoJar = childFolder.getName().getURI().endsWith(sjar); // ignore anything that is not a folder or a // jar if (!isAlsoJar && childFolder.getType() != FileType.FOLDER) { continue; } // ignore any subversion or CVS directories if (childFolder.getName().getBaseName().equalsIgnoreCase(".svn")) { continue; } else if (childFolder.getName().getBaseName().equalsIgnoreCase(".cvs")) { continue; } try { build(childFolder, isAlsoJar); } catch (KettleConfigException e) { log.logError(Plugin.PLUGIN_LOADER, e.getMessage()); continue; } } } } catch (FileSystemException e) { log.logError(Plugin.PLUGIN_LOADER, e.getMessage()); continue; } catch (KettleConfigException e) { log.logError(Plugin.PLUGIN_LOADER, e.getMessage()); continue; } } else { log.logDebug(Plugin.PLUGIN_LOADER, fobj + " does not exist, ignoring this."); } } catch (Exception e) { throw new KettleConfigException(e); } } } }
From source file:com.panet.imeta.job.entries.ssh2put.JobEntrySSH2PUT.java
private List<FileObject> getFiles(String localfolder) throws IOException { List<FileObject> myFileList = new ArrayList<FileObject>(); // Get all the files in the local directory... FileObject localFiles = KettleVFS.getFileObject(localfolder); FileObject[] children = localFiles.getChildren(); if (children != null) { for (int i = 0; i < children.length; i++) { // Get filename of file or directory if (children[i].getType().equals(FileType.FILE)) { myFileList.add(children[i]); }//from w w w. ja v a 2 s . c o m } // end for } return myFileList; }
From source file:com.panet.imeta.core.plugins.PluginLoader.java
private void build(FileObject parent, boolean isJar) throws KettleConfigException { try {/*from w w w . j av a2 s. com*/ FileObject xml = null; if (isJar) { FileObject exploded = explodeJar(parent); // try reading annotations first ... ResolverUtil<Plugin> resPlugins = new ResolverUtil<Plugin>(); // grab all jar files not part of the "lib" File fparent = new File(exploded.getURL().getFile()); File[] files = fparent.listFiles(new JarNameFilter()); URL[] classpath = new URL[files.length]; for (int i = 0; i < files.length; i++) classpath[i] = files[i].toURI().toURL(); ClassLoader cl = new PDIClassLoader(classpath, Thread.currentThread().getContextClassLoader()); resPlugins.setClassLoader(cl); for (FileObject couldBeJar : exploded.getChildren()) { if (couldBeJar.getName().getExtension().equals(JAR)) resPlugins.loadImplementationsInJar(Const.EMPTY_STRING, couldBeJar.getURL(), tests.values().toArray(new ResolverUtil.Test[2])); } for (Class<? extends Plugin> match : resPlugins.getClasses()) { for (Class<? extends Annotation> cannot : tests.keySet()) { Annotation annot = match.getAnnotation(cannot); if (annot != null) fromAnnotation(annot, exploded, match); } } // and we also read from the xml if present xml = exploded.getChild(Plugin.PLUGIN_XML_FILE); if (xml == null || !xml.exists()) return; parent = exploded; } else xml = parent.getChild(Plugin.PLUGIN_XML_FILE); // then read the xml if it is there if (xml != null && xml.isReadable()) fromXML(xml, parent); } catch (Exception e) { throw new KettleConfigException(e); } // throw new KettleConfigException("Unable to read plugin.xml from " + // parent); }
From source file:com.panet.imeta.job.entries.unzip.JobEntryUnZip.java
private boolean processOneFile(LogWriter log, Result result, Job parentJob, FileObject fileObject, String realTargetdirectory, String realWildcard, String realWildcardExclude, FileObject movetodir, String realMovetodirectory, String realWildcardSource) { boolean retval = false; try {//from w ww. j a va2s. c o m if (fileObject.getType().equals(FileType.FILE)) { // We have to unzip one zip file if (!unzipFile(log, fileObject, realTargetdirectory, realWildcard, realWildcardExclude, result, parentJob, fileObject, movetodir, realMovetodirectory)) updateErrors(); else updateSuccess(); } else { // Folder..let's see wildcard FileObject[] children = fileObject.getChildren(); for (int i = 0; i < children.length && !parentJob.isStopped(); i++) { if (successConditionBroken) { if (!successConditionBrokenExit) { log.logError(toString(), Messages.getString("JobUnZip.Error.SuccessConditionbroken", "" + NrErrors)); successConditionBrokenExit = true; } return false; } // Get only file! if (!children[i].getType().equals(FileType.FOLDER)) { boolean unzip = true; String filename = children[i].getName().getPath(); Pattern patternSource = null; if (!Const.isEmpty(realWildcardSource)) patternSource = Pattern.compile(realWildcardSource); // First see if the file matches the regular expression! if (patternSource != null) { Matcher matcher = patternSource.matcher(filename); unzip = matcher.matches(); } if (unzip) { if (!unzipFile(log, children[i], realTargetdirectory, realWildcard, realWildcardExclude, result, parentJob, fileObject, movetodir, realMovetodirectory)) updateErrors(); else updateSuccess(); } } } } } catch (Exception e) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Error.Label", e.getMessage())); } finally { if (fileObject != null) { try { fileObject.close(); } catch (IOException ex) { } ; } } return retval; }
From source file:com.panet.imeta.core.fileinput.FileInputList.java
public static FileInputList createFileList(VariableSpace space, String[] fileName, String[] fileMask, String[] fileRequired, boolean[] includeSubdirs, FileTypeFilter[] fileTypeFilters) { FileInputList fileInputList = new FileInputList(); // Replace possible environment variables... final String realfile[] = space.environmentSubstitute(fileName); final String realmask[] = space.environmentSubstitute(fileMask); for (int i = 0; i < realfile.length; i++) { final String onefile = realfile[i]; final String onemask = realmask[i]; final boolean onerequired = YES.equalsIgnoreCase(fileRequired[i]); final boolean subdirs = includeSubdirs[i]; final FileTypeFilter filter = ((fileTypeFilters == null || fileTypeFilters[i] == null) ? FileTypeFilter.ONLY_FILES : fileTypeFilters[i]);//from ww w .ja v a 2 s . c o m if (Const.isEmpty(onefile)) continue; // // If a wildcard is set we search for files // if (!Const.isEmpty(onemask)) { try { // Find all file names that match the wildcard in this directory // FileObject directoryFileObject = KettleVFS.getFileObject(onefile); if (directoryFileObject != null && directoryFileObject.getType() == FileType.FOLDER) // it's a directory { FileObject[] fileObjects = directoryFileObject.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return info.getDepth() == 0 || subdirs; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); try { if (fileObject != null && filter.isFileTypeAllowed(fileObject.getType())) { String name = fileObject.getName().getBaseName(); boolean matches = Pattern.matches(onemask, name); /* if (matches) { System.out.println("File match: URI: "+info.getFile()+", name="+name+", depth="+info.getDepth()); } */ return matches; } return false; } catch (FileSystemException ex) { // Upon error don't process the file. return false; } } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length; j++) { if (fileObjects[j].exists()) fileInputList.addFile(fileObjects[j]); } } if (Const.isEmpty(fileObjects)) { if (onerequired) fileInputList.addNonAccessibleFile(directoryFileObject); } // Sort the list: quicksort, only for regular files fileInputList.sortFiles(); } else { FileObject[] children = directoryFileObject.getChildren(); for (int j = 0; j < children.length; j++) { // See if the wildcard (regexp) matches... String name = children[j].getName().getBaseName(); if (Pattern.matches(onemask, name)) fileInputList.addFile(children[j]); } // We don't sort here, keep the order of the files in the archive. } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } else // A normal file... { try { FileObject fileObject = KettleVFS.getFileObject(onefile); if (fileObject.exists()) { if (fileObject.isReadable()) { fileInputList.addFile(fileObject); } else { if (onerequired) fileInputList.addNonAccessibleFile(fileObject); } } else { if (onerequired) fileInputList.addNonExistantFile(fileObject); } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } } return fileInputList; }
From source file:org.apache.commons.vfs.example.Shell.java
/** * Lists the children of a folder./*from w w w . j a va2s . c o m*/ */ private void listChildren(final FileObject dir, final boolean recursive, final String prefix) throws FileSystemException { final FileObject[] children = dir.getChildren(); for (int i = 0; i < children.length; i++) { final FileObject child = children[i]; System.out.print(prefix); System.out.print(child.getName().getBaseName()); if (child.getType() == FileType.FOLDER) { System.out.println("/"); if (recursive) { listChildren(child, recursive, prefix + " "); } } else { System.out.println(); } } }
From source file:org.apache.commons.vfs.example.ShowProperties.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs.example.ShowProperties LICENSE.txt"); return;//from w w w . j a v a 2 s . c o m } for (int i = 0; i < args.length; i++) { try { FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + args[i]); FileObject file = mgr.resolveFile(args[i]); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }
From source file:org.apache.ivy.plugins.repository.vfs.VfsRepository.java
/** * Return a listing of the contents of a parent directory. Listing is a set of strings * representing VFS URIs.//from ww w .j a va 2 s.c o m * * @param vfsURI * providing identifying a VFS provided resource * @throws IOException * on failure. * @see "Supported File Systems in the jakarta-commons-vfs documentation" */ public List list(String vfsURI) throws IOException { ArrayList list = new ArrayList(); Message.debug("list called for URI" + vfsURI); FileObject resourceImpl = getVFSManager().resolveFile(vfsURI); Message.debug("resourceImpl=" + resourceImpl.toString()); Message.debug("resourceImpl.exists()" + resourceImpl.exists()); Message.debug("resourceImpl.getType()" + resourceImpl.getType()); Message.debug("FileType.FOLDER" + FileType.FOLDER); if ((resourceImpl != null) && resourceImpl.exists() && (resourceImpl.getType() == FileType.FOLDER)) { FileObject[] children = resourceImpl.getChildren(); for (int i = 0; i < children.length; i++) { FileObject child = children[i]; Message.debug("child " + i + child.getName().getURI()); list.add(VfsResource.normalize(child.getName().getURI())); } } return list; }