當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.getQuery方法代碼示例

本文整理匯總了Java中java.net.URL.getQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.getQuery方法的具體用法?Java URL.getQuery怎麽用?Java URL.getQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: normalizeUrl

import java.net.URL; //導入方法依賴的package包/類
public static URL normalizeUrl(final URL url) throws MalformedURLException {
    String queryString = url.getQuery();
    if (null == queryString) {
        return url;
    }
    String original = url.toExternalForm();
    StringBuilder sb = new StringBuilder();
    String[] array = queryString.split("&");
    for (String str : array) {
        String[] pair = str.split("=");
        if (2 != pair.length) {
            throw new IllegalArgumentException("Parse failed: " + original);
        }
        try {
            sb.append(pair[0]).append("=");
            sb.append(URLEncoder.encode(pair[1], ENCODING));
            sb.append("&");
        } catch (UnsupportedEncodingException ex) {
            throw new IllegalArgumentException(ex);
        }
    }
    return new URL(original.replace(queryString, StringUtils.chop(sb
            .toString())));
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:25,代碼來源:URLUtils.java

示例2: encodeUrlToHttpFormat

import java.net.URL; //導入方法依賴的package包/類
public static String encodeUrlToHttpFormat(String urlString)
{
    String encodedUrl=null;
    try
    {
        URL url=new URL(urlString);
        URI uri= new URI(url.getProtocol(),url.getUserInfo(),url.getHost(),url.getPort(),url.getPath(),
                url.getQuery(),url.getRef());
        //System.out.println(uri.toURL().toString());
        encodedUrl=uri.toURL().toString();
    }
    catch (Exception exc)
    {
        return null;
    }
    return  encodedUrl;
}
 
開發者ID:gerard-bisama,項目名稱:DHIS2-fhir-lab-app,代碼行數:18,代碼來源:FhirMediatorUtilities.java

示例3: getPicturePathFromQuery

import java.net.URL; //導入方法依賴的package包/類
public static String getPicturePathFromQuery(URL url){
    String query = url.getQuery();
    String[] pairs = query.split("&");
    String ret = "";
    if(url.getQuery().contains(PICTURE_PATH_KEY)){
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            if(pair.substring(0, idx).equals(PICTURE_PATH_KEY)){
                try {
                    ret = URLDecoder.decode(pair.substring(idx + 1), "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    ret = "";
                }
                break;
            }
        }
    }
    return ret;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:UserData.java

示例4: getUrlWithQueryString

import java.net.URL; //導入方法依賴的package包/類
/**
 * Will encode url, if not disabled, and adds params on the end of it
 *
 * @param url             String with URL, should be valid URL without params
 * @param params          RequestParams to be appended on the end of URL
 * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20)
 * @return encoded url if requested with params appended if any available
 */
public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) {
    if (url == null)
        return null;

    if (shouldEncodeUrl) {
        try {
            String decodedURL = URLDecoder.decode(url, "UTF-8");
            URL _url = new URL(decodedURL);
            URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef());
            url = _uri.toASCIIString();
        } catch (Exception ex) {
            // Should not really happen, added just for sake of validity
            log.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex);
        }
    }

    if (params != null) {
        // Construct the query string and trim it, in case it
        // includes any excessive white spaces.
        String paramString = params.getParamString().trim();

        // Only add the query string if it isn't empty and it
        // isn't equal to '?'.
        if (!paramString.equals("") && !paramString.equals("?")) {
            url += url.contains("?") ? "&" : "?";
            url += paramString;
        }
    }

    return url;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:40,代碼來源:AsyncHttpClient.java

示例5: filterRequest

import java.net.URL; //導入方法依賴的package包/類
@Override
public HttpResponse filterRequest(HttpRequest httpRequest, HttpMessageContents httpMessageContents, HttpMessageInfo httpMessageInfo) {
    replayingState.addHttpRequestToQueue(httpMessageInfo.getOriginalRequest());
    replayingState.setHttpLock(false);

    for (ConditionsUpdater conditionsUpdater: conditionsUpdaters) {
        if (conditionsUpdater.shouldUpdate().test(httpRequest)) {
            try {
                URL url = new URL(httpRequest.getUri());
                String event = url.getQuery();
                conditionsUpdater.updater().update(replayingState, event);
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

    return null;
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:20,代碼來源:ReplayRequestFilter.java

示例6: queryMap

import java.net.URL; //導入方法依賴的package包/類
private static SortedMap<String, String> queryMap(URL url)  {
	SortedMap<String, String> map = new TreeMap<String, String>();
    String query = url.getQuery();
    if (query == null)
    	return map;
    String[] pairs = query.split("&");
    for (String pair : pairs) {
        int idx = pair.indexOf("=");
        if (idx < 0)
	        map.put(pair, "");
        else
             map.put(pair.substring(0, idx), pair.substring(idx + 1));
    }
    return map;
}
 
開發者ID:Nexenta,項目名稱:edgex-java-connector,代碼行數:16,代碼來源:S3Signature.java

示例7: getJsonURL

import java.net.URL; //導入方法依賴的package包/類
private URL getJsonURL(URL url) throws MalformedURLException {
    // Append ".json" to URL in appropriate location.
    String result = url.getProtocol() + "://" + url.getHost() + url.getPath() + ".json";
    if (url.getQuery() != null) {
        result += "?" + url.getQuery();
    }
    return new URL(result);
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:9,代碼來源:RedditRipper.java

示例8: toExternalForm

import java.net.URL; //導入方法依賴的package包/類
/**
 * Override as part of the fix for 36534, to ensure toString is correct.
 */
@Override
protected String toExternalForm(URL u) {
	// pre-compute length of StringBuilder
	int len = u.getProtocol().length() + 1;
	if (u.getPath() != null) {
		len += u.getPath().length();
	}
	if (u.getQuery() != null) {
		len += 1 + u.getQuery().length();
	}
	if (u.getRef() != null)
		len += 1 + u.getRef().length();
	StringBuilder result = new StringBuilder(len);
	result.append(u.getProtocol());
	result.append(":");
	if (u.getPath() != null) {
		result.append(u.getPath());
	}
	if (u.getQuery() != null) {
		result.append('?');
		result.append(u.getQuery());
	}
	if (u.getRef() != null) {
		result.append("#");
		result.append(u.getRef());
	}
	return result.toString();
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:32,代碼來源:DirContextURLStreamHandler.java

示例9: setQueryParam

import java.net.URL; //導入方法依賴的package包/類
/**
 * This method returns a {@link URL} with the specified query parameter added at the end.
 * @param url {@link URL}
 * @param key {@link String}
 * @param value {@link String}
 * @return {@link URL}
 * @throws JSKException If 'url', 'key' or 'value' param are null.
 * @throws JSKException If 'key' or 'value' param are empty.
 * @throws JSKException If 'key' is already in the URL.
 */
public static URL setQueryParam(URL url, String key, String value) throws JSKException {

	if (isNull(url, key, value)) {
		throw new JSKException(NULL_PARAMETERS);
	}

	if (voidOrNull(key, value)) {
		throw new JSKException(EMPTY_PARAMETERS);
	}

	if (getQueryParams(url).containsKey(key)) {
		throw new JSKException(String.format(DUPLICATED_KEY, key));
	}

	String baseUrl = getBaseUrl(url);
	String queries = QUESTION_MARK;
	String param = key + EQUAL + value;

	if(url.getQuery() == null || EMPTY_STRING.equals(url.getQuery())) {
		queries += param;
	}
	else {
		queries += url.getQuery() + AMPERSAND + param;
	}

	return stringToUrl(baseUrl + queries);
}
 
開發者ID:Varoso,項目名稱:JSK,代碼行數:38,代碼來源:JSKUrl.java

示例10: hasDelegationToken

import java.net.URL; //導入方法依賴的package包/類
private boolean hasDelegationToken(URL url, AuthenticatedURL.Token token) {
  boolean hasDt = false;
  if (token instanceof DelegationTokenAuthenticatedURL.Token) {
    hasDt = ((DelegationTokenAuthenticatedURL.Token) token).
        getDelegationToken() != null;
  }
  if (!hasDt) {
    String queryStr = url.getQuery();
    hasDt = (queryStr != null) && queryStr.contains(DELEGATION_PARAM + "=");
  }
  return hasDt;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:DelegationTokenAuthenticator.java

示例11: splitQuery

import java.net.URL; //導入方法依賴的package包/類
/**
 * Helper class to parse Query part of a URL
 *
 * @param url
 * @throws UnsupportedEncodingException
 * @return Query part in the given URL in name-value pair
 */
private static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException {
	Map<String, String> queryPairs = new HashMap<String, String>();
	String query = url.getQuery();
	String[] pairs = query.split("&");
	for (String pair : pairs) {
		int idx = pair.indexOf("=");
		queryPairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
	}
	return queryPairs;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:Agreement.java

示例12: setBaseURL

import java.net.URL; //導入方法依賴的package包/類
public void setBaseURL(URL url) {
//		baseScheme = url.getProtocol();
//		baseHost = baseScheme + "://" + url.getHost() + (url.getPort() == -1 ? "" : ":" + url.getPort());
		basePath = (url.getPath().length() == 0 ? "/" : url.getPath()) + (url.getQuery() == null ? "" : "?" + url.getQuery());
		try {
			basePath = URLEncoder.encode(basePath, "UTF-8");
		} catch (UnsupportedEncodingException e) {
		}
	}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:10,代碼來源:UrlBuilder.java

示例13: encodeUrl

import java.net.URL; //導入方法依賴的package包/類
public static String encodeUrl(String url) throws MalformedURLException {
	URL u = new URL(url);
	String path = u.getPath();
	String query = u.getQuery();
	String fragment = u.getRef();
	
	StringBuilder sb = new StringBuilder();
	sb.append(u.getProtocol());
	sb.append("://");
	sb.append(u.getHost());
	
	if (!path.isEmpty()) {
		path = encodePath(path);
		sb.append(path);
	}
	
	if (query != null && !query.isEmpty()) {
		query = encodeQuery(query);
		sb.append("?");
		sb.append(query);
	}
	
	if (fragment != null && !fragment.isEmpty()) {
		fragment = encodeFragment(fragment);
		sb.append("#");
		sb.append(fragment);
	}
	
	return sb.toString();
}
 
開發者ID:code4wt,項目名稱:short-url,代碼行數:31,代碼來源:UrlUtils.java

示例14: signRequest

import java.net.URL; //導入方法依賴的package包/類
public String signRequest(String mapsUrl) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, URISyntaxException, MalformedURLException {
	URL url = new URL(mapsUrl);
	String resource = url.getPath() + "?" + url.getQuery();
	SecretKeySpec sha1Key = new SecretKeySpec(key, "HmacSHA1");
	Mac mac = Mac.getInstance("HmacSHA1");
	mac.init(sha1Key);
	byte[] sigBytes = mac.doFinal(resource.getBytes());
	String signature = new String(Base64.encode(sigBytes));
	signature = signature.replace('+', '-');
	signature = signature.replace('/', '_');
	return signature;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:13,代碼來源:RoomDetailsBackend.java

示例15: getArgumentFromURL

import java.net.URL; //導入方法依賴的package包/類
private String
getArgumentFromURL(
	URL			url,
	String		argument )
{
	String query = url.getQuery();

	if ( query != null ){

		String[] args = query.split( "&" );

		for ( String arg: args ){

			String [] x = arg.split( "=" );

			if ( x.length == 2 ){

				if ( x[0].equals( argument )){

					return( UrlUtils.decode( x[1] ));
				}
			}
		}
	}

	return( null );
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:28,代碼來源:WebPlugin.java


注:本文中的java.net.URL.getQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。