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:org.emergent.android.weave.client.WeaveMain.java

public static void doPut(String nodepath) throws Exception {
    String userEmail = getUserEmail();
    UserWeave weave = smWeaveFactory.createUserWeave(URI.create(getServerUrl()), userEmail, getPassword());
    BulkKeyCouplet bulkKeyPair = getBulKKeyPair(weave);

    String sendBody = WeaveUtil.readToString(System.in);

    String respBody;//from  ww w . j  av a 2 s .c  o  m
    if (nodepath != null) {
        URI uri = weave.buildSyncUriFromSubpath(nodepath);
        System.err.println("PUTURI: " + uri.toASCIIString());

        if (nodepath.startsWith("/storage/crypto/keys")) {
            throw new Exception("You don't want this");
        }

        WeaveResponse response = weave.putNode(uri, sendBody);
        respBody = response.getBody();
    } else {
        respBody = sendBody;
    }

    System.err.println("RESPONSE:");
    System.out.println(respBody);
}

From source file:org.osaf.cosmo.dav.caldav.report.MultigetReport.java

private static URL normalizeHref(URL context, String href) throws DavException {
    URL url = null;//from w w  w  .  ja va  2s .  com
    try {
        url = new URL(context, href);
        // check that the URL is escaped. it's questionable whether or
        // not we should all unescaped URLs, but at least as of
        // 10/02/2007, iCal 3.0 generates them
        url.toURI();
        return url;
    } catch (URISyntaxException e) {
        try {
            URI escaped = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                    url.getRef());
            return new URL(escaped.toASCIIString());
        } catch (Exception e2) {
            throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new BadRequestException("Malformed href " + href + ": " + e.getMessage());
    }
}

From source file:org.apache.olingo.ext.proxy.commons.EntitySetInvocationHandler.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static EntitySetInvocationHandler getInstance(final Class<?> ref, final AbstractService<?> service,
        final URI uri) {
    return new EntitySetInvocationHandler(ref, service, service.getClient().newURIBuilder(uri.toASCIIString()));
}

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

/**
 * Build URI starting from the given base and href.
 * <br/>/*from  ww  w. ja  v a  2  s  . com*/
 * 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 URI href) {
    if (href == null) {
        throw new IllegalArgumentException("Null link provided");
    }
    return getURI(base, href.toASCIIString());
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static String toFileURI(File file) {
    URI uri = file.toURI();
    String uriString = uri.toASCIIString();
    return uriString.replaceAll("^file:/", "file:///");
}

From source file:net.tirasa.blog.ilgrosso.syncopecustompolicyrules.sample.App.java

private static <T> T getObject(final URI location, final Class<?> serviceClass, final Class<T> resultClass) {
    WebClient webClient = WebClient.fromClient(WebClient.client(client.getService(serviceClass)));
    webClient.accept(clientFactory.getContentType().getMediaType()).to(location.toASCIIString(), false);

    return webClient.get(resultClass);
}

From source file:org.emergent.android.weave.client.WeaveMain.java

public static void retrieveAndDump(String nodepath) throws Exception {
    String userEmail = getUserEmail();
    UserWeave weave = smWeaveFactory.createUserWeave(URI.create(getServerUrl()), userEmail, getPassword());
    BulkKeyCouplet bulkKeyPair = getBulKKeyPair(weave);

    String respBody;// www.  j a v a  2  s  . com
    if (nodepath != null) {
        URI uri = weave.buildSyncUriFromSubpath(nodepath);
        System.err.println("GETURI: " + uri.toASCIIString());

        if (nodepath.startsWith("/storage/crypto/keys")) {
            dump(getCryptoKeys(weave));
            return;
        }

        WeaveResponse response = weave.getNode(uri);
        respBody = response.getBody();
    } else {
        respBody = WeaveUtil.readToString(System.in);
    }

    if (respBody.startsWith("[")) {
        System.err.println("JSONARR:");
        JSONArray jsonNewArray = new JSONArray();
        JSONArray jsonOldArray = new JSONArray(respBody);
        for (int ii = 0; ii < jsonOldArray.length(); ii++) {
            JSONObject jsonObj = jsonOldArray.optJSONObject(ii);
            if (jsonObj != null) {
                jsonObj = safeSwapForCiphered(jsonObj, bulkKeyPair);
                jsonNewArray.put(jsonObj);
            } else {
                System.err.println("WARNING array element " + ii + " was not a JSONObject");
            }
        }
        dump(jsonNewArray);
    } else if (respBody.startsWith("{")) {
        System.err.println("JSONOBJ:");
        JSONObject jsonObj = new JSONObject(respBody);
        jsonObj = safeSwapForCiphered(jsonObj, bulkKeyPair);
        dump(jsonObj);
    } else {
        System.err.println("NONJSON:");
        System.out.println(respBody);
    }
}

From source file:org.apache.olingo.client.core.serialization.ContextURLParser.java

public static ContextURL parse(final URI contextURL) {
    if (contextURL == null) {
        return null;
    }/*from  w w  w .ja va  2  s. co  m*/

    final ContextURL.Builder contextUrl = ContextURL.with();

    String contextURLasString = contextURL.toASCIIString();

    boolean isEntity = false;
    if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) {
        isEntity = true;
        contextUrl.suffix(Suffix.ENTITY);
        contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY).replace("/@Element",
                StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$ref")) {
        contextUrl.suffix(Suffix.REFERENCE);
        contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$delta")) {
        contextUrl.suffix(Suffix.DELTA);
        contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedEntity")) {
        contextUrl.suffix(Suffix.DELTA_DELETED_ENTITY);
        contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$link")) {
        contextUrl.suffix(Suffix.DELTA_LINK);
        contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedLink")) {
        contextUrl.suffix(Suffix.DELTA_DELETED_LINK);
        contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY);
    }

    contextUrl.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA)));

    final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");

    String firstToken;
    String entitySetOrSingletonOrType;
    if (rest.startsWith("Collection(")) {
        firstToken = rest.substring(0, rest.indexOf(')') + 1);
        entitySetOrSingletonOrType = firstToken;
    } else {
        final int openParIdx = rest.indexOf('(');
        if (openParIdx == -1) {
            firstToken = StringUtils.substringBeforeLast(rest, "/");

            entitySetOrSingletonOrType = firstToken;
        } else {
            firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")";

            final List<String> parts = new ArrayList<String>();
            for (String split : firstToken.split("\\)/")) {
                parts.add(split.replaceAll("\\(.*", ""));
            }
            entitySetOrSingletonOrType = StringUtils.join(parts, '/');
            final int commaIdx = firstToken.indexOf(',');
            if (commaIdx != -1) {
                contextUrl.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1));
            }
        }
    }
    contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType);

    final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/');
    if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) {
        contextUrl.entitySetOrSingletonOrType(entitySetOrSingletonOrType.substring(0, slashIdx));
        contextUrl.derivedEntity(entitySetOrSingletonOrType.substring(slashIdx + 1));
    }

    if (!firstToken.equals(rest)) {
        final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/");
        if (pathElems.length > 0 && pathElems[0].length() > 0) {
            if (pathElems[0].indexOf('.') == -1) {
                contextUrl.navOrPropertyPath(pathElems[0]);
            } else {
                contextUrl.derivedEntity(pathElems[0]);
            }

            if (pathElems.length > 1) {
                contextUrl.navOrPropertyPath(pathElems[1]);
            }
        }
    }

    return contextUrl.build();
}

From source file:com.baidubce.util.HttpUtils.java

/**
 * Append the given path to the given baseUri.
 *
 * <p>/*  w  ww  . j a va2  s.c  o  m*/
 * This method will encode the given path but not the given baseUri.
 *
 * @param baseUri
 * @param pathComponents
 */
public static URI appendUri(URI baseUri, String... pathComponents) {
    StringBuilder builder = new StringBuilder(baseUri.toASCIIString());
    for (String path : pathComponents) {
        if (path != null && path.length() > 0) {
            path = normalizePath(path);
            if (path.startsWith("/")) {
                if (builder.charAt(builder.length() - 1) == '/') {
                    builder.setLength(builder.length() - 1);
                }
            } else {
                if (builder.charAt(builder.length() - 1) != '/') {
                    builder.append('/');
                }
            }
            builder.append(path);
        }
    }
    try {
        return new URI(builder.toString());
    } catch (URISyntaxException e) {
        throw new RuntimeException("Unexpected error", e);
    }
}

From source file:org.apache.olingo.commons.core.serialization.ContextURLParser.java

public static ContextURL parse(final URI contextURL) {
    if (contextURL == null) {
        return null;
    }//from   w  w  w  . j  av  a  2s .  c o  m

    final ContextURL.Builder builder = ContextURL.Builder.create();

    String contextURLasString = contextURL.toASCIIString();

    boolean isEntity = false;
    if (contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element")) {
        isEntity = true;
        builder.suffix(Suffix.ENTITY);
        contextURLasString = contextURLasString.replace("/$entity", StringUtils.EMPTY).replace("/@Element",
                StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$ref")) {
        builder.suffix(Suffix.REFERENCE);
        contextURLasString = contextURLasString.replace("/$ref", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$delta")) {
        builder.suffix(Suffix.DELTA);
        contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedEntity")) {
        builder.suffix(Suffix.DELTA_DELETED_ENTITY);
        contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$link")) {
        builder.suffix(Suffix.DELTA_LINK);
        contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY);
    } else if (contextURLasString.endsWith("/$deletedLink")) {
        builder.suffix(Suffix.DELTA_DELETED_LINK);
        contextURLasString = contextURLasString.replace("/$deletedLink", StringUtils.EMPTY);
    }

    builder.serviceRoot(URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA)));

    final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");

    String firstToken;
    String entitySetOrSingletonOrType = null;
    if (rest.startsWith("Collection(")) {
        firstToken = rest.substring(0, rest.indexOf(')') + 1);
        entitySetOrSingletonOrType = firstToken;
    } else {
        final int openParIdx = rest.indexOf('(');
        if (openParIdx == -1) {
            firstToken = StringUtils.substringBeforeLast(rest, "/");

            entitySetOrSingletonOrType = firstToken;
        } else {
            firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")";

            final List<String> parts = new ArrayList<String>();
            for (String split : firstToken.split("\\)/")) {
                parts.add(split.replaceAll("\\(.*", ""));
            }
            entitySetOrSingletonOrType = StringUtils.join(parts, '/');
            final int commaIdx = firstToken.indexOf(',');
            if (commaIdx != -1) {
                builder.selectList(firstToken.substring(openParIdx + 1, firstToken.length() - 1));
            }
        }
    }
    builder.entitySetOrSingletonOrType(entitySetOrSingletonOrType);

    final int slashIdx = entitySetOrSingletonOrType.lastIndexOf('/');
    if (slashIdx != -1 && entitySetOrSingletonOrType.substring(slashIdx + 1).indexOf('.') != -1) {
        final String clone = entitySetOrSingletonOrType;
        builder.entitySetOrSingletonOrType(clone.substring(0, slashIdx));
        builder.derivedEntity(clone.substring(slashIdx + 1));
    }

    if (!firstToken.equals(rest)) {
        final String[] pathElems = StringUtils.substringAfter(rest, "/").split("/");
        if (pathElems.length > 0 && pathElems[0].length() > 0) {
            if (pathElems[0].indexOf('.') == -1) {
                builder.navOrPropertyPath(pathElems[0]);
            } else {
                builder.derivedEntity(pathElems[0]);
            }

            if (pathElems.length > 1) {
                builder.navOrPropertyPath(pathElems[1]);
            }
        }
    }

    return builder.build();
}