Example usage for java.net URL getProtocol

List of usage examples for java.net URL getProtocol

Introduction

In this page you can find the example usage for java.net URL getProtocol.

Prototype

public String getProtocol() 

Source Link

Document

Gets the protocol name of this URL .

Usage

From source file:org.xwiki.contrib.jira.macro.internal.source.HTTPJIRAFetcher.java

private HttpHost createHttpHost(JIRAServer server) throws MalformedURLException {
    URL jiraURL = new URL(server.getURL());
    return new HttpHost(jiraURL.getHost(), jiraURL.getPort(), jiraURL.getProtocol());
}

From source file:br.com.uol.runas.classloader.JarClassLoader.java

private URL pathToUrl(String path) throws MalformedURLException {
    try {/*from ww w. ja  v  a2s .  c o  m*/
        final URL url = new URL(path);

        if (url.getProtocol().equals("jar")) {
            return url;
        }

        return new URL(transformToJarSpec(path));
    } catch (MalformedURLException e) {
        final File file = new File(path);

        if (file.isDirectory()) {
            return file.toURI().toURL();
        }

        return new URL(transformToJarSpec(file.toURI().toString()));
    }
}

From source file:com.anrisoftware.sscontrol.filesystem.FileSystem.java

private boolean isFileScheme(URL url) {
    return url.getProtocol().equalsIgnoreCase("file");
}

From source file:com.emobc.android.utils.RetreiveFileContentTask.java

@Override
protected String doInBackground(URL... params) {
    URL url = params[0];
    HttpClient httpclient = HttpUtils//  w w  w .  j a  v a  2  s .com
            .getHttpClient(url.getProtocol().equalsIgnoreCase(HttpUtils.HTTPS_PROTOCOL));

    HttpUriRequest httpUriRequest = createUriRequest(url);

    try {
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httpUriRequest);

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            String str = EntityUtils.toString(response.getEntity());
            return str;
        } else {
            Log.w("RetreiveFileContentTask: ",
                    "HttpStatus Code: " + String.valueOf(response.getStatusLine().getStatusCode()));
        }
    } catch (ClientProtocolException e) {
        Log.e("RetreiveFileContentTask: ClientProtocolException: ", e.getMessage());
        //          Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Log.e("RetreiveFileContentTask: IOException: ", e.getMessage());
        //          Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();             
    }
    return "";
}

From source file:com.amazon.speech.speechlet.verifier.CardSpeechletResponseVerifier.java

/**
 * Verifies the protocol of the provided URL and it logs a warning if the protocol is different
 * than {@value #VALID_IMAGE_PROTOCOL}./*from   w  w w  .j  ava 2s .c  o m*/
 *
 * @param imageUrlType
 *            the type of the image URL that is being verified
 * @param imageUrl
 *            the URL to be checked
 */
private void verifyProtocolImageUrl(String imageType, String imageUrl) {
    try {
        URL url = new URL(imageUrl);
        String protocol = url.getProtocol();
        if (!VALID_IMAGE_PROTOCOL.equals(protocol)) {
            log.warn("{} with value {} is invalid for the image of the card of type "
                    + "StandardCard since HTTPS is required", imageType, imageUrl);
        }
    } catch (MalformedURLException e) {
        log.warn("{} with value {} is malformed for the image of the card of type " + "StandardCard", imageType,
                imageUrl);
    }
}

From source file:cn.edu.pku.sei.plde.conqueroverfitting.localization.gzoltar.GZoltarSuspiciousProgramStatements.java

protected GZoltarSuspiciousProgramStatements(final URL[] classpath, Collection<String> packageNames,
        Metric metric, String testSrcPath, String srcPath, List<String> libPath) {
    try {//ww w  . j  a va2s. c  o m
        //gzoltar = new GZoltarJava7();
        gzoltar = new WGzoltar(System.getProperty("user.dir"), metric, testSrcPath, srcPath, libPath);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    ArrayList<String> classpaths = new ArrayList<String>();
    for (URL url : classpath) {
        if ("file".equals(url.getProtocol())) {
            classpaths.add(url.getPath());
        } else {
            classpaths.add(url.toExternalForm());
        }
    }

    gzoltar.setClassPaths(classpaths);
    gzoltar.addPackageNotToInstrument("org.junit");
    gzoltar.addPackageNotToInstrument("junit.framework");
    gzoltar.addTestPackageNotToExecute("junit.framework");
    gzoltar.addTestPackageNotToExecute("org.junit");
    for (String packageName : packageNames) {
        gzoltar.addPackageToInstrument(packageName);
    }
    for (URL url : classpath) {
        if (url.getPath().endsWith(".jar")) {
            gzoltar.addClassNotToInstrument(url.getPath());
            gzoltar.addPackageNotToInstrument(url.getPath());
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.StorageImpl.java

private String getKey(final Type type, final HtmlPage page) {
    switch (type) {
    case GLOBAL_STORAGE:
        return page.getUrl().getHost();

    case LOCAL_STORAGE:
        final URL url = page.getUrl();
        return url.getProtocol() + "://" + url.getHost() + ':' + url.getProtocol();

    case SESSION_STORAGE:
        final WebWindow topWindow = page.getEnclosingWindow().getTopWindow();
        return Integer.toHexString(topWindow.hashCode());

    default://from   w  ww  .  ja v  a 2 s .  c  o  m
        return null;
    }
}

From source file:com.blackducksoftware.tools.scmconnector.integrations.mercurial.MercurialConnector.java

/**
 * Constructs a valid HTTP url if a user *and* password is provided.
 *
 * @throws Exception/*w  w  w  .  j  a v  a  2 s  . c  o m*/
 */
private void buildURL() throws Exception {
    if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)) {
        URL url = new URL(repositoryURL);
        String protocol = url.getProtocol();
        int port = url.getPort();
        String host = url.getHost();
        String path = url.getPath();

        URIBuilder builder = new URIBuilder();
        builder.setScheme(protocol);
        builder.setHost(host);
        builder.setPort(port);
        builder.setPath(path);
        builder.setUserInfo(user, password);

        repositoryURL = builder.toString();
        // log.info("Using path: " + repositoryURL); // Reveals password
    }
}

From source file:com.cladonia.xngreditor.URLUtilities.java

/**
 * Convert the given URL to a file.// w  ww  . j  a  v a 2  s  .c o m
 * 
 * @param url the url to be converted.
 * 
 * @return a new file or null if the URL does not describe a file.
 */
public static File toFile(URL url) {
    if (url != null && url.getProtocol().equals("file")) {
        return new File(url.getFile());
    }

    return null;
}

From source file:net.sf.jabref.gui.help.HelpContent.java

/**
 * Convenience method for setPage(String)
 *///w ww.  jav  a2 s  .  co m
@Override
public void setPage(URL url) {
    if ("file".equals(url.getProtocol()) || "jar".equals(url.getProtocol())) {
        // Creating file by url.toString() and using file.getName() preserves anchors
        File file = new File(url.toString());
        setPage(file.getName(), JabRef.class);
    } else {
        //  open all external URLs externally
        JabRef.jrf.openBrowser(url.toString());
    }
}