List of usage examples for java.net URI getScheme
public String getScheme()
From source file:annis.libgui.Helper.java
public static String generateCitation(String aql, Set<String> corpora, int contextLeft, int contextRight, String segmentation, int start, int limit) { try {/* w w w.ja va 2s . c om*/ URI appURI = UI.getCurrent().getPage().getLocation(); return new URI(appURI.getScheme(), null, appURI.getHost(), appURI.getPort(), getContext(), null, StringUtils.join( citationFragment(aql, corpora, contextLeft, contextRight, segmentation, start, limit), "&")).toASCIIString(); } catch (URISyntaxException ex) { log.error(null, ex); } return "ERROR"; }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
/** * Extends scheme to include 'classpath'. * * @param uriString//w ww. j a va 2 s . c om * @return * @throws URISyntaxException * @throws IOException */ public static URL uriToURL(String uriString) throws URISyntaxException, IOException { URI uri = new URI(uriString); String scheme = uri.getScheme(); if (scheme == null) throw new URISyntaxException(uriString, "Invalid URI syntax: missing scheme => " + uriString); if (scheme.equals("classpath")) { ClassPathResource res = new ClassPathResource(uri.getSchemeSpecificPart()); return res.getURL(); } else { return uri.toURL(); } }
From source file:org.apache.gobblin.utils.HttpUtils.java
/** * Convert D2 URL template into a string used for throttling limiter * * Valid:/*from w ww . ja va 2 s.c om*/ * d2://host/${resource-id} * * Invalid: * d2://host${resource-id}, because we cannot differentiate the host */ public static String createR2ClientLimiterKey(Config config) { String urlTemplate = config.getString(HttpConstants.URL_TEMPLATE); try { String escaped = URIUtil.encodeQuery(urlTemplate); URI uri = new URI(escaped); if (uri.getHost() == null) throw new RuntimeException("Cannot get host part from uri" + urlTemplate); String key = uri.getScheme() + "/" + uri.getHost(); if (uri.getPort() > 0) { key = key + "/" + uri.getPort(); } log.info("Get limiter key [" + key + "]"); return key; } catch (Exception e) { throw new RuntimeException("Cannot create R2 limiter key", e); } }
From source file:piecework.util.FormUtility.java
public static boolean isExternal(URI uri) { if (uri != null) { String scheme = uri.getScheme(); return StringUtils.isNotEmpty(scheme) && (scheme.equals("http") || scheme.equals("https")); }/* w w w. j a va 2 s .c o m*/ return false; }
From source file:com.google.caja.precajole.StaticPrecajoleMap.java
public static String normalizeUri(String uri) { try {/* w w w . j a va 2s. c o m*/ URI u = new URI(uri).normalize(); if (u.getHost() != null) { u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); } else if (u.getScheme() != null) { u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment()); } return u.toString(); } catch (URISyntaxException e) { return uri; } }
From source file:org.elasticsearch.client.sniff.ElasticsearchHostsSniffer.java
private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { HttpHost httpHost = null;// w ww. ja va 2 s . c o m String fieldName = null; while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { if ("http".equals(fieldName)) { while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); httpHost = new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), boundAddressAsURI.getScheme()); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { parser.skipChildren(); } } } else { parser.skipChildren(); } } } //http section is not present if http is not enabled on the node, ignore such nodes if (httpHost == null) { logger.debug("skipping node [" + nodeId + "] with http disabled"); return null; } return httpHost; }
From source file:com.alexholmes.hdfsslurper.Configurator.java
public static boolean compareFs(FileSystem fs1, FileSystem fs2) { URI uri1 = fs1.getUri(); URI uri2 = fs2.getUri();//from ww w .j a v a2s . co m if (uri1.getScheme() == null) { return false; } if (!uri1.getScheme().equals(uri2.getScheme())) { return false; } return uri1.equals(uri2); }
From source file:mitm.common.util.URIUtils.java
/** * Checks whether the given identifier is a valid URI. If type is null, a FULL check will be done. * If identifier is null, false will be returned. *//*from w ww . j a va2 s . c om*/ public static boolean isValidURI(String identifier, URIType type) { if (identifier == null) { return false; } if (type == null) { type = URIType.FULL; } boolean valid = false; try { URI uri = new URI(identifier); if (type == URIType.BASE) { /* * Only accepts URI of the form [scheme:][//authority][path] */ if (StringUtils.isNotEmpty(uri.getScheme()) && StringUtils.isNotEmpty(uri.getHost()) && StringUtils.isEmpty(uri.getQuery()) && StringUtils.isEmpty(uri.getFragment())) { valid = true; } } else if (type == URIType.RELATIVE) { /* * Only accepts URI of the form [path][?query][#fragment] */ if (StringUtils.isEmpty(uri.getScheme()) && StringUtils.isEmpty(uri.getAuthority()) && StringUtils.isEmpty(uri.getHost())) { valid = true; } } else if (type == URIType.FULL) { /* * Only accepts URI of the form [scheme:][//authority][path][?query][#fragment] */ if (StringUtils.isNotEmpty(uri.getScheme()) && StringUtils.isNotEmpty(uri.getHost())) { valid = true; } } else { valid = true; } } catch (URISyntaxException e) { // ignore } return valid; }
From source file:com.inmobi.conduit.distcp.tools.util.DistCpUtils.java
public static boolean compareFs(FileSystem srcFs, FileSystem destFs) { URI srcUri = srcFs.getUri(); URI dstUri = destFs.getUri(); if (srcUri.getScheme() == null) { return false; }/*from www . j a va2s . c om*/ if (!srcUri.getScheme().equals(dstUri.getScheme())) { return false; } String srcHost = srcUri.getHost(); String dstHost = dstUri.getHost(); if ((srcHost != null) && (dstHost != null)) { try { srcHost = InetAddress.getByName(srcHost).getCanonicalHostName(); dstHost = InetAddress.getByName(dstHost).getCanonicalHostName(); } catch (UnknownHostException ue) { return false; } if (!srcHost.equals(dstHost)) { return false; } } else if (srcHost == null && dstHost != null) { return false; } else if (srcHost != null) { return false; } //check for ports if (srcUri.getPort() != dstUri.getPort()) { return false; } return true; }
From source file:URISupport.java
public static CompositeData parseComposite(URI uri) throws URISyntaxException { CompositeData rc = new CompositeData(); rc.scheme = uri.getScheme(); String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim(); parseComposite(uri, rc, ssp);/*from www .j a v a 2s. com*/ rc.fragment = uri.getFragment(); return rc; }