List of usage examples for java.net URL getRef
public String getRef()
From source file:org.opencms.staticexport.CmsLinkManager.java
/** * Calculates the absolute URI for the "relativeUri" with the given absolute "baseUri" as start. <p> * /*ww w . j a v a 2 s . c o m*/ * If "relativeUri" is already absolute, it is returned unchanged. * This method also returns "relativeUri" unchanged if it is not well-formed.<p> * * @param relativeUri the relative URI to calculate an absolute URI for * @param baseUri the base URI, this must be an absolute URI * * @return an absolute URI calculated from "relativeUri" and "baseUri" */ public static String getAbsoluteUri(String relativeUri, String baseUri) { if (isAbsoluteUri(relativeUri)) { // URI is null or already absolute return relativeUri; } try { URL url = new URL(new URL(m_baseUrl, baseUri), relativeUri); StringBuffer result = new StringBuffer(100); result.append(url.getPath()); if (url.getQuery() != null) { result.append('?'); result.append(url.getQuery()); } if (url.getRef() != null) { result.append('#'); result.append(url.getRef()); } return result.toString(); } catch (MalformedURLException e) { return relativeUri; } }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified path. * @param u the URL on which to base the returned URL * @param newPath the new path to use in the returned URL * @return a new URL identical to the specified URL, except using the specified path * @throws MalformedURLException if there is a problem creating the new URL *///from w w w .ja va 2 s . c o m public static URL getUrlWithNewPath(final URL u, final String newPath) throws MalformedURLException { return createNewUrl(u.getProtocol(), u.getAuthority(), newPath, u.getRef(), u.getQuery()); }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified protocol. * @param u the URL on which to base the returned URL * @param newProtocol the new protocol to use in the returned URL * @return a new URL identical to the specified URL, except using the specified protocol * @throws MalformedURLException if there is a problem creating the new URL */// w w w . j a v a 2 s . c om public static URL getUrlWithNewProtocol(final URL u, final String newProtocol) throws MalformedURLException { return createNewUrl(newProtocol, u.getAuthority(), u.getPath(), u.getRef(), u.getQuery()); }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified query string. * @param u the URL on which to base the returned URL * @param newQuery the new query string to use in the returned URL * @return a new URL identical to the specified URL, except using the specified query string * @throws MalformedURLException if there is a problem creating the new URL *///from ww w. j a va2 s. co m public static URL getUrlWithNewQuery(final URL u, final String newQuery) throws MalformedURLException { return createNewUrl(u.getProtocol(), u.getAuthority(), u.getPath(), u.getRef(), newQuery); }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified port. * @param u the URL on which to base the returned URL * @param newPort the new port to use in the returned URL * @return a new URL identical to the specified URL, except using the specified port * @throws MalformedURLException if there is a problem creating the new URL *///from ww w. jav a2s.c o m public static URL getUrlWithNewPort(final URL u, final int newPort) throws MalformedURLException { return createNewUrl(u.getProtocol(), u.getUserInfo(), u.getHost(), newPort, u.getPath(), u.getRef(), u.getQuery()); }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified host. * @param u the URL on which to base the returned URL * @param newHost the new host to use in the returned URL * @return a new URL identical to the specified URL, except using the specified host * @throws MalformedURLException if there is a problem creating the new URL *///w ww .j a va2 s. co m public static URL getUrlWithNewHost(final URL u, final String newHost) throws MalformedURLException { return createNewUrl(u.getProtocol(), u.getUserInfo(), newHost, u.getPort(), u.getPath(), u.getRef(), u.getQuery()); }
From source file:org.mycore.common.xml.MCRXMLFunctions.java
/** * Encodes the given URL so, that it is a valid RFC 2396 URL. */// w w w. j ava 2s .co m public static String normalizeAbsoluteURL(String url) throws MalformedURLException, URISyntaxException { try { return new URI(url).toASCIIString(); } catch (Exception e) { URL testURL = new URL(url); URI uri = new URI(testURL.getProtocol(), testURL.getUserInfo(), testURL.getHost(), testURL.getPort(), testURL.getPath(), testURL.getQuery(), testURL.getRef()); return uri.toASCIIString(); } }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Creates and returns a new URL identical to the specified URL, except using the specified host. * @param u the URL on which to base the returned URL * @param newHost the new host to use in the returned URL * @param newPort the new port to use in the returned URL * @return a new URL identical to the specified URL, except using the specified host * @throws MalformedURLException if there is a problem creating the new URL *///w w w . j ava 2 s .c o m public static URL getUrlWithNewHostAndPort(final URL u, final String newHost, final int newPort) throws MalformedURLException { return createNewUrl(u.getProtocol(), u.getUserInfo(), newHost, newPort, u.getPath(), u.getRef(), u.getQuery()); }
From source file:eionet.cr.util.URLUtil.java
/** * * @param urlString/* w w w .jav a2s . co m*/ * @return */ public static String normalizeUrl(String urlString) { // if given URL string is null, return it as it is if (urlString == null) { return urlString; } // we're going to need both the URL and URI wrappers URL url = null; URI uri = null; try { url = new URL(urlString.trim()); uri = url.toURI(); } catch (MalformedURLException e) { return urlString; } catch (URISyntaxException e) { return urlString; } // get all the various parts of this URL String protocol = url.getProtocol(); String userInfo = url.getUserInfo(); String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); String reference = url.getRef(); // start building the result, processing each of the above-found URL parts StringBuilder result = new StringBuilder(); try { if (!StringUtils.isEmpty(protocol)) { result.append(decodeEncode(protocol.toLowerCase())).append("://"); } if (!StringUtils.isEmpty(userInfo)) { result.append(decodeEncode(userInfo, ":")).append("@"); } if (!StringUtils.isEmpty(host)) { result.append(decodeEncode(host.toLowerCase())); } if (port != -1 && port != 80) { result.append(":").append(port); } if (!StringUtils.isEmpty(path)) { result.append(normalizePath(path)); } if (!StringUtils.isEmpty(query)) { String normalizedQuery = normalizeQueryString(uri); if (!StringUtils.isBlank(normalizedQuery)) { result.append("?").append(normalizedQuery); } } if (!StringUtils.isEmpty(reference)) { result.append("#").append(decodeEncode(reference)); } } catch (UnsupportedEncodingException e) { throw new CRRuntimeException("Unsupported encoding: " + e.getMessage(), e); } return result.toString(); }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.JarURLStreamHandler.java
protected String toExternalForm(URL u) { return URL_PREFIX + u.getPath() + SEPARATOR + u.getRef(); }