List of usage examples for java.net URI getRawFragment
public String getRawFragment()
From source file:Main.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.java2s.com"); System.out.println("URI : " + uri); System.out.println("Raw Fragment : " + uri.getRawFragment()); }
From source file:Main.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.example.org"); System.out.println("URI : " + uri); System.out.println("Raw Authority : " + uri.getRawAuthority()); System.out.println("Raw Fragment : " + uri.getRawFragment()); System.out.println("Fragment : " + uri.getFragment()); System.out.println("Authority : " + uri.getAuthority()); System.out.println("Authority : " + uri.getRawPath()); System.out.println("RawQuery : " + uri.getRawQuery()); System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart()); System.out.println("RawUserInfo : " + uri.getRawUserInfo()); }
From source file:IRIDemo.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://r%C3%A9sum%C3%A9.example.org"); System.out.println("URI : " + uri); System.out.println("Raw Authority : " + uri.getRawAuthority()); System.out.println("Raw Fragment : " + uri.getRawFragment()); System.out.println("Fragment : " + uri.getFragment()); System.out.println("Authority : " + uri.getAuthority()); System.out.println("Authority : " + uri.getRawPath()); System.out.println("RawQuery : " + uri.getRawQuery()); System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart()); System.out.println("RawUserInfo : " + uri.getRawUserInfo()); }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList, boolean removeFragment) { if (href == null) return null; href = href.trim();/*from w ww. j a v a 2s .co m*/ if (href.length() == 0) return null; String fragment = null; try { URI u = URIUtils.resolve(currentURL.toURI(), href); href = u.toString(); href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList); URI uri = URI.create(href); uri = uri.normalize(); String p = uri.getPath(); if (p != null) if (p.contains("/./") || p.contains("/../")) return null; if (!removeFragment) fragment = uri.getRawFragment(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment).normalize().toURL(); } catch (MalformedURLException e) { Logging.info(e.getMessage()); return null; } catch (URISyntaxException e) { Logging.info(e.getMessage()); return null; } catch (IllegalArgumentException e) { Logging.info(e.getMessage()); return null; } }
From source file:org.fcrepo.apix.integration.StreamingIT.java
/** * Appends the path to the URI. All other components of the URI are preserved. * * @param uri the URI with the path being appended to * @param toAppend the path to be appended to the URI * @return a new URI with a path component ending with {@code toAppend} * @throws URISyntaxException/*from ww w. ja v a2 s . co m*/ */ private static URI appendToPath(final URI uri, final String toAppend) throws URISyntaxException { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath() + toAppend, uri.getRawQuery(), uri.getRawFragment()); }
From source file:org.esigate.util.UriUtils.java
/** * Creates an {@link URI} after escaping some special characters in order to tolerate some incorrect URI types. If * the uri contains a server name but no path, the path is set to "/" as a browser would do. * //from w w w. j av a 2s . c om * @param uri * the URI as a {@link String} * @return the URI as a {@link URI} object */ public static URI createURI(String uri) { uri = encodeIllegalCharacters(uri); URI result = URI.create(uri); if (result.getHost() != null && StringUtils.isEmpty(result.getPath())) { result = URI.create(createURI(result.getScheme(), result.getHost(), result.getPort(), "/", result.getRawQuery(), result.getRawFragment())); } return result; }
From source file:org.hippoecm.frontend.service.restproxy.RestProxyServicePlugin.java
static String createRestURI(String value, final HttpServletRequest request) { if (StringUtils.isEmpty(value)) { throw new IllegalStateException( "No REST service URI configured. Please set the plugin configuration property '" + CONFIG_REST_URI + "'"); }/*from w w w. j a v a2 s . c o m*/ try { URI u = new URI(value); final int portNumber; if (u.getPort() == -1) { portNumber = request.getLocalPort(); } else { portNumber = u.getPort(); } return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), portNumber, u.getRawPath(), u.getRawQuery(), u.getRawFragment()).toString(); } catch (URISyntaxException e) { throw new IllegalStateException( "Invalid REST service URI configured. Please correct the plugin configuration property '" + CONFIG_REST_URI + "'", e); } }
From source file:com.gamesalutes.utils.WebUtils.java
/** * Adds the query parameters to the uri <code>path</code>. * /*from w w w . j a v a 2s. com*/ * @param path the uri * @param parameters the query parameters to set for the uri * @return <code>path</code> with the query parameters added */ public static URI setQueryParameters(URI path, Map<String, String> parameters) { try { return new URI(path.getScheme(), path.getRawUserInfo(), path.getHost(), path.getPort(), path.getRawPath(), urlEncode(parameters, false), path.getRawFragment()); } catch (URISyntaxException e) { // shouldn't happen throw new AssertionError(e); } }
From source file:org.orbeon.oxf.util.URLRewriterUtils.java
/** * Rewrite a URL based on a base URL, a URL, and a rewriting mode. * * @param scheme base URL scheme * @param host base URL host * @param port base URL port * @param contextPath base URL context path * @param requestPath base URL request path * @param urlString URL to rewrite (accept human-readable URI) * @param rewriteMode rewrite mode (see ExternalContext.Response) * @return rewritten URL *//*from w w w.j ava 2s.com*/ private static String rewriteURL(String scheme, String host, int port, String contextPath, String requestPath, String urlString, int rewriteMode) { // Accept human-readable URI urlString = NetUtils.encodeHRRI(urlString, true); // Case where a protocol is specified: the URL is left untouched (except for human-readable processing) if (NetUtils.urlHasProtocol(urlString)) return urlString; try { final String baseURLString; { String _baseURLString; // Prepend absolute base if needed if ((rewriteMode & ExternalContext.Response.REWRITE_MODE_ABSOLUTE) != 0) { _baseURLString = scheme + "://" + host + ((port == 80 || port == -1) ? "" : ":" + port); } else { _baseURLString = ""; } // Append context path if needed if ((rewriteMode & ExternalContext.Response.REWRITE_MODE_ABSOLUTE_PATH_NO_CONTEXT) == 0) _baseURLString = _baseURLString + contextPath; baseURLString = _baseURLString; } // Return absolute path URI with query string and fragment identifier if needed if (urlString.startsWith("?")) { // This is a special case that appears to be implemented // in Web browsers as a convenience. Users may use it. return baseURLString + requestPath + urlString; } else if ((rewriteMode & ExternalContext.Response.REWRITE_MODE_ABSOLUTE_PATH_OR_RELATIVE) != 0 && !urlString.startsWith("/") && !"".equals(urlString)) { // Don't change the URL if it is a relative path and we don't force absolute return urlString; } else { // Regular case, parse the URL final URI baseURIWithPath = new URI("http", "example.org", requestPath, null); final URI resolvedURI = baseURIWithPath.resolve(urlString).normalize();// normalize to remove "..", etc. // Append path, query and fragment final String query = resolvedURI.getRawQuery(); final String fragment = resolvedURI.getRawFragment(); final String tempResult = resolvedURI.getRawPath() + ((query != null) ? "?" + query : "") + ((fragment != null) ? "#" + fragment : ""); // Prepend base return baseURLString + tempResult; } } catch (Exception e) { throw new OXFException(e); } }
From source file:org.echocat.jomon.resources.RotatingDomainResourceRequestUriGenerator.java
public void setBaseUri(URI baseUri) { if (baseUri != null && (!isEmpty(baseUri.getRawFragment()) || !isEmpty(baseUri.getRawQuery()))) { throw new IllegalArgumentException("Provided baseUri has a fragment and/or query."); }//from w w w . j a va 2 s. c o m _baseUri = baseUri; }