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:com.microsoft.tfs.core.util.URIUtils.java

/**
 * Returns a {@link URI} string for display to the user, decoding escaped
 * ASCII characters into Unicode. If the decoding fails (invalid escaped
 * characters?) the URI's toString() value is returned instead.
 *
 * @param uri//from w ww  .ja  va 2 s.  c  om
 *        the URI to get the display string for (must not be
 *        <code>null</code>)
 * @return the decoded URI string
 */
public static String decodeForDisplay(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    try {
        return URIUtil.decode(uri.toASCIIString());
    } catch (final URIException e) {
        log.warn(MessageFormat.format("Couldn''t decode URI [{0}] display string, returning raw instead", //$NON-NLS-1$
                uri.toASCIIString()), e);

        return uri.toString();
    }
}

From source file:com.msopentech.odatajclient.engine.data.ODataBinder.java

/**
 * Gets an <tt>EntryResource</tt> from the given OData entity.
 *
 * @param <T> entry resource type.
 * @param entity OData entity./*from w w  w  .  j  av  a2 s .co  m*/
 * @param reference reference class.
 * @param setType whether to explicitly output type information.
 * @return <tt>EntryResource</tt> object.
 */
@SuppressWarnings("unchecked")
public static <T extends EntryResource> T getEntry(final ODataEntity entity, final Class<T> reference,
        final boolean setType) {

    final T entry = ResourceFactory.newEntry(reference);
    entry.setType(entity.getName());

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI editLink = entity.getEditLink();
    if (editLink != null) {
        final LinkResource entryEditLink = ResourceFactory.newLinkForEntry(reference);
        entryEditLink.setTitle(entity.getName());
        entryEditLink.setHref(editLink.toASCIIString());
        entryEditLink.setRel(ODataConstants.EDIT_LINK_REL);
        entry.setEditLink(entryEditLink);
    }

    if (entity.isReadOnly()) {
        final LinkResource entrySelfLink = ResourceFactory.newLinkForEntry(reference);
        entrySelfLink.setTitle(entity.getName());
        entrySelfLink.setHref(entity.getLink().toASCIIString());
        entrySelfLink.setRel(ODataConstants.SELF_LINK_REL);
        entry.setSelfLink(entrySelfLink);
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append navigation links (handling inline entry / feed as well)
    // -------------------------------------------------------------
    // handle navigation links
    for (ODataLink link : entity.getNavigationLinks()) {
        // append link 
        LOG.debug("Append navigation link\n{}", link);
        entry.addNavigationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getEditMediaLinks()) {
        LOG.debug("Append edit-media link\n{}", link);
        entry.addMediaEditLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append association links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getAssociationLinks()) {
        LOG.debug("Append association link\n{}", link);
        entry.addAssociationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    final Element content = newEntryContent();
    if (entity.isMediaEntity()) {
        entry.setMediaEntryProperties(content);
        entry.setMediaContentSource(entity.getMediaContentSource());
        entry.setMediaContentType(entity.getMediaContentType());
    } else {
        entry.setContent(content);
    }

    for (ODataProperty prop : entity.getProperties()) {
        content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType));
    }

    return entry;
}

From source file:org.rssowl.core.util.URIUtils.java

private static String getFile(URI uri) {
    String file = uri.getPath();/*ww w . j  a  va2  s.  c om*/
    if (StringUtils.isSet(file)) {
        String parts[] = file.split("/"); //$NON-NLS-1$
        if (parts.length > 0 && StringUtils.isSet(parts[parts.length - 1]))
            return urlDecode(parts[parts.length - 1]);
    }
    return uri.toASCIIString();
}

From source file:org.seedstack.seed.ws.internal.jms.SoapJmsUri.java

static SoapJmsUri parse(URI uri) {
    if (!"jms".equals(uri.getScheme())) {
        throw new IllegalArgumentException("Not a valid SOAP JMS URI " + uri.toString());
    }// w w w .  ja v a2s  .c  o m

    String ssp = uri.getSchemeSpecificPart();
    String[] splitSsp = ssp.split(":", 2);

    if (splitSsp.length != 2) {
        throw new IllegalArgumentException("Invalid SOAP JMS URI " + splitSsp[0]);
    }

    String[] splitSecondPart = splitSsp[1].split("\\?", 2);

    if (splitSecondPart.length != 2) {
        throw new IllegalArgumentException("Invalid SOAP JMS URI " + splitSsp[1]);
    }

    return new SoapJmsUri(splitSsp[0], splitSecondPart[0], parseUrlQueryString(splitSecondPart[1]),
            uri.toASCIIString());
}

From source file:org.mycore.common.xml.MCRXMLFunctions.java

/**
 * Encodes the path so that it can be safely used in an URI.
 * @param asciiOnly//  ww  w .ja  v a 2 s.c  o  m
 *          if true, return only ASCII characters (e.g. encode umlauts)
 * @return encoded path as described in RFC 2396
 */
public static String encodeURIPath(String path, boolean asciiOnly) throws URISyntaxException {
    URI relativeURI = new URI(null, null, path, null, null);
    return asciiOnly ? relativeURI.toASCIIString() : relativeURI.getRawPath();
}

From source file:fr.eolya.utils.http.HttpUtils.java

/**
 * Encode url// w ww . j a v a2s. c o m
 * 
 * @param url url to be encoded
 * @return 
 */
public static String urlEncode(String url) {
    try {
        URL u = new URL(url);
        String host = u.getHost();
        int indexFile = url.indexOf("/", url.indexOf(host));
        if (indexFile == -1)
            return url;

        String urlFile = u.getFile();
        urlFile = URLDecoder.decode(urlFile, "UTF-8");

        String protocol = u.getProtocol();
        int port = u.getPort();
        if (port != -1 && port != 80 && "http".equals(protocol))
            host += ":".concat(String.valueOf(port));
        if (port != -1 && port != 443 && "https".equals(protocol))
            host += ":".concat(String.valueOf(port));

        URI uri = new URI(u.getProtocol(), host, urlFile, null);
        String ret = uri.toASCIIString();
        ret = ret.replaceAll("%3F", "?");
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:cn.edu.seu.herald.ws.api.impl.RequestGetMethodFactoryImpl.java

@Override
public GetMethod newXmlRequestGetMethod(URI uri) {
    GetMethod getMethod = new GetMethod(uri.toASCIIString());
    getMethod.setRequestHeader(HTTP_HEADER_ACCEPT, MEDIA_TYPE_APPLICATION_XML);
    return getMethod;
}

From source file:cn.edu.seu.herald.ws.api.impl.RequestGetMethodFactoryImpl.java

@Override
public GetMethod newCsvRequestGetMethod(URI uri) {
    GetMethod getMethod = new GetMethod(uri.toASCIIString());
    getMethod.setRequestHeader(HTTP_HEADER_ACCEPT, MEDIA_TYPE_TEXT_CSV);
    return getMethod;
}

From source file:cn.edu.seu.herald.ws.api.impl.RequestGetMethodFactoryImpl.java

@Override
public GetMethod newPlainTextRequestMethod(URI uri) {
    GetMethod getMethod = new GetMethod(uri.toASCIIString());
    getMethod.setRequestHeader(HTTP_HEADER_ACCEPT, MEDIA_TYPE_TEXT_PLAIN);
    return getMethod;
}

From source file:com.jaeksoft.searchlib.remote.UriRead.java

public UriRead(URI uri) throws HttpException, IOException {
    HttpGet httpGet = new HttpGet(uri.toASCIIString());
    httpGet.setConfig(requestConfig);/*w w w .java 2  s  .  co m*/
    httpGet.addHeader("Connection", "close");
    execute(httpGet);
}