Example usage for java.net URL getRef

List of usage examples for java.net URL getRef

Introduction

In this page you can find the example usage for java.net URL getRef.

Prototype

public String getRef() 

Source Link

Document

Gets the anchor (also known as the "reference") of this URL .

Usage

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static URI newEncodedURI(String u) throws MalformedURLException, URISyntaxException {
    URL tmpUrl = new URL(u);
    return new URI(tmpUrl.getProtocol(), tmpUrl.getUserInfo(), tmpUrl.getHost(), tmpUrl.getPort(),
            tmpUrl.getPath(), tmpUrl.getQuery(), tmpUrl.getRef());
}

From source file:com.ibm.jaggr.core.util.PathUtil.java

/**
 * Convenience method to convert a URL to a URI that doesn't throw a
 * URISyntaxException if the path component for the URL contains
 * spaces (like {@link URL#toURI()} does).
 *
 * @param url The input URL/*from   ww w  .ja v  a 2 s  . c o  m*/
 * @return The URI
 * @throws URISyntaxException
 */
public static URI url2uri(URL url) throws URISyntaxException {
    return new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef());
}

From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java

/**
 * Sanitizes the given URL by escaping the path and query parameters, if necessary.
 * @see "http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java"
 * @param url//from  ww w . j  a  v a2 s  . co  m
 * @return
 * @throws URISyntaxException
 * @throws MalformedURLException
 */
public static String sanitize(String url) throws URISyntaxException, MalformedURLException {
    URL temp = new URL(url);
    URI uri = new URI(temp.getProtocol(), temp.getUserInfo(), temp.getHost(), temp.getPort(), temp.getPath(),
            temp.getQuery(), temp.getRef());
    return uri.toASCIIString();
}

From source file:SageCollegeProject.guideBox.java

public static String GetEncWebCall(String webcall) {
    try {/*  ww w .j  ava 2s .  c om*/
        URL url = new URL(webcall);
        URI test = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        return test.toASCIIString();
    } catch (URISyntaxException | MalformedURLException ex) {
        Logger.getLogger(guideBox.class.getName()).log(Level.SEVERE, null, ex);
    }
    return "";
}

From source file:illab.nabal.util.ParameterHelper.java

/**
 * Parse a URL query and fragment parameters into a key-value bundle.
 * //from  w w  w.  j a  va2  s  . c o  m
 * @param url - the URL to parse
 * @return bundle - a dictionary bundle of keys and values
 */
public static Bundle parseGetParams(String url) {

    // prepare a bundle
    Bundle bundle = null;
    try {
        URL u = new URL(url);
        bundle = decodeGetParams(u.getQuery());
        bundle.putAll(decodeGetParams(u.getRef()));
    } catch (MalformedURLException e) {
        Log.e(TAG, "malformed URL");
        Log.e(TAG, e.getMessage());
    }
    return bundle;
}

From source file:org.apache.maven.wagon.shared.http.EncodingUtil.java

/**
 * Parses and returns an encoded version of the given URL string.
 *
 * @param url Raw/decoded string form of a URL to parse/encode.
 * @return Parsed/encoded {@link URI} that represents the string form URL passed in.
 * @throws MalformedURLException//from  ww w  .  j  a va2 s.  co  m
 * @throws URISyntaxException
 */
public static URI encodeURL(String url) throws MalformedURLException, URISyntaxException {
    URL urlObject = new URL(url);

    URI uriEncoded = new URI(urlObject.getProtocol(), //
            urlObject.getAuthority(), //
            urlObject.getPath(), //
            urlObject.getQuery(), //
            urlObject.getRef());

    return uriEncoded;
}

From source file:org.eclipse.skalli.commons.URLUtils.java

/**
 * Converts a given string into a corresponding URL.
 * <p>//from  w ww. j  a  va 2s.  c o m
 * Encodes path and/or query parts of the given string according to
 * {@link URI#URI(String, String, String, int, String, String, String)}.
 * For example, blanks in the path are converted to <tt>%20</tt>.
 *
 * @param s  the string to convert to an URL.
 * @return  an URL, or <code>null</code> if the string is <code>null</code>, empty or whitespace.
 *
 * @throws MalformedURLException  if the given string is not a valid URL and cannot be
 * "sanitized" to yield a valid URL even after proper encoding of its parts.
 */
public static URL stringToURL(String s) throws MalformedURLException {
    if (StringUtils.isBlank(s)) {
        return null;
    }
    URI uri = null;
    try {
        uri = new URI(s);
    } catch (URISyntaxException e) {
        URL url = new URL(s);
        try {
            uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                    url.getQuery(), url.getRef());
        } catch (URISyntaxException e1) {
            MalformedURLException e2 = new MalformedURLException(e1.getMessage());
            e2.initCause(e1);
            throw e2;
        }
    }
    return new URL(uri.toASCIIString());
}

From source file:org.motechproject.mmnaija.web.util.HTTPCommunicator.java

public static String doGet(String urlStr) {
    URLConnection connection = null;
    try {// ww w  .  j  a v  a  2s .  c  o m
        URL url = new URL(urlStr);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();

        // Open the connection
        connection = url.openConnection();
    } catch (Exception e) {
    }

    try {
        InputStream in = connection.getInputStream();

        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer, "utf-8");
        String theString = writer.toString();
        return theString;
    } catch (Exception e) {
    }
    return "";
}

From source file:org.talend.commons.utils.network.NetworkUtil.java

/**
 * encode url//from   w  w  w .j  av a2s .  co  m
 * 
 * @param urlStr url not encoded yet!
 * @return
 * @throws Exception
 */
public static URL encodeUrl(String urlStr) throws Exception {
    try {
        // String decodedURL = URLDecoder.decode(urlStr, "UTF-8"); //$NON-NLS-1$
        URL url = new URL(urlStr);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        return uri.toURL();
    } catch (Exception e) {
        throw e;
    }
}

From source file:de.fhg.iais.asc.xslt.binaries.download.Downloader.java

private static URI createURI(URL url) throws URISyntaxException {
    return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
}