Example usage for java.io File toURL

List of usage examples for java.io File toURL

Introduction

In this page you can find the example usage for java.io File toURL.

Prototype

@Deprecated
public URL toURL() throws MalformedURLException 

Source Link

Document

Converts this abstract pathname into a file: URL.

Usage

From source file:org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.java

/**
 * This method will read in all of the schema files that were generated
 * for a given application.//from  w  w  w  .  ja va 2s .co m
 */
private HashMap<String, XmlSchema> readInSchema(String localOutputDirectory, JAXWSCatalogManager catalogManager)
        throws Exception {
    try {

        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        if (catalogManager != null)
            schemaCollection.setSchemaResolver(new CatalogURIResolver(catalogManager));
        schemaCollection.setBaseUri(new File(localOutputDirectory).getAbsolutePath());

        HashMap<String, XmlSchema> docMap = new HashMap<String, XmlSchema>();

        // Doc factory to read schema files
        DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
        fac.setNamespaceAware(true);

        List<File> schemaFiles = getSchemaFiles(localOutputDirectory);
        for (File schemaFile : schemaFiles) {
            // generate dom document for current schema file
            Document parsedDoc = fac.newDocumentBuilder().parse(schemaFile.toURL().toString());
            // read the schema through XmlSchema
            XmlSchema doc = schemaCollection.read(parsedDoc.getDocumentElement(), UIDGenerator.generateUID());
            if (log.isDebugEnabled()) {
                log.debug("Read in schema file: " + schemaFile.getName());
            }
            docMap.put(schemaFile.getName(), doc);
        }
        return docMap;
    } catch (Exception e) {
        String msg = "Error occurred while attempting to read generated schema file";
        log.error(msg, e);
        throw new Exception(msg);
    }
}

From source file:tufts.vue.action.ActionUtil.java

/** Unmarshall a LWMap from the given file (XML map data) */
public static LWMap unmarshallMap(File file, MapUnmarshalHandler handler) throws IOException {
    if (file.isDirectory())
        throw new MapException("is a directory, not a map file: " + file);
    if (!file.exists())
        throw new FileNotFoundException("does not exist");
    if (file.length() == 0)
        throw new EmptyFileException();

    return unmarshallMap(file.toURL(), handler);
}

From source file:com.symbian.driver.core.report.Result.java

/**
 * try to get the trace data of the task
 * /*from   w w  w  . j a v  a2 s .  c  o  m*/
 * @return null if no trace data
 */
private String getTraceFile() {

    //check if the task has starttrace subtask
    EObject task = iTaskFinishedEvent.getEObject();
    boolean hasStartTrace = false;
    for (EObject child : task.eContents()) {
        if (child instanceof StartTrace) {
            hasStartTrace = true;
            break;
        }
    }
    if (!hasStartTrace) {
        return null;
    }
    String taskName = setName(iTaskFinishedEvent.getEObject());
    if (taskName.indexOf(".") > 0) {
        taskName = taskName.substring(taskName.indexOf(".") + 1);
    }
    String fileName = taskName + TRACE_PREFIX;

    File traceFile = new File(sOutputPath, fileName);
    LOGGER.log(Level.INFO, "trace file url:" + traceFile.getAbsolutePath());
    //until here, we can't check the exists of trace file. since they will be copied later
    try {
        return traceFile.toURL().toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:org.objectstyle.cayenne.util.ResourceLocator.java

/** 
 * Returns a resource URL using the lookup strategy configured for this
 * Resourcelocator or <code>null</code> if no readable resource can be
 * found for the given name. /*from   ww  w .j  a va  2s  . co m*/
 */
public URL findResource(String name) {
    if (!willSkipAbsolutePath()) {
        File f = new File(name);
        if (f.isAbsolute() && f.exists()) {
            logObj.debug("File found at absolute path: " + name);
            try {
                return f.toURL();
            } catch (MalformedURLException ex) {
                // ignoring
                logObj.debug("Malformed url, ignoring.", ex);
            }
        } else {
            logObj.debug("No file at absolute path: " + name);
        }
    }

    if (!willSkipHomeDirectory()) {
        File f = findFileInHomeDirectory(name);
        if (f != null) {

            try {
                return f.toURL();
            } catch (MalformedURLException ex) {
                // ignoring
                logObj.debug("Malformed url, ignoring", ex);
            }
        }
    }

    if (!willSkipCurrentDirectory()) {
        File f = findFileInCurrentDirectory(name);
        if (f != null) {

            try {
                return f.toURL();
            } catch (MalformedURLException ex) {
                // ignoring
                logObj.debug("Malformed url, ignoring", ex);
            }
        }
    }

    if (!additionalFilesystemPaths.isEmpty()) {
        logObj.debug("searching additional paths: " + this.additionalFilesystemPaths);
        Iterator pi = this.additionalFilesystemPaths.iterator();
        while (pi.hasNext()) {
            File f = new File((String) pi.next(), name);
            logObj.debug("searching for: " + f.getAbsolutePath());
            if (f.exists()) {
                try {
                    return f.toURL();
                } catch (MalformedURLException ex) {
                    // ignoring
                    logObj.debug("Malformed URL, ignoring.", ex);
                }
            }
        }
    }

    if (!willSkipClasspath()) {
        URL url = findURLInClassLoader(name, classLoader);
        if (url != null) {
            return url;
        }

        if (!this.additionalClassPaths.isEmpty()) {
            logObj.debug("searching additional classpaths: " + this.additionalClassPaths);
            Iterator cpi = this.additionalClassPaths.iterator();
            while (cpi.hasNext()) {
                String fullName = cpi.next() + "/" + name;
                logObj.debug("searching for: " + fullName);
                url = findURLInClassLoader(fullName, classLoader);
                if (url != null) {
                    return url;
                }
            }
        }
    }

    return null;
}

From source file:org.rhq.plugins.jslee.jbossas5.helper.JBossInstanceInfo.java

private void finalizeSysProps() throws Exception {
    File homeDir;
    if (this.sysProps.containsKey(JBossProperties.HOME_DIR)) {
        homeDir = new File(this.sysProps.getProperty(JBossProperties.HOME_DIR));
    } else {/*  w  w w.  j a  va2s .  c  om*/
        homeDir = getHomeDir();
        this.sysProps.setProperty(JBossProperties.HOME_DIR, homeDir.toString());
    }

    if (!this.sysProps.containsKey(JBossProperties.HOME_URL)) {
        this.sysProps.setProperty(JBossProperties.HOME_URL, homeDir.toURL().toString());
    }
    File serverBaseDir;
    if (!sysProps.containsKey(JBossProperties.SERVER_BASE_DIR)) {
        serverBaseDir = new File(homeDir, "server");
        this.sysProps.setProperty(JBossProperties.SERVER_BASE_DIR, serverBaseDir.toString());
    } else {
        serverBaseDir = new File(this.sysProps.getProperty(JBossProperties.SERVER_BASE_DIR));
    }
    if (!this.sysProps.containsKey(JBossProperties.SERVER_BASE_URL)) {
        this.sysProps.setProperty(JBossProperties.SERVER_BASE_URL, serverBaseDir.toURL().toString());
    }
    this.installInfo = new JBossInstallationInfo(homeDir);
    if (!this.sysProps.containsKey(JBossProperties.SERVER_NAME)) {
        this.sysProps.setProperty(JBossProperties.SERVER_NAME,
                this.installInfo.getProductType().DEFAULT_CONFIG_NAME);
    }
    String serverName = this.sysProps.getProperty(JBossProperties.SERVER_NAME);
    if (!this.sysProps.containsKey(JBossProperties.SERVER_HOME_DIR)) {
        this.sysProps.setProperty(JBossProperties.SERVER_HOME_DIR, serverBaseDir + File.separator + serverName);
    }

    // temp
    if (!this.sysProps.containsKey(JBossProperties.SERVER_TEMP_DIR)) {
        String serverHomeDir = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR);
        this.sysProps.setProperty(JBossProperties.SERVER_TEMP_DIR, (serverHomeDir + File.separator + "tmp"));
        if (log.isTraceEnabled()) {
            log.trace("set JBossProperties.SERVER_TEMP_DIR to "
                    + this.sysProps.getProperty(JBossProperties.SERVER_TEMP_DIR));
        }
    } else {
        if (log.isTraceEnabled()) {
            log.trace("It already has JBossProperties.SERVER_TEMP_DIR");
        }
    }

    // Let us put mobicents dir here
    String mobicentsJSleeHome = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR) + File.separator
            + "deploy" + File.separator + "mobicents-slee";
    this.sysProps.setProperty(MobicentsJSleeProperties.JSLEE_HOME_DIR, mobicentsJSleeHome);

    if (!this.sysProps.containsKey(JBossProperties.SERVER_HOME_URL)) {
        String serverHomeDir = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR);
        this.sysProps.setProperty(JBossProperties.SERVER_HOME_URL, new File(serverHomeDir).toURL().toString());
    }

    if (!this.sysProps.containsKey(JBossProperties.BIND_ADDRESS)) {
        this.sysProps.setProperty(JBossProperties.BIND_ADDRESS, this.installInfo.getDefaultBindAddress());
    }
    String bindAddress = this.sysProps.getProperty(JBossProperties.BIND_ADDRESS); // this will not be null
    String remoteAddress = getRemoteAddress(bindAddress);
    String jgroupsBindAddress = this.sysProps.getProperty(JBossProperties.JGROUPS_BIND_ADDRESS);
    String jgroupsBindAddr = this.sysProps.getProperty(JBossProperties.JGROUPS_BIND_ADDR);
    if (jgroupsBindAddress == null) {
        jgroupsBindAddress = (jgroupsBindAddr != null) ? jgroupsBindAddr : remoteAddress;
        this.sysProps.setProperty(JBossProperties.JGROUPS_BIND_ADDRESS, jgroupsBindAddress);
    }
    if (jgroupsBindAddr == null) {
        this.sysProps.setProperty(JBossProperties.JGROUPS_BIND_ADDR, jgroupsBindAddress);
    }
    if (!this.sysProps.contains(JavaSystemProperties.JAVA_RMI_SERVER_HOSTNAME)) {
        this.sysProps.setProperty(JavaSystemProperties.JAVA_RMI_SERVER_HOSTNAME, remoteAddress);
    }
}

From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java

/**
 * Method testA//from w  w w.  ja  va  2 s  . c  om
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 * @throws org.apache.xml.security.keys.keyresolver.KeyResolverException
 */
public void testA() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException,
        CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException,
        XMLSecurityException, org.apache.xml.security.keys.keyresolver.KeyResolverException {

    File fileIn = new File(
            getAbsolutePath("data/ie/baltimore/merlin-examples/ec-merlin-iaikTests-two/signature.xml"));

    // File fileIn = new File("signature.xml");
    assertTrue("file exists", fileIn.exists());

    Document doc = this.db.parse(fileIn);
    Element signatureElement = (Element) doc
            .getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE).item(0);
    XMLSignature xmlSignature = new XMLSignature(signatureElement, fileIn.toURL().toString());
    boolean verify = xmlSignature.checkSignatureValue(xmlSignature.getKeyInfo().getPublicKey());
    int length = xmlSignature.getSignedInfo().getLength();
    int numberOfPositiveReferences = 0;

    for (int i = 0; i < length; i++) {
        boolean singleResult = xmlSignature.getSignedInfo().getVerificationResult(i);

        if (singleResult) {
            numberOfPositiveReferences++;
        }
    }

    assertTrue("Verification failed; only " + numberOfPositiveReferences + "/" + length + " matched", verify);
}

From source file:org.deegree.portal.standard.context.control.AbstractContextListener.java

/**
 * returns the name of the users start context. If the user does not own an individual start context the name of the
 * default start context for all users will be returned.
 * //from  w  ww  .  java 2  s  . c o  m
 * (copied and adapted from org.deegree.portal.standard.security.control.GetSessionIDListener)
 * 
 * @param userName
 * @return String
 * @throws IOException
 */
protected String getUsersStartContext(String userName) throws IOException {
    StringBuffer dir = new StringBuffer("users/");
    StringBuffer sb = new StringBuffer(300);
    sb.append(getHomePath()).append(userDir).append(userName);
    sb.append("/context.properties");

    File file = new File(sb.toString());
    if (!file.exists()) {
        sb.delete(0, sb.length());
        sb.append(getHomePath()).append(userDir).append("context.properties");
        file = new File(sb.toString());
    } else {
        dir.append(userName).append('/');
    }

    Properties prop = new Properties();
    InputStream is = file.toURL().openStream();
    prop.load(is);
    is.close();

    return dir.append(prop.getProperty("STARTCONTEXT")).toString();
}

From source file:org.rhq.plugins.diameter.jbossas5.helper.JBossInstanceInfo.java

private void finalizeSysProps() throws Exception {
    File homeDir;
    if (this.sysProps.containsKey(JBossProperties.HOME_DIR)) {
        homeDir = new File(this.sysProps.getProperty(JBossProperties.HOME_DIR));
    } else {//  w w w  .java  2 s .co  m
        homeDir = getHomeDir();
        this.sysProps.setProperty(JBossProperties.HOME_DIR, homeDir.toString());
    }

    if (!this.sysProps.containsKey(JBossProperties.HOME_URL)) {
        this.sysProps.setProperty(JBossProperties.HOME_URL, homeDir.toURL().toString());
    }
    File serverBaseDir;
    if (!sysProps.containsKey(JBossProperties.SERVER_BASE_DIR)) {
        serverBaseDir = new File(homeDir, "server");
        this.sysProps.setProperty(JBossProperties.SERVER_BASE_DIR, serverBaseDir.toString());
    } else {
        serverBaseDir = new File(this.sysProps.getProperty(JBossProperties.SERVER_BASE_DIR));
    }
    if (!this.sysProps.containsKey(JBossProperties.SERVER_BASE_URL)) {
        this.sysProps.setProperty(JBossProperties.SERVER_BASE_URL, serverBaseDir.toURL().toString());
    }
    this.installInfo = new JBossInstallationInfo(homeDir);
    if (!this.sysProps.containsKey(JBossProperties.SERVER_NAME)) {
        this.sysProps.setProperty(JBossProperties.SERVER_NAME,
                this.installInfo.getProductType().DEFAULT_CONFIG_NAME);
    }
    String serverName = this.sysProps.getProperty(JBossProperties.SERVER_NAME);
    if (!this.sysProps.containsKey(JBossProperties.SERVER_HOME_DIR)) {
        this.sysProps.setProperty(JBossProperties.SERVER_HOME_DIR, serverBaseDir + File.separator + serverName);
    }

    // temp
    if (!this.sysProps.containsKey(JBossProperties.SERVER_TEMP_DIR)) {
        String serverHomeDir = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR);
        this.sysProps.setProperty(JBossProperties.SERVER_TEMP_DIR, (serverHomeDir + File.separator + "tmp"));
        log.info("set JBossProperties.SERVER_TEMP_DIR to "
                + this.sysProps.getProperty(JBossProperties.SERVER_TEMP_DIR));
    } else {
        log.info("It already has JBossProperties.SERVER_TEMP_DIR");
    }

    String jbossDeploy = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR) + File.separator + "deploy"
            + File.separator;
    File f = new File(jbossDeploy);
    String[] diameterList = f.list(new FilenamePrefixFilter("mobicents-diameter-mux"));
    if (diameterList.length > 1) {
        log.warn("More than one Mobicents Diameter MUX were found.");
    } else if (diameterList.length < 1) {
        log.error("Skipping discovery for Mobicents Diameter " + jbossDeploy
                + ", because Mobicents Diameter dir could not be found.");
        throw new InvalidPluginConfigurationException("");
    }

    // Store Mobicents Diameter Home dir
    String mobicentsDiameterHome = jbossDeploy + diameterList[0];
    this.sysProps.setProperty(MobicentsDiameterProperties.DIAMETER_HOME_DIR, mobicentsDiameterHome);

    String diameterVersion = diameterList[0].replaceFirst("mobicents-diameter-mux-", "").replaceAll(".sar", "");
    this.sysProps.setProperty(MobicentsDiameterProperties.DIAMETER_VERSION, diameterVersion);

    if (!this.sysProps.containsKey(JBossProperties.SERVER_HOME_URL)) {
        String serverHomeDir = this.sysProps.getProperty(JBossProperties.SERVER_HOME_DIR);
        this.sysProps.setProperty(JBossProperties.SERVER_HOME_URL, new File(serverHomeDir).toURL().toString());
    }

    if (!this.sysProps.containsKey(JBossProperties.BIND_ADDRESS)) {
        this.sysProps.setProperty(JBossProperties.BIND_ADDRESS, this.installInfo.getDefaultBindAddress());
    }
    String bindAddress = this.sysProps.getProperty(JBossProperties.BIND_ADDRESS); // this will not be null
    String remoteAddress = getRemoteAddress(bindAddress);
    String jgroupsBindAddress = this.sysProps.getProperty(JBossProperties.JGROUPS_BIND_ADDRESS);
    String jgroupsBindAddr = this.sysProps.getProperty(JBossProperties.JGROUPS_BIND_ADDR);
    if (jgroupsBindAddress == null) {
        jgroupsBindAddress = (jgroupsBindAddr != null) ? jgroupsBindAddr : remoteAddress;
        this.sysProps.setProperty(JBossProperties.JGROUPS_BIND_ADDRESS, jgroupsBindAddress);
    }
    if (jgroupsBindAddr == null) {
        this.sysProps.setProperty(JBossProperties.JGROUPS_BIND_ADDR, jgroupsBindAddress);
    }
    if (!this.sysProps.contains(JavaSystemProperties.JAVA_RMI_SERVER_HOSTNAME)) {
        this.sysProps.setProperty(JavaSystemProperties.JAVA_RMI_SERVER_HOSTNAME, remoteAddress);
    }
}

From source file:org.wso2.carbon.ui.transports.fileupload.AbstractFileUploadExecutor.java

private void copyFile(File src, File dst) throws IOException {
    String dstAbsPath = dst.getAbsolutePath();
    String dstDir = dstAbsPath.substring(0, dstAbsPath.lastIndexOf(File.separator));
    File dir = new File(dstDir);
    if (!dir.exists() && !dir.mkdirs()) {
        log.warn("Could not create " + dir.getAbsolutePath());
    }/*  w w  w  .  j a  v a2 s  . c o m*/
    DataHandler dh = new DataHandler(src.toURL());
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(dst);
        dh.writeTo(out);
        out.flush();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:edu.harvard.i2b2.eclipse.LoginView.java

/**
 * opens logger browser in another display and separate thread
 * /*from   ww  w.  j  ava  2s . com*/
 * @param shell-
 *            the control that calls this method
 * 
 * @return new thread to show browser with logger html file 
 */
public Thread showLoggerBrowser(Shell shell) {
    final Shell myShell = shell;
    File file = new File(logFileName);
    URL url = null;
    // Convert the file object to a URL with an absolute path
    try {
        url = file.toURL();
    } catch (MalformedURLException e) {
        log.debug(e.getMessage());
    }

    final URL myurl = url;
    return new Thread() {
        @Override
        public void run() {
            new HelpBrowser().run(myurl.toString(), myShell);
        }
    };
}