List of usage examples for org.apache.commons.vfs2 FileObject getURL
URL getURL() throws FileSystemException;
From source file:com.google.code.docbook4j.renderer.BaseRenderer.java
protected Transformer createTransformer(FileObject xmlSource, FileObject xslStylesheet) throws TransformerConfigurationException, IOException { TransformerFactory transformerFactory = createTransformerFactory(); if (xslStylesheet != null) { transformerFactory.setURIResolver(new XslURIResolver()); }//from w w w .j a v a 2 s . c o m FileObject xsl = xslStylesheet != null ? xslStylesheet : getDefaultXslStylesheet(); Source source = new StreamSource(xsl.getContent().getInputStream(), xsl.getURL().toExternalForm()); Transformer transformer = transformerFactory.newTransformer(source); transformer.setParameter("use.extensions", "1"); transformer.setParameter("callout.graphics", "0"); transformer.setParameter("callout.unicode", "1"); transformer.setParameter("callouts.extension", "1"); transformer.setParameter("base.dir", xmlSource.getParent().getURL().toExternalForm()); for (Map.Entry<String, String> entry : this.params.entrySet()) { transformer.setParameter(entry.getKey(), entry.getValue()); } return transformer; }
From source file:architecture.ee.spring.scripting.groovy.GroovyScriptEngineFactory.java
public void afterPropertiesSet() throws Exception { if (this.groovyScriptEngine == null) { ApplicationProperties setupProperties = AdminHelper.getRepository().getSetupApplicationProperties(); String path = setupProperties.get(ApplicationConstants.SCRIPTING_GROOVY_SOURCE_LOCATION_PROP_NAME); String sourceEncoding = setupProperties .get(ApplicationConstants.SCRIPTING_GROOVY_SOURCE_ENCODING_PROP_NAME); boolean recompileGroovySource = setupProperties .getBooleanProperty(ApplicationConstants.SCRIPTING_GROOVY_SOURCE_RECOMPILE_PROP_NAME, false); if (StringUtils.isEmpty(path)) { path = AdminHelper.getRepository().getURI("groovy"); }//from w w w.java 2 s . c o m if (StringUtils.isEmpty(sourceEncoding)) sourceEncoding = ApplicationConstants.DEFAULT_CHAR_ENCODING; if (log.isErrorEnabled()) log.debug(L10NUtils.format("003031", path)); FileObject fo = VFSUtils.resolveFile(path); CompilerConfiguration config = CompilerConfiguration.DEFAULT; config.setRecompileGroovySource(recompileGroovySource); config.setSourceEncoding(sourceEncoding); this.groovyScriptEngine = new GroovyScriptEngine(new URL[] { fo.getURL() }); } }
From source file:functionaltests.dataspaces.TestUserSpace.java
@Test public void testUserSpace() throws Throwable { File in = tmpFolder.newFolder("input_space"); String inPath = in.getAbsolutePath(); File out = tmpFolder.newFolder("output_space"); String outPath = out.getAbsolutePath(); FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager(); Scheduler sched = schedulerHelper.getSchedulerInterface(); String userURI = sched.getUserSpaceURIs().get(0); assertTrue(userURI.startsWith("file:")); log("User URI is " + userURI); String userPath = new File(new URI(userURI)).getAbsolutePath(); FileObject pathReplaceFO = fsManager.resolveFile(userURI + "/" + pathReplaceFile); if (pathReplaceFO.exists()) { pathReplaceFO.delete();//www . j ava2s .co m } /** * Writes inFiles in INPUT */ writeFiles(inFiles, inPath); File testPathRepl = new File(inPath + File.separator + pathReplaceFile); testPathRepl.createNewFile(); PrintWriter out2 = new PrintWriter( new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testPathRepl)))); out2.print(pathReplaceFile); out2.close(); TaskFlowJob job = new TaskFlowJob(); job.setName(this.getClass().getSimpleName()); job.setInputSpace(in.toURI().toURL().toString()); job.setOutputSpace(out.toURI().toURL().toString()); JavaTask A = new JavaTask(); A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask"); A.setForkEnvironment(new ForkEnvironment()); A.setName("A"); for (String[] file : inFiles) { A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace); A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToUserSpace); } A.setPreScript(new SimpleScript(scriptA, "groovy")); job.addTask(A); JavaTask B = new JavaTask(); B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask"); B.setForkEnvironment(new ForkEnvironment()); B.setName("B"); B.addDependence(A); for (String[] file : inFiles) { B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromUserSpace); B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace); } B.setPreScript(new SimpleScript(scriptB, "groovy")); job.addTask(B); JobId id = sched.submit(job); schedulerHelper.waitForEventJobFinished(id); JobResult jr = schedulerHelper.getJobResult(id); Assert.assertFalse(jr.hadException()); /** * check: inFiles > IN > LOCAL A > GLOBAL > LOCAL B > OUT */ for (String[] inFile : inFiles) { File f = new File(outPath + File.separator + inFile[0] + ".out"); assertTrue("File does not exist: " + f.getAbsolutePath(), f.exists()); Assert.assertEquals("Original and copied files differ", inFile[1], FileUtils.readFileToString(f)); File inf = new File(inPath + File.separator + inFile[0]); } /** * check that the file produced is accessible in the global user space via the scheduler API */ for (String[] file : inFiles) { FileObject outFile = fsManager.resolveFile(userURI + "/" + file[0] + ".glob.A"); log("Checking existence of " + outFile.getURL()); assertTrue(outFile.getURL() + " exists", outFile.exists()); File outFile2 = new File(userPath, file[0] + ".glob.A"); log("Checking existence of " + outFile2); assertTrue(outFile2 + " exists", outFile2.exists()); } }
From source file:com.google.code.docbook4j.XslURIResolver.java
public Source resolve(String href, String base) throws TransformerException { log.debug("Resolving href={} for base={}", href, base); if (href == null || href.trim().length() == 0) return null; if (docbookXslBase == null && href.startsWith("res:") && href.endsWith("docbook.xsl")) { try {/*from w w w .j ava 2 s.c o m*/ docbookXslBase = FileObjectUtils.resolveFile(href).getParent().getURL().toExternalForm(); } catch (FileSystemException e) { docbookXslBase = null; } } String normalizedBase = null; if (base != null) { try { normalizedBase = FileObjectUtils.resolveFile(base).getParent().getURL().toExternalForm(); } catch (FileSystemException e) { normalizedBase = null; } } try { FileObject urlFileObject = FileObjectUtils.resolveFile(href, normalizedBase); if (!urlFileObject.exists()) throw new FileSystemException("File object not found: " + urlFileObject); return new StreamSource(urlFileObject.getContent().getInputStream(), urlFileObject.getURL().toExternalForm()); } catch (FileSystemException e) { // not exists for given base? try with docbook base... try { if (docbookXslBase != null) { FileObject urlFileObject = FileObjectUtils.resolveFile(href, docbookXslBase); return new StreamSource(urlFileObject.getContent().getInputStream(), urlFileObject.getURL().toExternalForm()); } } catch (FileSystemException e1) { // do nothing. } log.error("Error resolving href=" + href + " for base=" + base, e); } return null; }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
/** * Scans the folders/* w w w . ja v a 2s .co m*/ * * @param folders * @return a List of MovieInfo * * TODO get rid of the synchronized and create a factory or pass all state data */ @Override public synchronized List<FileGroup> scan(final Set<FileObject> folders, AsyncMonitor monitor) { movies = new ArrayList<FileGroup>(); if (monitor != null) { monitor.start(); } for (FileObject folder : folders) { try { URL url = folder.getURL(); if (folder.exists()) { currentLabel = folder.getName().getBaseName(); LOGGER.info("scanning " + url); try { browse(folder, monitor); } catch (InterruptedException ie) { LOGGER.info("task is cancelled!" + ie.getMessage()); return null; } } else { LOGGER.warn("folder " + folder.getURL() + " does not exist!"); } } catch (FileSystemException e) { LOGGER.error("error during checking " + folder + ", " + e.getMessage(), e); } } if (monitor != null) { monitor.finish(); } return movies; }
From source file:com.nesscomputing.velocity.VelocityGuiceModule.java
protected void walk(Set<String> foundTemplates, final String prefix, FileObject root) throws FileSystemException, URISyntaxException { List<FileObject> foundFiles = Lists.newArrayList(); root.findFiles(new MacroFileSelector(), true, foundFiles); for (FileObject file : foundFiles) { String templateName = StringUtils.removeEndIgnoreCase(root.getName().getRelativeName(file.getName()), ".vm"); String bindName = prefix + "." + templateName; if (!foundTemplates.add(bindName)) { continue; }//from www.j ava2 s .co m UriTemplateProvider provider = new UriTemplateProvider(file.getURL().toURI()); bind(Template.class).annotatedWith(Names.named(bindName)).toProvider(provider).in(Scopes.SINGLETON); } }
From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java
/** * Find a resource by searching through all the classpath entries that have * been set up./* w w w . j ava 2 s . c o m*/ * * @param name * @return */ @Override public URL findResource(final String name) { try { return (URL) Security.doPrivileged(new PrivilegedExceptionAction<URL>() { @Override public URL run() throws Exception { FileObject fo = findResourceFileObject(name); return fo == null ? null : fo.getURL(); } }); } catch (Exception ex) { Logger.getLogger(VirtualFileSystemClassLoader.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java
@Override public Enumeration<URL> findResources(final String name) throws IOException { if (log.isLoggable(Level.FINE)) { log.fine("findResourceFileObjects(" + name + ")"); }//from w ww.java 2 s. c o m Enumeration result = (Enumeration) Security.doPrivileged(new PrivilegedAction<Enumeration>() { public Enumeration run() { List<URL> urlList = new ArrayList<URL>(); try { List<FileObject> foList = findResourceFileObjects(name); for (FileObject fo : foList) { urlList.add(fo.getURL()); if (log.isLoggable(Level.FINE)) { log.fine("..found file object with URL:" + fo.getURL()); log.fine("..trying to open it"); } /* For unknown reasons, actually getting the resources will fail iff the target folder is not under the current working directory, unless we try to open it while we're here. */ InputStream in = null; //BufferedReader r = null; try { in = fo.getURL().openStream(); //r = new BufferedReader(new InputStreamReader(in, "utf-8")); } catch (Exception x) { log.log(Level.FINE, "..Got an exception:" + x); } finally { try { // if (r != null) { // r.close(); // } if (in != null) { in.close(); } } catch (IOException y) { log.log(Level.FINE, "..Additionally, got an exception on close:" + y); } } } } catch (FileSystemException ex) { Logger.getLogger(VirtualFileSystemClassLoader.class.getName()).log(Level.SEVERE, null, ex); } return Collections.enumeration(urlList); } }); return result; }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
private void addCompressedFiles(FileGroup fg, FileObject[] files) throws FileSystemException { for (FileObject f : files) { if (!f.getType().hasChildren()) { String ext = getExtension(f); if (ext == null) { LOGGER.trace("Ignoring file without extension: " + f.getURL()); } else { MovieFileType type = MovieFileType.getTypeByExtension(ext); if (type == MovieFileType.COMPRESSED || type == MovieFileType.NFO || type == MovieFileType.SUBTITLE) { fg.getFiles().add(createFileMeta(f, type)); }/*from www.j a va 2 s . c om*/ } } } }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
/** * //from w w w. j a va 2s . c om * @param folder * @param monitor * @return true, if it contained movie file * @throws InterruptedException * @throws FileSystemException */ private boolean browse(FileObject folder, AsyncMonitor monitor) throws InterruptedException, FileSystemException { URL url = folder.getURL(); LOGGER.trace("entering " + url); FileObject[] files = folder.getChildren(); if (monitor != null) { if (monitor.isCanceled()) { throw new InterruptedException("at " + url); } monitor.step("scanning " + url); } Set<String> plainFileNames = new HashSet<String>(); int subDirectories = 0; int compressedFiles = 0; Set<String> directoryNames = new HashSet<String>(); for (FileObject f : files) { if (isDirectory(f)) { subDirectories++; directoryNames.add(f.getName().getBaseName().toLowerCase()); } else { String ext = getExtension(f); if (ext == null) { LOGGER.trace("Ignoring file without extension: " + f.getURL()); } else { if (MovieFileType.getTypeByExtension(ext) == MovieFileType.COMPRESSED) { compressedFiles++; } if (ext != null && MovieFileFilter.VIDEO_EXTENSIONS.contains(ext)) { plainFileNames.add(getNameWithoutExt(f)); } } } } // check for multiple compressed files, the case of: // Title_of_the_film/abc.rar // Title_of_the_film/abc.r01 // Title_of_the_film/abc.r02 if (compressedFiles > 0) { FileGroup fg = initStorableMovie(folder); fg.getLocations().add(new FileLocation(currentLabel, folder.getURL())); addCompressedFiles(fg, files); add(fg); return true; } if (subDirectories >= 2 && subDirectories <= 5) { // the case of : // Title_of_the_film/cd1/... // Title_of_the_film/cd2/... // with an optional sample/subs directory // Title_of_the_film/sample/ // Title_of_the_film/subs/ // Title_of_the_film/subtitles/ // or // Title_of_the_film/bla1.avi // Title_of_the_film/bla2.avi // Title_of_the_film/sample/ // Title_of_the_film/subs/ if (isMovieFolder(directoryNames)) { FileGroup fg = initStorableMovie(folder); fg.getLocations().add(new FileLocation(currentLabel, folder.getURL())); for (String cdFolder : getCdFolders(directoryNames)) { addCompressedFiles(fg, files, cdFolder); } for (FileObject file : folder.getChildren()) { if (!isDirectory(file)) { String ext = getExtension(file); if (MovieFileFilter.VIDEO_EXT_EXTENSIONS.contains(ext)) { fg.getFiles().add(createFileMeta(file, MovieFileType.getTypeByExtension(ext))); } } } add(fg); return true; } } boolean subFolderContainMovie = false; for (FileObject f : files) { final String baseName = f.getName().getBaseName(); if (isDirectory(f) && !baseName.equalsIgnoreCase("sample") && !baseName.startsWith(".")) { subFolderContainMovie |= browse(f, monitor); } } // We want to handle the following cases: // 1, // Title_of_the_film/abc.avi // Title_of_the_film/abc.srt // --> no subdirectory, one film -> the title should be name of the // directory // // 2, // Title_of_the_film/abc-cd1.avi // Title_of_the_film/abc-cd1.srt // Title_of_the_film/abc-cd2.srt // Title_of_the_film/abc-cd2.srt // if (subDirectories > 0 && subFolderContainMovie) { return genericMovieFindProcess(files) || subFolderContainMovie; } else { int foundFiles = plainFileNames.size(); switch (foundFiles) { case 0: return subFolderContainMovie; case 1: { FileGroup fg = initStorableMovie(folder); fg.getLocations().add(new FileLocation(currentLabel, folder.getURL())); addFiles(fg, files, plainFileNames.iterator().next()); add(fg); return true; } case 2: { Iterator<String> it = plainFileNames.iterator(); String name1 = it.next(); String name2 = it.next(); if (LevenshteinDistance.distance(name1, name2) < 3) { // the difference is -cd1 / -cd2 FileGroup fg = initStorableMovie(folder); fg.getLocations().add(new FileLocation(currentLabel, folder.getURL())); addFiles(fg, files, name1); add(fg); return true; } // the difference is significant, we use the generic // solution } default: { return genericMovieFindProcess(files); } } } }