List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.pentaho.reporting.engine.classic.core.filter.URLFilter.java
/** * Tries to form a url from the object returned from the datasource. This function will return null if the datasource * is null or returned null when getValue was called. * <p/>//from ww w. j a va2s . com * Null is also returned if the datasources value is not an url, a String or a file. If the creation of the url failed * with an MalformedURLException or the datasource returned a file which is not readable, also null is returned. * * @param runtime * the expression runtime that is used to evaluate formulas and expressions when computing the value of this * filter. * @param element * @return created url or null if something went wrong on url creation. */ public Object getValue(final ExpressionRuntime runtime, final ReportElement element) { if (getDataSource() == null) { return null; } final Object o = getDataSource().getValue(runtime, element); if (o == null) { return null; } if (o instanceof URL) { return o; } try { if (o instanceof File) { final File f = (File) o; if (f.canRead()) { return f.toURL(); } } else if (o instanceof String) { if (getBaseURL() == null) { return new URL((String) o); } else { return new URL(getBaseURL(), (String) o); } } } catch (MalformedURLException mfe) { URLFilter.logger.info("URLFilter.getValue(): MalformedURLException!"); } return null; }
From source file:org.apache.axis2.jaxws.util.CatalogWSDLLocator.java
/** * Returns an InputStream pointed at an imported wsdl pathname relative to * the parent document.//w w w . j a va2 s. c o m * * @param importPath * identifies the WSDL file within the context * @return a stream of the WSDL file */ protected InputStream getInputStream(String importPath) throws IOException { URL importURL = null; InputStream is = null; try { importURL = new URL(importPath); is = importURL.openStream(); } catch (Throwable t) { // No FFDC required } if (is == null) { try { is = classLoader.getResourceAsStream(importPath); } catch (Throwable t) { // No FFDC required } } if (is == null) { try { File file = new File(importPath); is = file.toURL().openStream(); } catch (Throwable t) { // No FFDC required } } if (is == null) { try { URI uri = new URI(importPath); is = uri.toURL().openStream(); } catch (Throwable t) { // No FFDC required } } return is; }
From source file:org.onecmdb.ui.gwt.desktop.server.service.content.ContentParserFactory.java
public URL getURL(ContentData data) { try {//from w w w .ja v a 2 s .c om File content = new File(getRootPath(), data.getPath()); return (content.toURL()); } catch (MalformedURLException e) { throw new IllegalArgumentException("URL not corret<" + data.getPath() + ">", e); } }
From source file:org.apache.cocoon.core.xml.impl.DefaultEntityResolver.java
/** * Correct resource uris./*from ww w.ja va 2s . c o m*/ */ protected String correctUri(String uri) throws IOException { // if it is a file we have to recreate the url, // otherwise we get problems under windows with some file // references starting with "/DRIVELETTER" and some // just with "DRIVELETTER" if (uri.startsWith("file:")) { final File f = new File(uri.substring(5)); return f.toURL().toExternalForm(); } return uri; }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.extwriter.ReportConverter.java
/** * Returns the URL of a report./*from ww w . j a v a 2 s .c o m*/ * * @param name * the report name. * @return The URL (or <code>null</code>). * @throws java.io.IOException * if there is an I/O problem. */ public URL findReport(final String name) throws IOException { final URL in = ObjectUtilities.getResource(name, ReportConverter.class); if (in != null) { return in; } final File f = new File(name); if (f.canRead()) { return f.toURL(); } return null; }
From source file:interactivespaces.workbench.project.test.JavaTestRunner.java
/** * Detect and run any JUnit test classes. * * @param testCompilationFolder//from w w w . j a va 2 s . co m * folder where the test classes were compiled * @param jarDestinationFile * the jar that was built * @param projectType * the project type * @param extension * the Java project extension for the project (can be {@code null}) * @param context * the build context * * @return {@code true} if all tests passed */ private boolean runJavaUnitTests(File testCompilationFolder, File jarDestinationFile, JavaProjectType projectType, JavaProjectExtension extension, ProjectTaskContext context) { List<File> classpath = Lists.newArrayList(); classpath.add(jarDestinationFile); classpath.add(testCompilationFolder); projectType.getProjectClasspath(true, context, classpath, extension, context.getWorkbenchTaskContext()); List<URL> urls = Lists.newArrayList(); for (File classpathElement : classpath) { try { urls.add(classpathElement.toURL()); } catch (MalformedURLException e) { context.getWorkbenchTaskContext().getWorkbench().getLog().error(String.format( "Error while adding %s to the unit test classpath", classpathElement.getAbsolutePath()), e); } } URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), context.getWorkbenchTaskContext().getWorkbench().getBaseClassLoader()); return runTestsInIsolation(testCompilationFolder, classLoader, context); }
From source file:interactivespaces.workbench.project.test.IsolatedClassloaderJavaTestRunner.java
/** * Detect and run any JUnit test classes. * * @param testCompilationFolder// ww w .j a v a 2s .co m * folder where the test classes were compiled * @param jarDestinationFile * the jar that was built * @param projectType * the project type * @param extension * the Java project extension for the project (can be {@code null}) * @param context * the build context * * @throws InteractiveSpacesException * the tests failed */ private void runJavaUnitTests(File testCompilationFolder, File jarDestinationFile, JavaProjectType projectType, JavaProjectExtension extension, ProjectTaskContext context) throws InteractiveSpacesException { List<File> classpath = Lists.newArrayList(); classpath.add(jarDestinationFile); classpath.add(testCompilationFolder); projectType.getProjectClasspath(true, context, classpath, extension, context.getWorkbenchTaskContext()); List<URL> urls = Lists.newArrayList(); for (File classpathElement : classpath) { try { urls.add(classpathElement.toURL()); } catch (MalformedURLException e) { context.getWorkbenchTaskContext().getWorkbench().getLog().error(String.format( "Error while adding %s to the unit test classpath", classpathElement.getAbsolutePath()), e); } } URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), context.getWorkbenchTaskContext().getWorkbench().getBaseClassLoader()); runTestsInIsolation(testCompilationFolder, classLoader, context); }
From source file:org.sonar.batch.internal.PluginsManager.java
public void start() throws Exception { LOG.info("Starting Sonar Plugins Manager (workDir: {})", workDir); collection = new ClassLoadersCollection(parentClassLoader); for (Map.Entry<File, Manifest> entry : manifests.entrySet()) { File file = entry.getKey(); Manifest manifest = entry.getValue(); Attributes attributes = manifest.getMainAttributes(); String childFirst = attributes.getValue("Plugin-ChildFirstClassLoader"); String pluginKey = attributes.getValue("Plugin-Key"); String pluginClass = attributes.getValue("Plugin-Class"); String pluginDependencies = StringUtils.defaultString(attributes.getValue("Plugin-Dependencies")); File pluginDir = file.getParentFile().getParentFile(); Collection<URL> urls = new ArrayList<URL>(); urls.add(pluginDir.toURL()); String[] deps = StringUtils.split(pluginDependencies); for (String dep : deps) { File depFile = new File(pluginDir, dep); urls.add(depFile.toURL());//from w w w .ja v a 2 s. com } LOG.debug("ClassPath for plugin {} : {}", pluginKey, urls); collection.createClassLoader(pluginKey, urls, "true".equals(childFirst)); plugins.put(pluginKey, pluginClass); } collection.done(); }
From source file:org.apache.archiva.converter.RepositoryConverterTest.java
@Before @Override/*from w ww . j a v a 2 s . c o m*/ public void setUp() throws Exception { super.setUp(); ArtifactRepositoryFactory factory = plexusSisuBridge.lookup(ArtifactRepositoryFactory.class); //(ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); ArtifactRepositoryLayout layout = plexusSisuBridge.lookup(ArtifactRepositoryLayout.class, "legacy"); //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); File sourceBase = new File("src/test/source-repository"); sourceRepository = factory.createArtifactRepository("source", sourceBase.toURL().toString(), layout, null, null); layout = plexusSisuBridge.lookup(ArtifactRepositoryLayout.class, "default"); //(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); File targetBase = new File("target/test-target-repository"); copyDirectoryStructure(new File("src/test/target-repository"), targetBase); targetRepository = new ManagedRepositoryConfiguration(); targetRepository.setId("target"); targetRepository.setName("Target Repo"); targetRepository.setLocation(targetBase.getAbsolutePath()); targetRepository.setLayout("default"); //repositoryConverter = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE, "default" ); }
From source file:com.retroduction.carma.resolvers.util.TestCaseInstantiationVerifier.java
Set<URL> filterInvalidURLs(Set<File> classPathEntries) { Set<URL> result = new HashSet<URL>(); if (classPathEntries != null) { for (File file : classPathEntries) { if (file != null) { try { result.add(file.toURL()); } catch (MalformedURLException e) { this.log.warn("Invalid class path entry: " + file.toString()); }// ww w . ja v a2 s. com } } } return result; }