当前位置: 首页>>代码示例>>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;未经允许,请勿转载。