List of usage examples for org.apache.commons.vfs FileSelectInfo getFile
FileObject getFile();
From source file:org.pentaho.di.repository.KettleFileRepositoryTest.java
private void verifyJobSamples(RepositoryDirectoryInterface samplesDirectory) throws Exception { FileObject jobSamplesFolder = KettleVFS.getFileObject("samples/jobs/"); FileObject[] files = jobSamplesFolder.findFiles(new FileSelector() { @Override/*from ww w. ja v a 2s .c o m*/ public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getExtension().equalsIgnoreCase("kjb"); } }); List<FileObject> filesList = Arrays.asList(files); Collections.sort(filesList, new Comparator<FileObject>() { @Override public int compare(FileObject o1, FileObject o2) { return o1.getName().getPath().compareTo(o2.getName().getPath()); } }); for (FileObject file : filesList) { String jobFilename = file.getName().getPath(); System.out.println("Storing/Loading/validating job '" + jobFilename + "'"); // Load the JobMeta object... // JobMeta jobMeta = new JobMeta(jobFilename, repository); jobMeta.setFilename(null); // The name is sometimes empty in the file, duplicates are present too... // Replaces slashes and the like as well... // jobMeta.setName(Const.createName(file.getName().getBaseName())); jobMeta.setName(jobMeta.getName().replace('/', '-')); if (Const.isEmpty(jobMeta.getName())) { jobMeta.setName(Const.createName(file.getName().getBaseName())); } if (jobMeta.getName().contains("/")) { jobMeta.setName(jobMeta.getName().replace('/', '-')); } // Save it in the repository in the samples folder // jobMeta.setRepositoryDirectory(samplesDirectory); repository.save(jobMeta, "unit testing"); assertNotNull(jobMeta.getObjectId()); // Load it back up again... // JobMeta repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String oneXml = repJobMeta.getXML(); // Save & load it again // repository.save(jobMeta, "unit testing"); repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String twoXml = repJobMeta.getXML(); // The XML needs to be identical after loading // // storeFile(oneXml, "/tmp/one.ktr"); // storeFile(twoXml, "/tmp/two.ktr"); // assertEquals(oneXml, twoXml); } // Verify the number of stored files, see if we can find them all again. // System.out.println("Stored " + files.length + " job samples in folder " + samplesDirectory.getPath()); String[] jobNames = repository.getJobNames(samplesDirectory.getObjectId(), false); assertEquals(files.length, jobNames.length); }
From source file:org.pentaho.di.ui.i18n.MessagesSourceCrawler.java
public void crawl() throws Exception { for (final String sourceDirectory : sourceDirectories) { FileObject folder = KettleVFS.getFileObject(sourceDirectory); FileObject[] javaFiles = folder.findFiles(new FileSelector() { @Override/*from w w w . j ava2s . c om*/ public boolean traverseDescendents(FileSelectInfo info) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getExtension().equals("java"); } }); for (FileObject javaFile : javaFiles) { /** * We don't want the Messages.java files, there is nothing in there for us. */ boolean skip = false; for (String filename : filesToAvoid) { if (javaFile.getName().getBaseName().equals(filename)) { skip = true; } } if (skip) { continue; // don't process this file. } // For each of these files we look for keys... // lookForOccurrencesInFile(sourceDirectory, javaFile); } } // Also search for keys in the XUL files... // for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) { String[] xmlDirs = { xmlFolder.getFolder(), }; String[] xmlMasks = { xmlFolder.getWildcard(), }; String[] xmlReq = { "N", }; boolean[] xmlSubdirs = { true, }; // search sub-folders too FileInputList xulFileInputList = FileInputList.createFileList(new Variables(), xmlDirs, xmlMasks, xmlReq, xmlSubdirs); for (FileObject fileObject : xulFileInputList.getFiles()) { try { Document doc = XMLHandler.loadXMLFile(fileObject); // Scan for elements and tags in this file... // for (SourceCrawlerXMLElement xmlElement : xmlFolder.getElements()) { addLabelOccurrences(xmlFolder.getDefaultSourceFolder(), fileObject, doc.getElementsByTagName(xmlElement.getSearchElement()), xmlFolder.getKeyPrefix(), xmlElement.getKeyTag(), xmlElement.getKeyAttribute(), xmlFolder.getDefaultPackage(), xmlFolder.getPackageExceptions()); } } catch (KettleXMLException e) { log.logError("Unable to open XUL / XML document: " + fileObject); } } } }
From source file:org.sonatype.gshell.commands.vfs.ListDirectoryCommand.java
private void listChildren(final IO io, final FileObject dir) throws Exception { assert io != null; assert dir != null; FileObject[] files;/*from www . j av a 2 s . c o m*/ if (includeHidden) { files = dir.getChildren(); } else { FileFilter filter = new FileFilter() { public boolean accept(final FileSelectInfo selection) { assert selection != null; try { return !selection.getFile().isHidden(); } catch (FileSystemException e) { throw new RuntimeException(e); } } }; files = dir.findFiles(new FileFilterSelector(filter)); } ConsoleReader reader = new ConsoleReader(io.streams.in, io.out, io.getTerminal()); reader.setPaginationEnabled(false); List<String> names = new ArrayList<String>(files.length); List<FileObject> dirs = new LinkedList<FileObject>(); for (FileObject file : files) { String fileName = file.getName().getBaseName(); if (FileObjects.hasChildren(file)) { fileName += FileName.SEPARATOR; if (recursive) { dirs.add(file); } } names.add(fileName); file.close(); } if (longList) { for (String name : names) { io.out.println(name); } } else { reader.printColumns(names); } if (!dirs.isEmpty()) { for (FileObject subdir : dirs) { io.out.println(); io.out.print(subdir.getName().getBaseName()); io.out.print(":"); listChildren(io, subdir); } } dir.close(); }