Example usage for java.net URI getQuery

List of usage examples for java.net URI getQuery

Introduction

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

Prototype

public String getQuery() 

Source Link

Document

Returns the decoded query component of this URI.

Usage

From source file:Main.java

public static void main(String[] args) {
    URI uri = URI.create("http://java2s.com/query.php?name=value");
    System.out.println(uri.getQuery());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    URI u = new URI("http://www.java2s.com");
    System.out.println("The URI is " + u);
    if (u.isOpaque()) {
        System.out.println("This is an opaque URI.");
        System.out.println("The scheme is " + u.getScheme());
        System.out.println("The scheme specific part is " + u.getSchemeSpecificPart());
        System.out.println("The fragment ID is " + u.getFragment());
    } else {/*  ww w  .  ja  v  a 2 s.c om*/
        System.out.println("This is a hierarchical URI.");
        System.out.println("The scheme is " + u.getScheme());

        u = u.parseServerAuthority();
        System.out.println("The host is " + u.getUserInfo());
        System.out.println("The user info is " + u.getUserInfo());
        System.out.println("The port is " + u.getPort());
        System.out.println("The path is " + u.getPath());
        System.out.println("The query string is " + u.getQuery());
        System.out.println("The fragment ID is " + u.getFragment());
    }

}

From source file:wzw.util.DbUtils.java

public static void main(String[] args) throws URISyntaxException {
    java.net.URI u = new java.net.URI("");
    u.getQuery();
    System.out.println(DbUtils.escape2Sql(null, "a'b'c"));

}

From source file:com.github.walterfan.util.http.URLHelper.java

/**
 * Parsers the query string of the URI into a map of key-value pairs
 *///from  ww w .j  a  v a2  s.  c  o m
public static Map<String, String> parseQuery(URI uri) {
    return parseQuery(uri.getQuery());
}

From source file:NioHttpClient.java

public static String uriForRequest(URI u) {
    if (null == u.getQuery()) {
        return u.getPath();
    } else {//from  w  w w  . j ava2s.c  o  m
        int n = u.getPath().length() + u.getQuery().length() + 1;
        StringBuilder b = new StringBuilder(n);
        b.append(u.getPath()).append('?').append(u.getQuery());
        return b.toString();
    }
}

From source file:com.gsma.mobileconnect.utils.HttpUtils.java

/**
 * Extract the parameters from the passed URL.
 *
 * @param url The URL to extract the parameters from.
 * @return The list of parameters, as a list of NameValuePairs.
 * @throws URISyntaxException//from  w  ww .  j a v  a 2  s.c o  m
 */
public static List<NameValuePair> extractParameters(String url) throws URISyntaxException {
    if (StringUtils.isNullOrEmpty(url)) {
        return new ArrayList<NameValuePair>(0);
    }
    URI uri = new URI(url);
    return URLEncodedUtils.parse(uri.getQuery(), null);
}

From source file:de.ii.xtraplatform.feature.provider.wfs.FeatureProviderDataWfsFromMetadata.java

static URI parseAndCleanWfsUrl(URI inUri) throws URISyntaxException {
    URIBuilder outUri = new URIBuilder(inUri).removeQuery();

    if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) {
        for (String inParam : inUri.getQuery().split("&")) {
            String[] param = inParam.split("=");
            if (!WFS.hasKVPKey(param[0].toUpperCase())) {
                outUri.addParameter(param[0], param[1]);
            }/*w w w .  j  a  v  a  2  s. co m*/
        }
    }

    return outUri.build();
}

From source file:at.bitfire.davdroid.URIUtils.java

/**
 * Parse a received absolute/relative URL and generate a normalized URI that can be compared.
 * @param original       URI to be parsed, may be absolute or relative
  * @param mustBePath    true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
 * @return             normalized URI// www.  ja  v a 2s.c  o  m
 * @throws URISyntaxException
 */
public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException {
    if (mustBePath) {
        // may contain ":"
        // case 1: "my:file"        won't be parsed by URI correctly because it would consider "my" as URI scheme
        // case 2: "path/my:file"   will be parsed by URI correctly
        // case 3: "my:path/file"   won't be parsed by URI correctly because it would consider "my" as URI scheme
        int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':');
        if (idxColon != -1) {
            // colon present
            if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon  everything OK
                ;
            else // No slash before the colon; we have to put it there
                original = "./" + original;
        }
    }

    // escape some common invalid characters  servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf"
    // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name)
    String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    if (!repaired.equals(original))
        Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired);

    URI uri = new URI(repaired);
    URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
            uri.getFragment());
    Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
    return normalized;
}

From source file:io.gravitee.gateway.standalone.DynamicRoutingGatewayTest.java

private static URI create(URI uri, int port) {
    try {/*from  www  .j  ava 2  s . c om*/
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port, uri.getPath(), uri.getQuery(),
                uri.getFragment());
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:de.mpg.imeji.presentation.util.SearchAndExportHelper.java

public static String getCitation(Publication publication) {
    URI uri = publication.getUri();
    URI searchAndExportUri = URI.create("http://" + uri.getHost() + "/search/SearchAndExport");
    String itemId = null;// w w w  .  ja v a2  s . c  o  m
    if (uri.getQuery() != null && uri.getQuery().contains("itemId=")) {
        itemId = uri.getQuery().split("itemId=")[1];
    } else if (uri.getPath() != null && uri.getPath().contains("/item/")) {
        itemId = uri.getPath().split("/item/")[1];
    }
    if (UrlHelper.isValidURI(searchAndExportUri)) {
        try {
            HttpClient client = new HttpClient();
            String exportUri = searchAndExportUri.toString() + "?cqlQuery=" + URLEncoder.encode(
                    "escidoc.objid=" + itemId + " or escidoc.property.version.objid=" + itemId, "ISO-8859-1")
                    + "&exportFormat=" + publication.getExportFormat() + "&outputFormat=html_linked";
            GetMethod method = new GetMethod(exportUri);
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}