List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.apache.axis2.deployment.util.Utils.java
/** * Get a ClassLoader which contains a classpath of a) the passed directory and b) any jar files * inside the "lib/" or "Lib/" subdirectory of the passed directory. * * @param parent parent ClassLoader which will be the parent of the result of this method * @param file a File which must be a directory for this to be useful * @return a new ClassLoader pointing to both the passed dir and jar files under lib/ * @throws DeploymentException if problems occur *///from w ww . ja v a2 s. c om public static ClassLoader getClassLoader(final ClassLoader parent, File file, final boolean isChildFirstClassLoading) throws DeploymentException { URLClassLoader classLoader; if (file == null) return null; // Shouldn't this just return the parent? try { ArrayList urls = new ArrayList(); urls.add(file.toURL()); // lower case directory name File libfiles = new File(file, "lib"); if (!addFiles(urls, libfiles)) { // upper case directory name libfiles = new File(file, "Lib"); addFiles(urls, libfiles); } final URL urllist[] = new URL[urls.size()]; for (int i = 0; i < urls.size(); i++) { urllist[i] = (URL) urls.get(i); } classLoader = (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { if (useJarFileClassLoader()) { return new JarFileClassLoader(urllist, parent); } else { return new DeploymentClassLoader(urllist, null, parent, isChildFirstClassLoading); } } }); return classLoader; } catch (MalformedURLException e) { throw new DeploymentException(e); } }
From source file:org.eclipse.equinox.servletbridge.FrameworkLauncher.java
/** buildInitialPropertyMap create the initial set of properties from the contents of launch.ini * and for a few other properties necessary to launch defaults are supplied if not provided. * The value '@null' will set the map value to null. * @return a map containing the initial properties *//*w w w.ja v a 2s . c o m*/ protected Map buildInitialPropertyMap() { Map initialPropertyMap = new HashMap(); Properties launchProperties = loadProperties(resourceBase + LAUNCH_INI); for (Iterator it = launchProperties.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (key.endsWith("*")) { //$NON-NLS-1$ if (value.equals(NULL_IDENTIFIER)) { clearPrefixedSystemProperties(key.substring(0, key.length() - 1), initialPropertyMap); } } else if (value.equals(NULL_IDENTIFIER)) initialPropertyMap.put(key, null); else initialPropertyMap.put(entry.getKey(), entry.getValue()); } try { // install.area if not specified if (initialPropertyMap.get(OSGI_INSTALL_AREA) == null) initialPropertyMap.put(OSGI_INSTALL_AREA, platformDirectory.toURL().toExternalForm()); // configuration.area if not specified if (initialPropertyMap.get(OSGI_CONFIGURATION_AREA) == null) { File configurationDirectory = new File(platformDirectory, "configuration"); //$NON-NLS-1$ if (!configurationDirectory.exists()) { configurationDirectory.mkdirs(); } initialPropertyMap.put(OSGI_CONFIGURATION_AREA, configurationDirectory.toURL().toExternalForm()); } // instance.area if not specified if (initialPropertyMap.get(OSGI_INSTANCE_AREA) == null) { File workspaceDirectory = new File(platformDirectory, "workspace"); //$NON-NLS-1$ if (!workspaceDirectory.exists()) { workspaceDirectory.mkdirs(); } initialPropertyMap.put(OSGI_INSTANCE_AREA, workspaceDirectory.toURL().toExternalForm()); } // osgi.framework if not specified if (initialPropertyMap.get(OSGI_FRAMEWORK) == null) { // search for osgi.framework in osgi.install.area String installArea = (String) initialPropertyMap.get(OSGI_INSTALL_AREA); // only support file type URLs for install area if (installArea.startsWith(FILE_SCHEME)) installArea = installArea.substring(FILE_SCHEME.length()); String path = new File(installArea, "plugins").toString(); //$NON-NLS-1$ path = searchFor(FRAMEWORK_BUNDLE_NAME, path); if (path == null) throw new RuntimeException("Could not find framework"); //$NON-NLS-1$ initialPropertyMap.put(OSGI_FRAMEWORK, new File(path).toURL().toExternalForm()); } } catch (MalformedURLException e) { throw new RuntimeException("Error establishing location"); //$NON-NLS-1$ } return initialPropertyMap; }
From source file:org.talend.librariesmanager.ui.dialogs.InstallModuleDialog.java
@Override protected void okPressed() { String newMVNURI = null;//from w w w.ja v a 2 s .c o m if (useCustomBtn.getSelection()) { newMVNURI = MavenUrlHelper.addTypeForMavenUri(customUriText.getText().trim(), moduleName); if (cellEditor != null) { cellEditor.setConsumerExpression(newMVNURI); cellEditor.fireApplyEditorValue(); } } else { newMVNURI = defaultUriTxt.getText().trim(); if (cellEditor != null) { cellEditor.setConsumerExpression(defaultUriTxt.getText()); cellEditor.fireApplyEditorValue(); } } if (!"".equals(jarPathTxt.getText().trim())) { final String mvnURI = newMVNURI; File file = new File(jarPathTxt.getText().trim()); if (file.exists()) { final IRunnableWithProgress acceptOursProgress = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Install module " + file.getName(), 100); monitor.worked(30); LibManagerUiPlugin.getDefault().getLibrariesService().deployLibrary(file.toURL(), mvnURI); monitor.done(); } catch (IOException e) { ExceptionHandler.process(e); } } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); try { dialog.run(true, true, acceptOursProgress); } catch (Throwable e) { if (!(e instanceof TimeoutException)) { ExceptionHandler.process(e); } } } } super.okPressed(); LibManagerUiPlugin.getDefault().getLibrariesService().checkLibraries(); }
From source file:org.pentaho.platform.repository.solution.filebased.FileBasedSolutionRepository.java
public ClassLoader getClassLoader(final String path) { File localeDir = new File(PentahoSystem.getApplicationContext().getSolutionPath(path)); try {// w w w .j a va 2 s . c om URLClassLoader loader = new URLClassLoader(new URL[] { localeDir.toURL() }, null); return loader; } catch (Exception e) { error(Messages.getErrorString("SolutionRepository.ERROR_0024_CREATING_CLASSLOADER")); //$NON-NLS-1$ } return null; }
From source file:org.wso2.carbon.core.multitenancy.TenantAxisConfigurator.java
/** * This over-ridden method is same as super method except * this does a axisConfig.getRepository() == null before setting the repo. * This is done because with Stratos, we can not set the repo twice. * * @param repoDir//from w w w . jav a 2s. co m * @throws DeploymentException */ @Override public void loadRepository(String repoDir) throws DeploymentException { File axisRepo = new File(repoDir); if (!axisRepo.exists()) { throw new DeploymentException(Messages.getMessage("cannotfindrepo", repoDir)); } setDeploymentFeatures(); prepareRepository(repoDir); // setting the CLs setClassLoaders(repoDir); repoListener = new RepositoryListener(this, false); org.apache.axis2.util.Utils.calculateDefaultModuleVersion(axisConfig.getModules(), axisConfig); try { try { if (axisConfig.getRepository() == null) { //we set axisConfig.setRepository(axisRepo.toURL()); } } catch (MalformedURLException e) { log.info(e.getMessage()); } axisConfig.validateSystemPredefinedPhases(); } catch (AxisFault axisFault) { throw new DeploymentException(axisFault); } }
From source file:org.kalypso.test.gml.serializer.GMLSerializerTest.java
/** * Class under test for GMLWorkspace createGMLWorkspace(URL) *///www . j av a 2s . c o m public void multiLoadAndSaveGMLWorkspace(final URL resourceURL) throws Exception { final File testFileOrg = File.createTempFile("testOriginal", ".gml"); final File testFileParsed = File.createTempFile("testParsed", ".gml"); final File testFileParsed2 = File.createTempFile("testParsed2", ".gml"); OutputStreamWriter writerOrg = null; OutputStreamWriter writerParsed = null; OutputStreamWriter writerParsed2 = null; try { // Remark: why write it into a separate file? Load it directly for comparison // via URL.open(); writerOrg = new OutputStreamWriter(new FileOutputStream(testFileOrg), "UTF-8"); final Document documentOrg = XMLTools.parse(resourceURL); XMLHelper.writeDOM(documentOrg, "UTF-8", writerOrg); writerOrg.close(); final GMLWorkspace workspace = GmlSerializer.createGMLWorkspace(resourceURL, null); writerParsed = new OutputStreamWriter(new FileOutputStream(testFileParsed), "UTF-8"); GmlSerializer.serializeWorkspace(writerParsed, workspace, "UTF-8"); writerParsed.close(); final GMLWorkspace workspace2 = GmlSerializer.createGMLWorkspace(testFileParsed.toURL(), null); writerParsed2 = new OutputStreamWriter(new FileOutputStream(testFileParsed2), "UTF-8"); GmlSerializer.serializeWorkspace(writerParsed2, workspace2, "UTF-8"); writerParsed.close(); assertTrue(StreamUtilities.isEqual(new FileInputStream(testFileParsed2), new FileInputStream(testFileParsed))); } finally { IOUtils.closeQuietly(writerOrg); IOUtils.closeQuietly(writerParsed); IOUtils.closeQuietly(writerParsed2); testFileOrg.delete(); testFileParsed.delete(); testFileParsed2.delete(); } }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
/** * Setting the internal field {@link #document} directly (bypassing * {@link #setDocument(URL)}) is used to deplay the document loading until * {@link #ready()}./*w w w .j av a 2 s . com*/ */ @Override protected void initialize(final String[] as) { if ("Linux".equals(System.getProperty("os.name"))) getContext().getResourceManager().setPlatform("linux"); final Class<?> mc = this.getClass(); { final ResourceMap r = Application.getInstance().getContext().getResourceMap(); initialScene = mc.getResource("/" + r.getResourcesDir() + r.getString("Application.defaultDocument")); templateScene = mc.getResource("/" + r.getResourcesDir() + r.getString("Application.templateDocument")); } // schedule the document to load in #ready() document = initialScene; for (final String p : as) { // ignore javaws parameters if ("-open".equals(p) || "-print".equals(p)) continue; try { document = new URL(p); break; } catch (final MalformedURLException e) { final File f = new File(p); if (f.canRead()) try { document = f.toURL(); break; } catch (final MalformedURLException e2) { log.warn("Cannot load '" + p + "'.", e); } else log.warn("Cannot load '" + p + "'.", e); } } }
From source file:org.apache.axis2.deployment.util.Utils.java
private static boolean addFiles(ArrayList urls, final File libfiles) throws MalformedURLException { Boolean exists = (Boolean) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedAction() { public Object run() { return libfiles.exists(); }/*ww w .j a va2 s. co m*/ }); if (exists) { urls.add(libfiles.toURL()); File jarfiles[] = (File[]) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedAction() { public Object run() { return libfiles.listFiles(); } }); int i = 0; while (i < jarfiles.length) { File jarfile = jarfiles[i]; if (jarfile.getName().endsWith(".jar")) { urls.add(jarfile.toURL()); } i++; } } return exists; }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
/** File Menu Action */ @Action/* www . ja v a2 s. c o m*/ public void fileSaveAs() { final File f = saveHelper(null, getFile(), "saveAsFileChooser", false); log.info(f); if (f != null) { try { setDocument(f.toURL(), false); } catch (final IOException e) { throw new RuntimeException("Unhandled", e); } setModified(false); } }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
/** File Menu Action */ @Action(enabledProperty = "modified") public void fileSave() { if (!isModified()) return;//from w ww. j a v a 2 s . c o m final File f = saveHelper(getFile(), getFile(), "saveFileChooser", true); log.info(f); if (f != null) { try { setDocument(f.toURL(), false); } catch (final IOException e) { throw new RuntimeException("Unhandled", e); } setModified(false); } }