Example usage for java.net URI toASCIIString

List of usage examples for java.net URI toASCIIString

Introduction

In this page you can find the example usage for java.net URI toASCIIString.

Prototype

public String toASCIIString() 

Source Link

Document

Returns the content of this URI as a US-ASCII string.

Usage

From source file:nl.knaw.dans.easy.sword2examples.Common.java

public static void setBagIsVersionOf(File bagDir, URI versionOfUri) throws Exception {
    Bag bag = bagFactory.createBag(bagDir);
    BagInfoTxt info = bag.getBagInfoTxt();
    info.put("Is-Version-Of", versionOfUri.toASCIIString());

    // bag-info.txt's checksums have changed, so we need to update the tag manifests.
    TagManifestCompleter completer = new TagManifestCompleter(bagFactory);
    completer.complete(bag);//  www.ja  v a  2  s  .  c  o m
    FileSystemWriter writer = new FileSystemWriter(bagFactory);
    writer.setTagFilesOnly(true);
    bag.write(writer, bagDir);
}

From source file:org.apache.olingo.ext.proxy.utils.ProxyUtils.java

public static Object getComplexProxy(final AbstractService<?> service, final String name,
        final ClientValue value, final Class<?> ref, final EntityInvocationHandler handler, final URI baseURI,
        final boolean collectionItem) {

    final URIBuilder targetURI;
    if (collectionItem) {
        targetURI = null;//from   w  w  w.  j av a 2  s.co  m
    } else {
        targetURI = baseURI == null ? null
                : service.getClient().newURIBuilder(baseURI.toASCIIString()).appendPropertySegment(name);
    }

    final ComplexInvocationHandler complexHandler;
    Class<?> actualRef = ref;
    if (value == null) {
        complexHandler = ComplexInvocationHandler.getInstance(actualRef, service, targetURI);
    } else {
        actualRef = CoreUtils.getComplexTypeRef(service, value); // handle derived types
        complexHandler = ComplexInvocationHandler.getInstance(value.asComplex(), actualRef, service, targetURI);
    }

    complexHandler.setEntityHandler(handler);

    return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { actualRef },
            complexHandler);
}

From source file:com.msopentech.odatajclient.engine.utils.URIUtils.java

/**
 * Build URI starting from the given base and href.
 * <br/>//  w w w  .  j ava 2 s .c  o m
 * If href is absolute or base is null then base will be ignored.
 *
 * @param base URI prefix.
 * @param href URI suffix.
 * @return built URI.
 */
public static URI getURI(final URI base, final String href) {
    if (href == null) {
        throw new IllegalArgumentException("Null link provided");
    }

    URI uri = URI.create(href);

    if (!uri.isAbsolute() && base != null) {
        uri = URI.create(base.toASCIIString() + "/" + href);
    }

    return uri.normalize();
}

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

private static URI followRedirectsInternal(URI url, int maxRedirections) {
    URI response = url;//  w  w  w.  j a  v  a2  s. c  o  m
    HttpClient client = new HttpClient();
    DefaultHttpMethodRetryHandler handler = new DefaultHttpMethodRetryHandler(1, false);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, handler);
    HttpMethod method = new HeadMethod(url.toASCIIString());
    //method.setRequestHeader("Accept-Language", locale.getLanguage() + ",en");
    method.setFollowRedirects(false);
    try {
        int statusCode = client.executeMethod(method);
        if ((statusCode == HttpStatus.SC_MOVED_PERMANENTLY) | (statusCode == HttpStatus.SC_MOVED_TEMPORARILY)) {
            if (maxRedirections > 0) {
                Header location = method.getResponseHeader("Location");
                if (!location.getValue().equals("")) {
                    // recursively check URL until it's not redirected any more
                    // locations can be relative to previous URL
                    URI target = url.resolve(location.getValue());
                    response = followRedirectsInternal(target, maxRedirections - 1);
                }
            }
        }
    } catch (Exception e) {
        //HttpClient can also throw IllegalArgumentException when URLs are malformed
    }
    return response;
}

From source file:org.eclipse.ecr.common.utils.URIUtils.java

public static String quoteURIPathComponent(String s, boolean quoteSlash) {
    if ("".equals(s)) {
        return s;
    }//  ww w . ja  v a  2s.c om
    URI uri;
    try {
        // fake scheme so that a colon is not mistaken as a scheme
        uri = new URI("x", s, null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Illegal characters in: " + s, e);
    }
    String r = uri.toASCIIString().substring(2);
    // replace reserved characters ;:$&+=?/[]@
    // FIXME: find a better way to do this...
    r = r.replace(";", "%3B");
    r = r.replace(":", "%3A");
    r = r.replace("$", "%24");
    r = r.replace("&", "%26");
    r = r.replace("+", "%2B");
    r = r.replace("=", "%3D");
    r = r.replace("?", "%3F");
    r = r.replace("[", "%5B");
    r = r.replace("]", "%5D");
    r = r.replace("@", "%40");
    if (quoteSlash) {
        r = r.replace("/", "%2F");
    }
    return r;
}

From source file:org.codice.ddf.catalog.content.monitor.DavEntry.java

static String getLocation(String initialLocation, DavEntry parent) {
    String location = initialLocation;
    if (parent != null && !location.startsWith(HTTP)) {
        String parentLocation = parent.getLocation();
        if (parentLocation.endsWith(FORSLASH) && location.startsWith(FORSLASH)) {
            location = location.replaceFirst(FORSLASH, "");
        }//from  w  w  w  .  j av  a2s.  c  o  m
        if (!parentLocation.endsWith(FORSLASH) && !location.startsWith(FORSLASH)) {
            location = FORSLASH + location;
        }
        location = parentLocation + location;
    }
    try {
        // URL class performs structural decomposition of location for us
        // URI class performs character encoding, but ONLY via multipart constructors
        // Finally, we have a fully qualified and escaped location for future manipulation
        URL url = new URL(location);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        location = uri.toASCIIString();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return location;
}

From source file:com.karma.konnect.BeaconConfigFragment.java

/**
 * Check if the given URL only uses characters from the set defined in RFC 3986 section 2
 * https://tools.ietf.org/html/rfc3986#section-2
 * @param url URL to check/*from  ww w.  j av  a 2s .  c  om*/
 * @return True if the URL is RFC 3986 compliant
 */
private static boolean isAsciiUrl(String url) {
    boolean isCompliant = false;
    try {
        URI uri = new URI(url);
        String urlString = uri.toASCIIString();
        isCompliant = url.equals(urlString);
    } catch (URISyntaxException e) {
        // bad url
    }
    return isCompliant;
}

From source file:org.nuxeo.common.utils.URIUtils.java

/**
 * Quotes a URI path component, with ability to quote "/" and "@"
 * characters or not depending on the URI path
 *
 * @since 5.6/*from  w w  w  .j ava 2s.  c om*/
 * @param the uri path to quote
 * @param quoteSlash true if "/" character should be quoted
 * @param quoteAt true if "@" character should be quoted
 */
public static String quoteURIPathComponent(String s, boolean quoteSlash, boolean quoteAt) {
    if ("".equals(s)) {
        return s;
    }
    URI uri;
    try {
        // fake scheme so that a colon is not mistaken as a scheme
        uri = new URI("x", s, null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Illegal characters in: " + s, e);
    }
    String r = uri.toASCIIString().substring(2);
    // replace reserved characters ;:$&+=?/[]@
    // FIXME: find a better way to do this...
    r = r.replace(";", "%3B");
    r = r.replace(":", "%3A");
    r = r.replace("$", "%24");
    r = r.replace("&", "%26");
    r = r.replace("+", "%2B");
    r = r.replace("=", "%3D");
    r = r.replace("?", "%3F");
    r = r.replace("[", "%5B");
    r = r.replace("]", "%5D");
    if (quoteAt) {
        r = r.replace("@", "%40");
    }
    if (quoteSlash) {
        r = r.replace("/", "%2F");
    }
    return r;
}

From source file:com.seajas.search.utilities.web.WebFeeds.java

private static void ensureResourceIdentification(SyndEntry entry, SyndFeed feed) throws FeedException {
    try {/*from ww  w.  j  a  v  a 2 s.c o m*/
        String uri = entry.getLink();
        if (!StringUtils.hasText(uri))
            uri = entry.getUri();

        boolean generated = false;
        if (!StringUtils.hasText(uri)) {
            logger.debug("Entry has no resource identification");
            int position = feed.getEntries().indexOf(entry);
            if (position < 0)
                uri = "#hash-" + entry.hashCode();
            else
                uri = "#entry-" + position;
            generated = true;
        }

        URI parsed = WebResourceLocators.parseURI(uri, feed.getLink(), feed.getUri());
        if (!parsed.isAbsolute()) {
            if (generated)
                throw new FeedException("No resource identification available");
            else
                throw new FeedException("Relative resource: " + parsed);
        }
        uri = parsed.toASCIIString();

        entry.setLink(uri);
        if (!StringUtils.hasText(entry.getUri()))
            entry.setUri(uri);
    } catch (URISyntaxException e) {
        throw new FeedException("Can't resolve resource", e);
    }
}

From source file:com.amazonaws.client.regions.RegionUtils.java

/**
 * Loads a set of region metadata by downloading an XML file from the
 * given URI and parsing it.// ww w.  j a  v a 2 s  . com
 *
 * @param uri the uri of the XML file to parse
 * @throws AmazonClientException on error
 */
public static synchronized void initializeFromURI(final URI uri) {
    doInitializeFromURI(uri, null);
    source = uri.toASCIIString();
}