List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.jboss.web.tomcat.service.WebCtxLoader.java
/** * Build the classpath from the war url WEB-INF/{classes,lib}. * // w w w . j a v a 2s. co m * @param warURL * @throws MalformedURLException */ public void setWarURL(URL warURL) throws MalformedURLException { this.warURL = warURL; String path = warURL.getFile(); File classesDir = new File(path, "WEB-INF/classes"); if (classesDir.exists()) { ctxLoader.addURLInternal(classesDir.toURL()); } File libDir = new File(path, "WEB-INF/lib"); if (libDir.exists()) { File[] jars = libDir.listFiles(); int length = jars != null ? jars.length : 0; for (int j = 0; j < length; j++) { File jar = jars[j]; if (jar.getAbsolutePath().endsWith(".jar")) { ctxLoader.addURLInternal(jar.toURL()); } } } }
From source file:com.concursive.connect.web.modules.wiki.jobs.WikiExporterJob.java
protected WikiExportBean getExisting(File checkFile, Vector collectionToCheck) throws Exception { Iterator i = collectionToCheck.iterator(); while (i.hasNext()) { WikiExportBean bean = (WikiExportBean) i.next(); if (bean.getExportedFile().toURL().equals(checkFile.toURL())) { return bean; }// w ww . ja va2 s . c o m } return null; }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.extwriter.ReportConverter.java
/** * Parses a report from the old version of the XML report format, and writes a file in the new XML report format. * * @param inName/*from www .ja va 2s. c o m*/ * the input report file. * @param outFile * the output report file. * @param encoding * the encoding of the generated file. * @throws IOException * if there is an I/O problem. * @throws ReportWriterException * if there is a problem writing the report. */ public void convertReport(final String inName, final String outFile, final String encoding) throws IOException, ReportWriterException { final URL reportURL = findReport(inName); if (reportURL == null) { throw new IOException("The specified report definition was not found"); } final File out = new File(outFile); final OutputStream base = new FileOutputStream(out); final Writer w = new BufferedWriter(new OutputStreamWriter(base, encoding)); try { convertReport(reportURL, out.toURL(), w, encoding); } finally { w.close(); } }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315Test.java
/** * Method c14nAndCompare/*from ww w.java2s. co m*/ * * @param fileIn * @param fileRef * @param fileOut * @param c14nURI * @param validating * @param xpath * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException */ private static boolean c14nAndCompare(String fileIn, String fileRef, String fileOut, String c14nURI, boolean validating, Object xpath) throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException { DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); dfactory.setValidating(validating); DocumentBuilder documentBuilder = dfactory.newDocumentBuilder(); // throw away all warnings and errors documentBuilder.setErrorHandler(new IgnoreAllErrorHandler()); // org.xml.sax.EntityResolver resolver = new TestVectorResolver(); // documentBuilder.setEntityResolver(resolver); // Document doc = documentBuilder.parse(resolver.resolveEntity(null, fileIn)); Document doc = documentBuilder.parse(fileIn); Canonicalizer c14n = Canonicalizer.getInstance(c14nURI); byte c14nBytes[] = null; if (xpath == null) { c14nBytes = c14n.canonicalizeSubtree(doc); } else { CachedXPathAPI xpathAPI = new CachedXPathAPI(); NodeList nl = null; if (xpath instanceof String) { nl = xpathAPI.selectNodeList(doc, (String) xpath); } else { Element xpathElement = (Element) xpath; String xpathStr = ((Text) xpathElement.getFirstChild()).getData(); nl = xpathAPI.selectNodeList(doc, xpathStr, xpathElement); } c14nBytes = c14n.canonicalizeXPathNodeSet(nl); } // org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef); // byte refBytes[] = JavaUtils.getBytesFromStream(refIs.getByteStream()); byte refBytes[] = JavaUtils.getBytesFromFile(fileRef); // if everything is OK, result is true; we do a binary compare, byte by byte boolean result = java.security.MessageDigest.isEqual(refBytes, c14nBytes); if (result == false) { File f = new File(fileOut); if (!f.exists()) { File parent = new File(f.getParent()); parent.mkdirs(); f.createNewFile(); } FileOutputStream fos = new FileOutputStream(f); fos.write(c14nBytes); log.debug("Wrote errornous result to file " + f.toURL().toString()); assertEquals(new String(refBytes), new String(c14nBytes)); } return result; }
From source file:org.apache.axis.components.compiler.Javac.java
private ClassLoader getClassLoader() { // Use reflection to be able to build on all JDKs ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL toolsURL = null;/*from ww w. ja v a 2 s .c om*/ String tools = System.getProperty("java.home"); if (tools != null) { File f = new File(tools + "/../lib/tools.jar"); if (f.exists()) { try { toolsURL = f.toURL(); cl = new URLClassLoader(new URL[] { toolsURL }, cl); } catch (MalformedURLException e) { } } } return cl; }
From source file:org.nuxeo.runtime.jboss.adapter.RepositoryAdapter.java
public void deployRepository(String name) throws Exception { log.info("Deploying DS for repository: " + name); RuntimeAdapterMBean rad = (RuntimeAdapterMBean) ServiceLocator.getService(RuntimeAdapterMBean.class, RuntimeAdapter.NAME);//from w w w. j ava 2 s . c o m File file = new File(rad.getTempDeployDir(), name + "-ds.xml"); FileOutputStream out = new FileOutputStream(file); String content = getDSContent(name); out.write(content.getBytes()); out.close(); DeploymentInfo parent = JBossOSGiAdapter.getEARDeployment(); DeploymentHelper.deploy(file.toURL(), parent); }
From source file:org.wso2.appserver.integration.common.utils.SpringServiceMaker.java
public SpringBeansData getSpringBeanNames(String springContextFilePath, String springBeanFilePath, ClassLoader bundleClassLoader) throws AxisFault { SpringBeansData data = new SpringBeansData(); File urlFile = new File(springBeanFilePath); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); ClassLoader urlCl;//w w w . jav a 2 s . co m try { URL url = urlFile.toURL(); urlCl = URLClassLoader.newInstance(new URL[] { url }, bundleClassLoader); // Save the class loader so that you can restore it later Thread.currentThread().setContextClassLoader(urlCl); ApplicationContext aCtx = GenericApplicationContextUtil .getSpringApplicationContext(springContextFilePath, springBeanFilePath); String[] beanDefintions = aCtx.getBeanDefinitionNames(); data.setBeans(beanDefintions); } catch (Exception e) { String msg = "Spring cannot load spring beans"; handleException(msg, e); } finally { Thread.currentThread().setContextClassLoader(prevCl); } return data; }
From source file:uk.ac.ebi.intact.dataexchange.cvutils.OboSlimBuilder.java
public void build(File file) throws OBOParseException, IOException, DataAdapterException { if (log.isDebugEnabled()) { log.debug("Building a slim ontology based on " + terms.size() + " given term(s)..."); }/* w ww . j a va 2 s .co m*/ if (cacheDirectory != null) { String name = ontologyURL.getFile(); String cachedFilename = name.substring(name.lastIndexOf("/"), name.length()); File cachedFile = new File(cacheDirectory, cachedFilename); if (cachedFile.exists()) { System.out.println("Using already existing file cached in: " + cachedFile.getAbsolutePath()); ontologyURL = cachedFile.toURL(); } else { System.out.println("Saving ontology into" + cachedFile.getAbsolutePath()); saveUrlToCache(ontologyURL, cachedFile); ontologyURL = cachedFile.toURL(); } } System.out.println("Reading ontology from: " + ontologyURL); final OBOSession session = OboUtils.createOBOSession(ontologyURL); // Issue, that class is MI specific, no way to load ChEBI into it :( final List<OBOObject> allOboObjects = Lists.newArrayList(); final boolean recursive = true; for (String termId : terms) { OBOObject oboObject = (OBOObject) session.getObject(termId); allOboObjects.add(oboObject); if (oboObject == null) { throw new RuntimeException("Could not find term " + termId + " in the given ontology."); } if (includeParents) allOboObjects.addAll(OboUtils.findParents(oboObject, recursive)); if (includeChildren) allOboObjects.addAll(OboUtils.findChildren(oboObject, recursive)); } if (log.isDebugEnabled()) { log.debug("Found " + allOboObjects.size() + " term(s), now saving your subset..."); } ObjectFactory objFactory = new DefaultObjectFactory(); OBOSession session2export = new OBOSessionImpl(objFactory); // Transfers Session meta data such as synonym category, namespaces for (SynonymType category : session.getSynonymTypes()) { session2export.addSynonymType(category); } session2export.setDefaultNamespace(session.getDefaultNamespace()); for (Namespace namespace : session.getNamespaces()) { session2export.addNamespace(namespace); } for (TermSubset category : session.getSubsets()) { session2export.addSubset(category); } // Add all selected OBO objects for (OBOObject oboObject : allOboObjects) { session2export.addObject(oboObject); } OboUtils.saveSession(session2export, file); }
From source file:org.onecmdb.ui.gwt.desktop.server.service.change.ChangeStoreImpl.java
public ICIMDR getBase(ICIMDR localMDR) { ICIMDR base = new CIMDRCollection(localMDR.getID()); File path = new File(getRoot(), localMDR.getID()); if (!path.exists()) { return (base); }/*from w w w . ja va2 s. com*/ File file = new File(path, "base.xml"); if (!file.exists()) { return (base); } try { XmlParser provider = new XmlParser(); provider.setURL(file.toURL().toExternalForm()); CIMDRBeanProvider mdr = new CIMDRBeanProvider(); mdr.setProvider(provider); return (mdr); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return (base); /* if (localMDR instanceof CIMDRCollection) { CIMDRCollection col = (CIMDRCollection)localMDR; CIMDRCollection result = new CIMDRCollection(); for (ICIMDR mdr : col.getMDRs()) { ICIMDR b = getBase(mdr); if (b != null) { result.add(b); } } base = result; } else { // Try to open the latest for this File path = new File(getRoot(), localMDR.getID()); if (path.exists()) { try { XmlParser provider = new XmlParser(); provider.setURL(path.toURL().toExternalForm()); CIMDRBeanProvider mdr = new CIMDRBeanProvider(); mdr.setProvider(provider); base = mdr; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return(base); */ }
From source file:EditorDropTarget4.java
protected boolean dropFile(Transferable transferable) throws IOException, UnsupportedFlavorException, MalformedURLException { List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor); File transferFile = (File) fileList.get(0); final URL transferURL = transferFile.toURL(); DnDUtils.debugPrintln("File URL is " + transferURL); pane.setPage(transferURL);//from w w w . j ava 2 s . c om return true; }