Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

In this page you can find the example usage for java.net URI getScheme.

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:mobisocial.nfcserver.handler.HttpFileHandler.java

public int handleNdef(NdefMessage[] ndefMessages) {
    URI page = null;
    NdefRecord firstRecord = ndefMessages[0].getRecords()[0];
    if (UriRecord.isUri(firstRecord)) {
        page = UriRecord.parse(firstRecord).getUri();
    }//from   w  w w  .  j a v  a 2 s  .  c  o  m

    try {
        if (page != null && (page.getScheme().startsWith("http"))) {
            System.out.println("trying to get " + page);
            if (page.getPath() == null || !page.toString().contains(".")) {
                return NDEF_PROPAGATE;
            }

            try {
                String extension = page.toString().substring(page.toString().lastIndexOf(".") + 1);
                if (!MimeTypeHandler.MIME_EXTENSIONS.containsValue(extension)) {
                    return NDEF_PROPAGATE;
                }

                // Download content
                System.out.println("Downloading " + extension + " file.");
                HttpGet httpGet = new HttpGet(page);
                HttpClient httpClient = new DefaultHttpClient();
                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity entity = httpResponse.getEntity();
                InputStream content = entity.getContent();

                File fileOut = new File("nfcfiles/" + System.currentTimeMillis() + "." + extension);
                fileOut.getParentFile().mkdirs();
                FileOutputStream fileOutStream = new FileOutputStream(fileOut);
                BufferedOutputStream buffered = new BufferedOutputStream(fileOutStream);
                byte[] buf = new byte[1024];
                while (true) {
                    int r = content.read(buf);
                    if (r <= 0)
                        break;
                    buffered.write(buf, 0, r);
                }
                buffered.close();
                fileOutStream.close();

                MimeTypeHandler.openFile(fileOut);
                return NDEF_CONSUME;
            } catch (Exception e) {
                e.printStackTrace();
                return NDEF_PROPAGATE;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Error launching page", e);
    }
    return NDEF_PROPAGATE;
}

From source file:net.bluemix.connectors.core.info.IBMObjectStorageServiceInfo.java

public IBMObjectStorageServiceInfo(final String id, final String url) throws URISyntaxException {
    super(id);/*w  w  w .  j  av  a2 s.co m*/
    final String modUrl = url.replaceFirst(IBMObjectStorageServiceInfo.SCHEME, "https");
    final URI uri = new URI(modUrl);
    this.authUrl = uri.getScheme() + "://" + uri.getHost();
    if (uri.getPort() > 0) {
        this.authUrl = authUrl + ":" + uri.getPort();
    }
    if (uri.getUserInfo() != null) {
        final String[] credentials = uri.getUserInfo().split(":");
        this.userId = credentials[0];
        this.password = credentials[1];
    }
    if (uri.getPath() != null) {
        //the path includes the '/' after the host
        final String[] path = uri.getPath().split("/");
        if (path.length == 3) {
            this.project = path[1];
            this.domainName = path[2];
        }
    }

}

From source file:com.vp9.plugin.WebSocket.java

/**
 * Create the uri./*from w w w .ja va2 s .c o m*/
 * @param uriString
 * @return
 * @throws URISyntaxException
 */
private URI createURI(String uriString) throws URISyntaxException {
    URI uri = new URI(uriString);
    int port = uri.getPort();

    if (port == -1) {
        if ("ws".equals(uri.getScheme())) {
            port = 80;
        } else if ("wss".equals(uri.getScheme())) {
            port = 443;
        }
        uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), port, uri.getPath(), uri.getQuery(),
                uri.getFragment());
    }
    return uri;
}

From source file:io.curly.artifact.web.remote.PaperclipLinkCatcher.java

private String reconstructURI(String host, String href) {
    URI original;
    try {//w  w  w.  j ava2s . com
        original = new URI(href);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Cannot create URI from: " + href);
    }
    int port = 80;
    if ("https".equals(original.getScheme())) {
        port = 443;
    }
    if (host.contains(":")) {
        String[] pair = host.split(":");
        host = pair[0];
        port = Integer.valueOf(pair[1]);
    }
    if (host.equals(original.getHost()) && port == original.getPort()) {
        return href;
    }
    String scheme = original.getScheme();
    if (scheme == null) {
        scheme = port == 443 ? "https" : "http";
    }

    StringBuilder sb = new StringBuilder();
    sb.append(scheme).append("://");
    if (StringUtils.hasText(original.getRawUserInfo())) {
        sb.append(original.getRawUserInfo()).append("@");
    }
    sb.append(host);
    if (port >= 0) {
        sb.append(":").append(port);
    }
    sb.append(original.getPath());
    if (StringUtils.hasText(original.getRawQuery())) {
        sb.append("?").append(original.getRawQuery());
    }
    if (StringUtils.hasText(original.getRawFragment())) {
        sb.append("#").append(original.getRawFragment());
    }

    return sb.toString();
}

From source file:com.android.idtt.http.client.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8));
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:net.geoprism.localization.LocaleManager.java

private Collection<Locale> loadCLDRs() {
    try {/*from ww  w.j a va  2  s  . c  o  m*/

        // Get the list of known CLDR locale
        Set<Locale> locales = new HashSet<Locale>();

        Set<String> paths = new HashSet<String>();

        URL resource = this.getClass().getResource("/cldr/main");
        URI uri = resource.toURI();

        if (uri.getScheme().equals("jar")) {
            FileSystem fileSystem = FileSystems.newFileSystem(uri, new HashMap<String, Object>());
            Path path = fileSystem.getPath("/cldr/main");

            Stream<Path> walk = Files.walk(path, 1);

            try {
                for (Iterator<Path> it = walk.iterator(); it.hasNext();) {
                    Path location = it.next();

                    paths.add(location.toAbsolutePath().toString());
                }
            } finally {
                walk.close();
            }
        } else {
            String url = resource.getPath();
            File root = new File(url);

            File[] files = root.listFiles(new DirectoryFilter());

            if (files != null) {
                for (File file : files) {
                    paths.add(file.getAbsolutePath());
                }
            }
        }

        for (String path : paths) {
            File file = new File(path);

            String filename = file.getName();

            locales.add(LocaleManager.getLocaleForName(filename));
        }

        return locales;
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}

From source file:org.cloudfoundry.identity.uaa.login.saml.IdentityProviderConfigurator.java

protected String adjustURIForPort(String uri) throws URISyntaxException {
    URI metadataURI = new URI(uri);
    if (metadataURI.getPort() < 0) {
        switch (metadataURI.getScheme()) {
        case "https":
            return new URIBuilder(uri).setPort(443).build().toString();
        case "http":
            return new URIBuilder(uri).setPort(80).build().toString();
        default://w  ww.  ja va2s  .c om
            return uri;
        }
    }
    return uri;
}

From source file:at.gv.egiz.bku.slcommands.impl.cms.Signature.java

protected AlgorithmID getAlgorithmID(String uri) throws URISyntaxException {
    String oid = null;//from  w w w .j av  a  2s  . c  om
    URI urn = new URI(uri);
    String scheme = urn.getScheme();
    if ("URN".equalsIgnoreCase(scheme)) {
        String schemeSpecificPart = urn.getSchemeSpecificPart().toLowerCase();
        if (schemeSpecificPart.startsWith("oid:")) {
            oid = schemeSpecificPart.substring(4, schemeSpecificPart.length());
        }
    }
    return new AlgorithmID(new ObjectID(oid));
}

From source file:chat.viska.xmpp.Connection.java

/**
 * Constructs a {@link Connection} with a full server URI. Convenient method
 * of {@link #Connection(Protocol, String, String, int, String)}.
 *//*from   www . j av a 2 s .  c om*/
public Connection(final Protocol protocol, final URI uri) {
    this(protocol, uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
}

From source file:com.trickl.crawler.protocol.http.HttpProtocol.java

@Override
public boolean isAllowed(URI uri) throws IOException {
    if (forceAllow) {
        return forceAllow;
    }// w w  w.j a  v a  2 s  . com

    URI baseURI;
    try {
        baseURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), "/", null, null);
    } catch (URISyntaxException ex) {
        log.error("Unable to determine base URI for " + uri);
        return false;
    }

    NoRobotClient nrc = new NoRobotClient(contentLoader, userAgent);
    try {
        nrc.parse(baseURI);
    } catch (NoRobotException ex) {
        log.error("Failure parsing robots.txt: " + ex.getMessage());
        return false;
    }
    boolean test = nrc.isUrlAllowed(uri);
    if (log.isInfoEnabled()) {
        log.info(uri + " is " + (test ? "allowed" : "denied"));
    }
    return test;
}