List of usage examples for java.net URI toString
public String toString()
From source file:info.rmapproject.webapp.utils.WebappUtils.java
/** * Retrieve the node type based on URI provided. The graph visualization is colored based on * node type. Node types also appear in the legend. * * @param type the RDF type/* w w w . j a v a 2 s . co m*/ * @return the Node type */ public static String getNodeType(URI type) { if (type == null) { return Constants.NODETYPE_NOTYPE; } try { return typeMappings.getMessage(type.toString(), null, Locale.ENGLISH); } catch (NoSuchMessageException e) { return Constants.NODETYPE_OTHER; } }
From source file:com.vaadin.sass.testcases.scss.W3ConformanceTests.java
public static void extractCSS(final URI url, File targetdir) throws Exception { /*/*from w w w. j a v a 2s. c o m*/ * For each test URL: 1) extract <style> tag contents 2) extract from * <link rel="stylesheet"> files 3) extract inline style attributes from * all elements and wrap the result in .style {} */ Document doc = Jsoup.connect(url.toString()).timeout(20000).get(); List<String> tests = new ArrayList<String>(); for (Element e : doc.select("style[type=text/css]")) { tests.add(e.data()); } for (Element e : doc.select("link[rel=stylesheet][href][type=text/css]")) { URI cssUri = new URI(e.attr("href")); if (!cssUri.isAbsolute()) { cssUri = url.resolve(cssUri); } String encoding = doc.outputSettings().charset().name(); tests.add(IOUtils.toString(cssUri, encoding)); } for (Element e : doc.select("*[style]")) { tests.add(String.format(".style { %s }", e.attr("style"))); } for (final String test : tests) { targetdir.mkdirs(); String logfile = String.format("%s.%d.scss", FilenameUtils.getBaseName(url.toString()), tests.indexOf(test)); PrintStream dataLogger = new PrintStream(new File(targetdir, logfile)); dataLogger.println("/* Source: " + url + " */"); dataLogger.println(test); } }
From source file:com.ryan.ryanreader.fragments.ImageViewFragment.java
public static ImageViewFragment newInstance(final URI url, final RedditPost post) { final ImageViewFragment f = new ImageViewFragment(); final Bundle bundle = new Bundle(1); bundle.putString("url", url.toString()); if (post != null) bundle.putParcelable("post", post); f.setArguments(bundle);//from ww w .j av a 2 s . c o m return f; }
From source file:Main.java
/** * Extract the UUID part from a MusicBrainz identifier. * /*from w w w . ja v a 2 s . c o m*/ * This function takes a MusicBrainz ID (an absolute URI) as the input * and returns the UUID part of the URI, thus turning it into a relative * URI. If <code>uriStr</code> is null or a relative URI, then it is * returned unchanged. * * The <code>resType</code> parameter can be used for error checking. * Set it to 'artist', 'release', or 'track' to make sure * <code>uriStr</code> is a syntactically valid MusicBrainz identifier * of the given resource type. If it isn't, an * <code>IllegalArgumentException</code> exception is raised. This error * checking only works if <code>uriStr</code> is an absolute URI, of course. * * Example: * >>> MBUtils.extractUuid('http://musicbrainz.org/artist/c0b2500e-0cef-4130-869d-732b23ed9df5', 'artist') * 'c0b2500e-0cef-4130-869d-732b23ed9df5' * * @param uriStr A string containing a MusicBrainz ID (an URI), or null * @param resType A string containing a resource type * @return A String containing a relative URI or null * @throws URISyntaxException */ public static String extractUuid(String uriStr, String resType) { if (uriStr == null) { return null; } URI uri; try { uri = new URI(uriStr); } catch (URISyntaxException e) { return uriStr; // not really a valid URI, probably the UUID } if (uri.getScheme() == null) { return uriStr; // not really a valid URI, probably the UUID } if (!"http".equals(uri.getScheme()) || !"musicbrainz.org".equals(uri.getHost())) { throw new IllegalArgumentException(uri.toString() + " is no MB ID"); } String regex = "^/(label|artist|release-group|release|recording|work|collection)/([^/]*)$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(uri.getPath()); if (m.matches()) { if (resType == null) { return m.group(2); } else { if (resType.equals(m.group(1))) { return m.group(2); } else { throw new IllegalArgumentException("expected '" + resType + "' Id"); } } } else { throw new IllegalArgumentException("'" + uriStr + " is no valid MB id"); } }
From source file:com.ibm.stocator.fs.common.Utils.java
/** * Test if hostName of the form container.service * * @param uri schema URI//w w w .ja v a 2s . co m * @return true if hostName of the form container.service */ public static boolean validSchema(URI uri) { LOG.trace("Checking schema {}", uri.toString()); String hostName = Utils.getHost(uri); LOG.trace("Got hostname as {}", hostName); int i = hostName.lastIndexOf("."); if (i < 0) { return false; } String service = hostName.substring(i + 1); LOG.trace("Got service as {}", service); if (service.isEmpty() || service.contains(".")) { return false; } return true; }
From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java
public static URI parseURI(String uriString) throws ParseException { Validate.notEmpty(uriString, "uriString"); URI uri; try {/* w w w.java 2 s .c om*/ uri = new URI(uriString); } catch (URISyntaxException e) { throw new ParseException("failed to parse uri", e); } String[] allowedSchemes = { "https" }; UrlValidator urlValidator = new UrlValidator(allowedSchemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(uri.toString())) { throw new ParseException("uri is not a valid https url"); } return uri; }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getHttpsGitUrlFromSshUrl(final String sshGitRemoteUrl) { if (isSshGitRemoteUrl(sshGitRemoteUrl)) { final URI sshUrl; if (!StringUtils.startsWithIgnoreCase(sshGitRemoteUrl, "ssh://")) { sshUrl = UrlHelper.createUri("ssh://" + sshGitRemoteUrl); } else {// ww w .j a v a 2s. co m sshUrl = UrlHelper.createUri(sshGitRemoteUrl); } final String host = sshUrl.getHost(); final String path = sshUrl.getPath(); final URI httpsUrl = UrlHelper.createUri("https://" + host + path); return httpsUrl.toString(); } return null; }
From source file:com.vaushell.superpipes.tools.HTTPhelper.java
/** * Expand all shorten URLs contained inside a message. * * @param builder Http client builder// w w w .java 2 s. com * @param message the message * @return the message with expanded URLs * @throws IOException */ public static String expandShortenURLinMessage(final HttpClientBuilder builder, final String message) throws IOException { if (builder == null || message == null) { throw new IllegalArgumentException(); } final Pattern p = Pattern.compile("http\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*)?"); final Matcher m = p.matcher(message); String result = message; while (m.find()) { final URI shorten = URI.create(m.group()); final List<URI> redirects = HTTPhelper.getRedirected(builder, shorten); if (!redirects.isEmpty()) { final URI expand = redirects.get(redirects.size() - 1); result = result.replace(shorten.toString(), expand.toString()); } } return result; }
From source file:com.puppycrawl.tools.checkstyle.ConfigurationLoader.java
/** * Returns the module configurations in a specified file. * * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @param omitIgnoredModules {@code true} if modules with severity * 'ignore' should be omitted, {@code false} otherwise * @return the check configurations//from w w w. j a v a2s . com * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver, boolean omitIgnoredModules) throws CheckstyleException { // figure out if this is a File or a URL final URI uri = CommonUtils.getUriByFilename(config); final InputSource source = new InputSource(uri.toString()); return loadConfiguration(source, overridePropsResolver, omitIgnoredModules); }
From source file:org.altchain.neo4j.database.Database.java
@SuppressWarnings("unchecked") public static URI addNodeToIndex(URI nodeUri, String indexName, String key, Object value) { String indexUri = NODE_INDEX_ROOT + indexName; WebResource resource = Client.create().resource(indexUri); JSONObject params = new JSONObject(); params.put("value", value); params.put("uri", nodeUri.toString()); params.put("key", key); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .entity(params.toJSONString()).post(ClientResponse.class); response.getEntity(String.class); final URI location = response.getLocation(); logger.debug(String.format("POST to [%s], status code [%d], location header [%s], JSON: %s", indexUri, response.getStatus(), location.toString(), params.toJSONString())); response.close();// ww w . j a v a 2 s .c om return location; }