private static String normalizeClusterUrl(String clusterIdentifier) { try { URI uri = new URI(clusterIdentifier.trim()); // URIs without protocol prefix if (!uri.isOpaque() && null != uri.getHost()) { clusterIdentifier = uri.getHost(); } else { clusterIdentifier = uri.toString().replaceAll("[/:]"," ").trim().replaceAll(" ", "_"); } } catch (URISyntaxException e) { //leave ID as is } return clusterIdentifier; }
/** * Returns the path from the given {@link URI}. In case the given {@link URI} is opaque, e.g. beginning with jar:file, * the path is extracted from URI by leaving out the protocol prefix, see DATAJPA-519. * * @param uri * @return */ private static String getResourcePath(URI uri) throws IOException { if (uri.isOpaque()) { // e.g. jar:file:/foo/lib/somelib.jar!/com/acme/orm.xml String rawPath = uri.toString(); if (rawPath != null) { int exclamationMarkIndex = rawPath.lastIndexOf('!'); if (exclamationMarkIndex > -1) { // /com/acme/orm.xml return rawPath.substring(exclamationMarkIndex + 1); } } } return uri.getPath(); } }
@Override public boolean matches(final URI uri, final String abstractType, final String abstractTypeAuthority) { if (! uri.isOpaque()) return false; String scheme = uri.getScheme(); String name; if (scheme.equals("domain")) { // special parsing rules for security domains String ssp = uri.getSchemeSpecificPart(); int idx = ssp.indexOf('@'); if (idx != -1) { name = ssp.substring(idx + 1, ssp.length()); } else { name = ssp; } } else { name = uri.getSchemeSpecificPart(); } return name.equals(this.name) && super.matches(uri, abstractType, abstractTypeAuthority); }
/** * Adds a URL-valued attribute. * @param attr the attribute name * @param value the attribute value, e.g. {@code "/my/module/resource.html"} * or {@code "nbresloc:/my/module/resource.html"}; relative values permitted * but not likely useful as base URL would be e.g. {@code "jar:...!/META-INF/"} * @return this builder * @throws LayerGenerationException in case an opaque URI is passed as {@code value} */ public File urlvalue(String attr, URI value) throws LayerGenerationException { if (value.isOpaque()) { throw new LayerGenerationException("Cannot use an opaque URI: " + value, originatingElement); } attrs.put(attr, new String[] {"urlvalue", value.toString()}); return this; }
/** * Dump this URI to the log. * * @param description * @param dburi */ static void dump(String description, URI dburi) { String dumpString = String.format( "dump (%s)\n: isOpaque=%s, isAbsolute=%s Scheme=%s,\n SchemeSpecificPart=%s,\n Host=%s,\n Port=%s,\n Path=%s,\n Fragment=%s,\n Query=%s\n", description, dburi.isOpaque(), dburi.isAbsolute(), dburi.getScheme(), dburi.getSchemeSpecificPart(), dburi.getHost(), dburi.getPort(), dburi.getPath(), dburi.getFragment(), dburi.getQuery()); LOGGER.fine(dumpString); String query = dburi.getQuery(); if (null != query && !"".equals(query)) { String[] params = query.split("&"); Map<String, String> map = new HashMap<>(); for (String param : params) { String[] splits = param.split("="); String name = splits[0]; String value = null; if (splits.length > 1) { value = splits[1]; } map.put(name, value); LOGGER.fine(String.format("name=%s,value=%s\n", name, value)); } } // return map; }
/** * Set the concrete URI. * * @param uri the concrete URI (must not be {@code null}) * @return this builder */ public Builder setUri(final URI uri) { Assert.checkNotNullParam("uri", uri); final String fragment = uri.getFragment(); if (fragment != null && ! fragment.isEmpty()) { throw new IllegalArgumentException("Service URI " + uri + " may not have a fragment"); } if (! uri.isAbsolute()) { throw new IllegalArgumentException("Service URI " + uri + " must be absolute"); } final String query = uri.getQuery(); // sanitized URI try { this.uri = uri.isOpaque() ? new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null) : new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query != null && query.isEmpty() ? null : query, null); } catch (URISyntaxException e) { // should be impossible as the original URI was valid throw new IllegalStateException(e); } return this; }
/** * This parses out all of the parameters in the query string for both * http: and geo: URIs. This will only work on URIs with valid syntax, so * it will not work on URIs that do odd things like have a query string in * the fragment, like this one: * http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000 * * @param uri * @return {@link Map<String, String>} a Map of the query parameters */ static Map<String, String> getQueryParameters(URI uri) { String query = null; if (uri.isOpaque()) { String schemeSpecificPart = uri.getSchemeSpecificPart(); int pos = schemeSpecificPart.indexOf("?"); if (pos == schemeSpecificPart.length()) { query = ""; } else if (pos > -1) { query = schemeSpecificPart.substring(pos + 1); } } else { query = uri.getRawQuery(); } return getQueryParameters(query); }
Assert.notNull(uri, "URI must not be null"); this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); resetHierarchicalComponents();
public static File resourceAsFile(String path) throws URISyntaxException, IOException { ClassLoader cl = TestUtils.class.getClassLoader(); URI uri = cl.getResource(path).toURI(); if (uri.isAbsolute() && !uri.isOpaque()) { return new File(uri); } else { File tmpFile = File.createTempFile("tmpfile-", ".data", TMP_DIR); tmpFile.deleteOnExit(); try (InputStream is = cl.getResourceAsStream(path)) { FileUtils.copyInputStreamToFile(is, tmpFile); return tmpFile; } } }
if (uri.isOpaque()) { scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart();
if (uri.isOpaque()) { scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart();
if (uri.isOpaque()) { scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart();
Assert.notNull(uri, "URI must not be null"); this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); resetHierarchicalComponents();
try { URI systemUri = new URI(systemId); if (!systemUri.isAbsolute() && !systemUri.isOpaque()) {
throw new ConfigXMLParseException("Invalid include URI: must not contain fragment identifier", getLocation()); fallback |= href.isOpaque(); break;
private void validateOriginAsUri(String origin) throws PreflightFailedException { try { final URI originUri = URI.create(origin); if (originUri.isOpaque() || !originUri.isAbsolute()) { throw new IllegalArgumentException( "The origin URI must be absolute and not opaque."); } } catch (IllegalArgumentException ex) { throw new PreflightFailedException("Origin '" + origin + "' is not a valid URI"); } }
/** * Returns true if the provided origin is from a browser extension. * * @param origin the origin to check. * @return true if the provided origin is from a browser extension, * otherwise returns false. */ boolean isOriginABrowserExtension(String origin) { if (StringUtils.isEmpty(origin)) { return false; } try { final URI originUri = new URI(origin); return BROWSER_EXTENSION_ORIGINS.contains(originUri.getScheme()) && !originUri.isOpaque(); } catch (URISyntaxException e) { return false; } }
public String resolveSchemaLocation(XSDSchema xsdSchema, String namespaceURI, String schemaLocationURI) { try { URI contextUri = new URI(xsdSchema.getSchemaLocation()); if (contextUri.isOpaque()) { // probably a jar:file: URL, which is opaque and thus not // supported by URI.resolve() URL contextUrl = new URL(xsdSchema.getSchemaLocation()); return (new URL(contextUrl, schemaLocationURI)).toString(); } else { return contextUri.resolve(schemaLocationURI).toString(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (MalformedURLException e) { throw new RuntimeException(e); } } }));
private boolean matchNormalized(URI uri) { if(uriPattern.isOpaque()) { // This url only has scheme, scheme-specific part and fragment return uri.isOpaque() && match(uriPattern.getScheme(), uri.getScheme()) && match(uriPattern.getSchemeSpecificPart(), uri.getSchemeSpecificPart()) && match(uriPattern.getFragment(), uri.getFragment()); } else { return match(uriPattern.getScheme(), uri.getScheme()) && match(uriPattern.getAuthority(), uri.getAuthority()) && match(uriPattern.getQuery(), uri.getQuery()) && match(uriPattern.getPath(), uri.getPath()) && match(uriPattern.getFragment(), uri.getFragment()); } }