List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:com.newatlanta.appengine.vfs.provider.GaeFileSystemManager.java
/** * Sets the base file to use when resolving relative URI. Base file must * be a sub-directory of the root path; set equal to the root path if null. * //w ww . ja v a2 s.c o m * @param baseFile The new base FileObject. * @throws FileSystemException if an error occurs. */ @Override public void setBaseFile(FileObject baseFile) throws FileSystemException { if (baseFile == null) { baseFile = rootObject; } else if (!rootObject.getName().isDescendent(baseFile.getName())) { throw new FileSystemException("Base file must be a descendent of root."); } super.setBaseFile(baseFile); }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileSystemManager.java
private String checkRelativity(FileObject baseFile, String uri) throws FileSystemException { if ((baseFile != null) && uri.startsWith("/")) { String basePath = GaeFileNameParser.getRootPath(baseFile.getName()); if (!uri.startsWith(basePath)) { return uri.substring(1); }/*from w w w .j ava 2s. c om*/ } return uri; }
From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java
public void testDoCreateFileSystem() throws FileSystemException { FileObject object = ROOT.resolveFile("/"); Assert.assertEquals(BUCKETID, ((S3FileName) object.getName()).getRootFile()); }
From source file:com.pongasoft.kiwidoc.builder.RepositoryContentHandler.java
/** * Loads the content of the given resource. * * @param resource the resource to load// w ww. ja va2 s. c om * @return the content as an object since it depends on which content is being read (ex: manifest, * library, packages, class) (never <code>null</code>) * @throws NoSuchContentException if the content does not exist * @throws StoreException if there is a problem reading the content. */ public RepositoryModel loadContent(RepositoryResource resource) throws NoSuchContentException, StoreException { if (resource == null) throw new NoSuchContentException(resource); Collection<LibraryVersionResource> lvc = new ArrayList<LibraryVersionResource>(); FileObject root = getResourceFile(resource); try { FileObject[] organisations = root.findFiles(_fileSelector); for (FileObject organisation : organisations) { if (organisation.getType() == FileType.FOLDER) { OrganisationResource organisationResource = new OrganisationResource( organisation.getName().getBaseName()); FileObject[] libraries = organisation.getChildren(); for (FileObject library : libraries) { LibraryResource libraryResource = new LibraryResource(organisationResource, library.getName().getBaseName()); FileObject[] libraryVersions = library.getChildren(); for (FileObject libraryVersion : libraryVersions) { lvc.add(new LibraryVersionResource(libraryResource, libraryVersion.getName().getBaseName())); } } } } } catch (FileSystemException e) { throw new StoreException(e); } return new RepositoryModel(lvc); }
From source file:com.thinkberg.moxo.dav.WebdavHandler.java
/** * Get the destination object or collection. The destination header contains * a URL to the destination which is returned as a file object. * //from w ww .j a v a2 s.co m * @param request * the servlet request * @return the file object of the destination * @throws FileSystemException * if the file system cannot create a file object * @throws MalformedURLException * if the url is misformatted */ FileObject getDestination(HttpServletRequest request) throws FileSystemException, MalformedURLException { String targetUrlStr = request.getHeader("Destination"); FileObject targetObject = null; if (null != targetUrlStr) { URL target = new URL(targetUrlStr); targetObject = getResourceManager().getFileObject(target.getPath()); log("Destination: " + targetObject.getName().getPath()); } return targetObject; }
From source file:com.thinkberg.webdav.WebdavHandler.java
/** * Get the destination object or collection. The destination header contains * a URL to the destination which is returned as a file object. * * @param request the servlet request//from w ww.j a v a 2 s. c o m * @return the file object of the destination * @throws FileSystemException if the file system cannot create a file object * @throws MalformedURLException if the url is misformatted */ FileObject getDestination(HttpServletRequest request) throws FileSystemException, MalformedURLException { String targetUrlStr = request.getHeader("Destination"); FileObject targetObject = null; if (null != targetUrlStr) { URL target = new URL(targetUrlStr); targetObject = VFSBackend.resolveFile(target.getPath()); LOG.debug(String.format("request header: Destination: %s", targetObject.getName().getPath())); } return targetObject; }
From source file:com.newatlanta.appengine.junit.vfs.provider.GaeProviderTestCase.java
/** * Returns the base folder for tests. Copies test files from the local file * system to GaeVFS. Note that SVN (.svn) folders are not copied; if the are, * then the size of the LRUFilesCache created within GaeFileSystemManager.prepare() * must be increased to avoid testcase failures. *//*from www . java2 s .c o m*/ @Override public FileObject getBaseTestFolder(FileSystemManager manager) throws Exception { FileObject gaeTestBaseDir = manager.getBaseFile().resolveFile("test-data"); if (!gaeTestBaseDir.exists()) { FileObject localTestBaseDir = manager .resolveFile("file://" + GaeFileNameParser.getRootPath(manager.getBaseFile().getName()) + gaeTestBaseDir.getName().getPath()); gaeTestBaseDir.copyFrom(localTestBaseDir, new TestFileSelector()); // confirm that the correct number of files were copied FileObject[] testFiles = localTestBaseDir.findFiles(new TestFileSelector()); FileObject[] gaeFiles = gaeTestBaseDir.findFiles(Selectors.SELECT_FILES); assertEquals(testFiles.length, gaeFiles.length); } return gaeTestBaseDir; }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private FileObject testCreateTestFolder(FileObject rootObject) throws Exception { FileObject testFolder = GaeVFS.resolveFile("testFolder"); assertFalse(testFolder.exists());/*from w w w . j ava 2 s . c om*/ testFolder.createFolder(); assertFolder(testFolder); assertEquals(rootObject, testFolder.getParent()); assertTrue(testFolder.getName().isAncestor(rootObject.getName())); assertTrue(rootObject.getName().isDescendent(testFolder.getName())); assertChildren(rootObject, rootChildren); assertEntity(rootObject); return testFolder; }
From source file:com.panet.imeta.job.entries.deleteresultfilenames.JobEntryDeleteResultFilenames.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; result.setResult(false);/*w ww. j a v a 2 s . co m*/ if (previousResult != null) { try { int size = previousResult.getResultFiles().size(); if (log.isBasic()) log.logBasic(toString(), Messages.getString("JobEntryDeleteResultFilenames.log.FilesFound", "" + size)); if (!specifywildcard) { // Delete all files previousResult.getResultFiles().clear(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryDeleteResultFilenames.log.DeletedFiles", "" + size)); } else { List<ResultFile> resultFiles = result.getResultFilesList(); if (resultFiles != null && resultFiles.size() > 0) { for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped();) { ResultFile resultFile = (ResultFile) it.next(); FileObject file = resultFile.getFile(); if (file != null && file.exists()) { if (CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcard), true) && !CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcardexclude), false)) { // Remove file from result files list result.getResultFiles().remove(resultFile.getFile().toString()); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryDeleteResultFilenames.log.DeletedFile", file.toString())); } } } } } result.setResult(true); } catch (Exception e) { log.logError(toString(), Messages.getString("JobEntryDeleteResultFilenames.Error", e.toString())); } } return result; }
From source file:net.sf.jvifm.ui.ZipLister.java
private File extractToTemp(FileObject fileObject) { String basename = fileObject.getName().getBaseName(); File tempFile = null;/*from w w w. j a v a 2s. c om*/ try { String tmpPath = System.getProperty("java.io.tmpdir"); tempFile = new File(FilenameUtils.concat(tmpPath, basename)); byte[] buf = new byte[4096]; BufferedInputStream bin = new BufferedInputStream(fileObject.getContent().getInputStream()); BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(tempFile)); while (bin.read(buf, 0, 1) != -1) { bout.write(buf, 0, 1); } bout.close(); bin.close(); // by barney } catch (Throwable e) { e.printStackTrace(); } return tempFile; }