List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.ops4j.gaderian.util.FileResource.java
public URL getResourceURL() { File file = getFile(); try {// ww w .j a va2s .c o m if (file == null || !file.exists()) return null; return file.toURL(); } catch (MalformedURLException ex) { LOG.error(UtilMessages.badFileURL(getPath(), ex), ex); return null; } }
From source file:org.retroduction.carma.reportgenerator.beanbuilder.ProjectSourceCodeFileListBeanBuilder.java
@SuppressWarnings("unchecked") public ProjectSourceCodeFileListBean getSourceCodeFileList(MutationRun report, List<File> sourceFolders) { ProjectSourceCodeFileListBean project = new ProjectSourceCodeFileListBean(); for (File folderName : sourceFolders) { try {//from w ww . j av a2s. co m URL sourceFolderUrl = folderName.toURL(); Iterator fileIterator = FileUtils.iterateFiles(folderName, new String[] { "java" }, true); while (fileIterator.hasNext()) { try { File sourceFileName = (File) fileIterator.next(); URL sourceFileUrl = sourceFileName.toURL(); SourceFile sourceFile = new SourceFile(); sourceFile.setFileName(sourceFileName.getPath()); sourceFile.setPackageName(this.extractPackageName(sourceFolderUrl, sourceFileUrl)); sourceFile.setClassName(FilenameUtils.getBaseName(sourceFileUrl.toString())); sourceFile.setSourceText(FileUtils.readLines(new File(sourceFileUrl.getPath()))); project.addSourceFile(sourceFile); } catch (IOException e) { logger.warn("Source folder " + folderName + " is invalid. Skipping ..."); continue; } } } catch (IOException e) { logger.warn("Source folder " + folderName + " is invalid. Skipping ..."); continue; } } return project; }
From source file:org.apache.cocoon.environment.commandline.CommandLineContext.java
public URL getResource(String path) throws MalformedURLException { if (getLogger().isDebugEnabled()) { getLogger().debug("CommandlineContext: getResource=" + path); }//from ww w . j a v a 2s.c om // rely on File to build correct File and URL File f = new File(contextDir, path); if (!f.exists()) return null; return f.toURL(); }
From source file:de.nava.informa.utils.TestChannelRegistry.java
public void XXXtestCreate() throws Exception { ChannelRegistry reg = new ChannelRegistry(new ChannelBuilder()); // first channel File inpFile = new File(getDataDir(), "xmlhack-0.91.xml"); ChannelIF chA = reg.addChannel(inpFile.toURL(), 2, true); Date dateA = chA.getLastUpdated(); assertNull("channel shouldn't be parsed now", dateA); // second channel inpFile = new File(getDataDir(), "pro-linux.rdf"); ChannelIF chB = reg.addChannel(inpFile.toURL(), 2, true); // third channel inpFile = new File(getDataDir(), "snipsnap-org.rss"); ChannelIF chC = reg.addChannel(inpFile.toURL(), 2, true); // some basic assertions assertEquals("channel exists", 3, reg.getChannels().size()); assertTrue("channel A", reg.getChannels().contains(chA)); assertTrue("channel B", reg.getChannels().contains(chB)); assertTrue("channel C", reg.getChannels().contains(chC)); logger.info("starting to sleep ..."); try {/*ww w .j a va 2 s.co m*/ Thread.sleep(5000); } catch (InterruptedException e) { logger.warn("Interrupted waiting thread"); } logger.info("... stopped sleeping"); // check that they are still active assertTrue("channel A active", reg.isActiveChannel(chA)); assertTrue("channel B active", reg.isActiveChannel(chB)); assertTrue("channel C active", reg.isActiveChannel(chC)); // verify update assertNotNull("channel should have been updated in the meantime", chA.getLastUpdated()); }
From source file:com.cyclopsgroup.waterview.jelly.taglib.JellyScriptTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//*from w w w . ja v a2 s . co m*/ protected void processTag(XMLOutput output) throws Exception { requireAttribute("type"); requireAttribute("path"); Script script = null; if (StringUtils.equals(getType(), "system")) { JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); script = je.getScript(getPath()); } else if (StringUtils.equals(getType(), "classpath")) { URL resource = getClass().getClassLoader().getResource(getPath()); if (resource != null) { script = context.compileScript(resource); } } else if (StringUtils.equals(getType(), "file")) { File file = new File(getPath()); if (file.exists()) { script = context.compileScript(file.toURL()); } } else { throw new JellyTagException("Type must be system|classpath|file, default value is system"); } if (script == null) { throw new FileNotFoundException("Resource " + getPath() + " is not found in " + getType()); } JellyContext jc = new JellyContext(getContext()); if (script != null) { script.run(jc, output); output.flush(); } }
From source file:org.pentaho.ui.xul.swing.tags.SwingImage.java
public void setSrc(String src) { // First try the relative path URL url = SwingImage.class.getClassLoader().getResource(this.container.getXulLoader().getRootDir() + src); // Then try to see if we can get the fully qualified file if (url == null) { try {//from w w w. j a v a 2s. c o m File f = new File(src); if (f.exists()) { url = f.toURL(); } } catch (MalformedURLException e) { // do nothing and let the null url get caught below. } } if (url == null) { logger.error("Could not find resource: " + src); return; } ico = new ImageIcon(url); if (ico == null) { logger.error("Image could not be found: " + ico); } this.src = src; layout(); }
From source file:org.nuxeo.runtime.jboss.adapter.RepositoryAdapter.java
public void undeployRepository(String name) throws Exception { log.info("Undeploying DS for repository: " + name); RuntimeAdapterMBean rad = (RuntimeAdapterMBean) ServiceLocator.getService(RuntimeAdapterMBean.class, RuntimeAdapter.NAME);/*w ww .ja v a 2 s.c om*/ File file = new File(rad.getTempDeployDir(), name + "-ds.xml"); if (file.isFile()) { DeploymentHelper.undeploy(file.toURL()); } }
From source file:org.apache.commons.jelly.demos.HomepageBuilder.java
/*** * @return the URL for the relative file name or absolute URL *//* ww w .ja v a 2 s . co m*/ protected URL resolveURL(String name) throws MalformedURLException { File file = new File(name); if (file.exists()) { return file.toURL(); } return new URL(name); }
From source file:org.apache.axis2.jaxws.util.ModuleWSDLLocator.java
/** * Return the wsdlLocation in URL form. WsdlLocation could be URL, relative * module path, full absolute path./*w w w.j a v a 2s. c o m*/ * * @param wsdlLocation * the location of a WSDL document in the form of a URL string, a * relative pathname (relative to the root of a module, or a * full-qualified absolute pathname * @return the location of the WSDL document in the form of a URL */ public URL getWsdlUrl(String wsdlLocation) { URL streamURL = null; InputStream is = null; URI pathURI = null; try { streamURL = new URL(wsdlLocation); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } if (is == null) { try { pathURI = new URI(wsdlLocation); streamURL = pathURI.toURL(); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } } if (is == null) { try { File file = new File(wsdlLocation); streamURL = file.toURL(); is = streamURL.openStream(); is.close(); } catch (Throwable t) { // No FFDC required } } if (log.isDebugEnabled() && streamURL == null) { log.debug("Absolute wsdlLocation could not be determined: " + wsdlLocation); } return streamURL; }
From source file:com.smilonet.common.zk.GeneralLabelLocator.java
public URL locate(Locale locale) throws Exception { // String menu_res_filename = // (locale.getLanguage().equals(Locale.ITALIAN.getLanguage())) ? // MENU_FILE_NAME + MENU_FILE_SUFFIX // : MENU_FILE_NAME + "_" + locale.getLanguage() + MENU_FILE_SUFFIX; String menu_res_filename = ""; if (StringUtils.isEmpty(context)) { // Locale.setDefault(new Locale("en", "EN")); context = "en_EN"; }// w w w . j av a 2 s .c o m if (context.equals("en_EN")) { // default property-file without locale Sessions.getCurrent().setAttribute("px_preferred_locale", new Locale("en", "EN")); menu_res_filename = MENU_FILE_NAME + MENU_FILE_SUFFIX; } else if (context.equals("de_DE")) { Sessions.getCurrent().setAttribute("px_preferred_locale", new Locale("de", "DE")); menu_res_filename = MENU_FILE_NAME + "_" + "de_DE" + MENU_FILE_SUFFIX; } // String menu_res_filename = MENU_FILE_NAME + "_" + context + // MENU_FILE_SUFFIX; // real path String menu_res_path = Sessions.getCurrent().getWebApp().getRealPath("/WEB-INF/" + menu_res_filename); // check if the file exists File fmr = new File(menu_res_path); if (!fmr.exists()) throw new Exception("..........."); // return url return fmr.toURL(); }