List of usage examples for java.net URL getQuery
public String getQuery()
From source file:org.jboss.set.aphrodite.common.Utils.java
public static String getParamaterFromUrl(Pattern pattern, URL url) throws NotFoundException { Matcher matcher = pattern.matcher(url.getQuery()); if (!matcher.find()) throw new NotFoundException("No parameter matching the specified pattern exists in the provided url."); return decodeURLParam(matcher.group(1)); }
From source file:org.geotools.data.wfs.protocol.http.HttpUtil.java
@SuppressWarnings("unchecked") public static Map<String, String> requestKvp(URL url) { String queryString = url.getQuery(); String[] split = queryString.split("&"); Map<String, String> kvp = new LinkedHashMap<String, String>(); for (String encodedKvp : split) { String[] splittedKvp = encodedKvp.split("="); final String key = splittedKvp[0]; String value = splittedKvp.length == 2 ? splittedKvp[1] : null; if (value != null) { try { value = URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }/*ww w . jav a 2s . c o m*/ } kvp.put(key, value); } return new CaseInsensitiveMap(kvp); }
From source file:Main.java
public static String encodeDocumentUrl(String urlString) { try {/*from w ww .j a va2s .c o m*/ URL url = new URL(urlString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); return uri.toASCIIString(); } catch (MalformedURLException e) { return null; } catch (URISyntaxException e) { return null; } }
From source file:Main.java
public static String realUrl(String target) { try {//from ww w . j a va 2 s. co m URL url = new URL(target); String protocol = url.getProtocol(); String host = url.getHost(); String path = url.getPath(); String query = url.getQuery(); path = URLEncoder.encode(path, "utf-8").replace("%3A", ":").replace("%2B", "+").replace("%2C", ",") .replace("%5E", "^").replace("%2F", "/").replace("%21", "!").replace("%24", "$") .replace("%25", "%").replace("%26", "&").replace("%28", "(").replace("%29", ")") .replace("%40", "@").replace("%60", "`"); // .replace("", "#"); // not support. StringBuilder urlBuild = new StringBuilder(protocol).append("://").append(host).append(path); if (query != null) urlBuild.append("?").append(query); return urlBuild.toString(); } catch (IOException e) { return target; } }
From source file:com.threadswarm.imagefeedarchiver.FeedUtils.java
/** * Returns a hierarchical {@code URI} constructed from individual components * of the supplied {@code urlString} argument. * <p>/* www . ja v a 2s.co m*/ * The {@code urlString} argument is first used to instantiate a {@code URL} * which in turn is used to construct a {@code URI} based on the individual * components of the former. This more robust then simply calling {@code URL.toURI()}. * * @param urlString the {@code String} based representation of a URL * @return a {@code URI} constructed from the individual URL components * @throws URISyntaxException if a valid {@code URI} cannot be constructed from the supplied {@code urlString} argument * @throws MalformedURLException if the {@code urlString} cannot be used to instantiate a {@code URL} */ public static URI getUriFromUrlString(String urlString) throws URISyntaxException, MalformedURLException { URL url = new URL(urlString); return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); }
From source file:org.mar9000.space2latex.utils.ConfluenceRESTUtils.java
public static JSONObject getURLResponse(String urlString, int start, int limit) throws MalformedURLException { StringBuffer buffer = new StringBuffer(); // Always add limit. URL receivedURL = new URL(urlString); if (receivedURL.getQuery() == null) urlString += "?"; else/*from ww w . j a v a 2s.c o m*/ urlString += "&"; urlString += "limit=" + limit; if (start != 0) { urlString += "&start=" + start; } URL requestURL = new URL(urlString); URLConnection urlConn = null; int count = MAX_REQUEST_TRY; while (urlConn == null && count > 0) { try { urlConn = requestURL.openConnection(); } catch (IOException e) { try { Thread.sleep(1000 * 5); } catch (InterruptedException e1) { } count--; urlConn = null; } } if (urlConn == null) throw new RuntimeException("Max retry count reached for open URL: " + urlString); // BufferedReader reader = null; count = MAX_REQUEST_TRY; while (reader == null && count > 0) { try { reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); } catch (IOException e) { reader = null; count--; try { Thread.sleep(1000 * 5); } catch (InterruptedException e1) { } } } if (reader == null) throw new RuntimeException("Max retry count reached for open InputStream: " + urlString); // try { String inputLine; while ((inputLine = reader.readLine()) != null) { buffer.append(inputLine); } reader.close(); } catch (IOException e) { throw new RuntimeException("Error reading line from URL: " + urlString); } // Return. return new JSONObject(buffer.toString()); }
From source file:com.cdancy.artifactory.rest.util.ArtifactoryUtils.java
public static String getBasePath(URL url, String endpoint) { String pathFromUrl = url.toString().replaceFirst(endpoint, ""); if (url.getQuery() != null) { int index = url.getQuery().lastIndexOf("?"); if (index != -1) { pathFromUrl = url.getQuery().substring(0, index); }/*w w w. j ava 2 s . c om*/ } return pathFromUrl; }
From source file:net.turnbig.pandora.utils.Encodes.java
/** * URL ?, EncodeUTF-8./* www. j a v a2 s . co m*/ */ public static String uriEncode(String uri) { try { URL url = new URL(uri); URI temp = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), url.getRef()); return temp.toString(); } catch (URISyntaxException e) { throw Exceptions.unchecked(e); } catch (MalformedURLException e) { throw Exceptions.unchecked(e); } }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URI newEncodedURI(String u) throws MalformedURLException, URISyntaxException { URL tmpUrl = new URL(u); return new URI(tmpUrl.getProtocol(), tmpUrl.getUserInfo(), tmpUrl.getHost(), tmpUrl.getPort(), tmpUrl.getPath(), tmpUrl.getQuery(), tmpUrl.getRef()); }
From source file:com.github.walterfan.util.http.URLHelper.java
public static String getPathAndQuery(String strUrl) { try {//from ww w . ja va 2 s . c o m URL url = new URL(strUrl); //System.out.println("url=" + url); String path = url.getPath(); String query = url.getQuery(); if (StringUtils.isNotBlank(query)) { path = path + "?" + query; } if (path.startsWith("/")) { return path.substring(1); } } catch (MalformedURLException e) { e.printStackTrace(); } return ""; }