List of usage examples for org.apache.http.client.utils URLEncodedUtils parse
public static List<NameValuePair> parse(final String s, final Charset charset)
From source file:org.apache.shindig.social.core.oauth2.OAuth2NormalizedRequest.java
private void normalizeBody(String body) throws OAuth2Exception { if (body == null || body.length() == 0) { return;/*from www . j a v a 2s .co m*/ } List<NameValuePair> params; try { params = URLEncodedUtils.parse(new URI("http://localhost:8080?" + body), "UTF-8"); for (NameValuePair param : params) { put(param.getName(), param.getValue()); } } catch (URISyntaxException e) { OAuth2NormalizedResponse response = new OAuth2NormalizedResponse(); response.setError(ErrorType.INVALID_REQUEST.toString()); response.setErrorDescription("The message body's syntax is incorrect"); response.setStatus(HttpServletResponse.SC_FORBIDDEN); throw new OAuth2Exception(response); } }
From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java
/** * Takes a string that looks like a URL and performs an operation based on the * contents of the URL. Currently only starting activities is supported. * <p>/* w w w . java2s . c om*/ * Supported URL type follows: * <ul> * <li>{@code and-activity://<Activity class name>}<br> * start specified activity * </ul> */ @Override public void get(String url) { URI dest; try { dest = new URI(url); } catch (URISyntaxException exception) { throw new IllegalArgumentException(exception); } if (!"and-activity".equals(dest.getScheme())) { throw new WebDriverException("Unrecognized scheme in URI: " + dest.toString()); } else if (!Strings.isNullOrEmpty(dest.getPath())) { throw new WebDriverException("Unrecognized path in URI: " + dest.toString()); } Class<?> clazz; try { clazz = Class.forName(dest.getAuthority()); } catch (ClassNotFoundException exception) { throw new WebDriverException("The specified Activity class does not exist: " + dest.getAuthority(), exception); } for (NameValuePair nvp : URLEncodedUtils.parse(dest, "utf8")) { if ("id".equals(nvp.getName())) { // This is to prevent people from recycling the same URL they got from // getCurrentUrl() and expecting to return to an arbitrary running // activity. It is not supported in the Android user interface so we // don't expose this functionality. throw new WebDriverException("Moving to the specified activity is not supported."); } } startActivity(clazz); }
From source file:org.wso2.identity.integration.test.util.Utils.java
public static Map<String, String> getQueryParams(String Url) throws Exception { Map<String, String> queryParams = new HashMap<>(); List<NameValuePair> params = URLEncodedUtils.parse(new URI(Url), "UTF-8"); for (NameValuePair param : params) { queryParams.put(param.getName(), param.getValue()); }//from ww w . java2s . c om return queryParams; }
From source file:org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter.java
@VisibleForTesting static String getDoAs(HttpServletRequest request) { List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (DelegationTokenAuthenticatedURL.DO_AS.equalsIgnoreCase(nv.getName())) { return nv.getValue(); }/*from w w w .j a v a 2s. c o m*/ } } return null; }
From source file:com.gsma.mobileconnect.impl.DiscoveryImpl.java
/** * See {@link IDiscovery#parseDiscoveryRedirect(String, IParsedDiscoveryRedirectCallback)} *///from w w w. ja v a 2 s. c o m public void parseDiscoveryRedirect(String redirectURL, IParsedDiscoveryRedirectCallback callback) throws URISyntaxException { ValidationUtils.validateParameter(redirectURL, "redirectURL"); ValidationUtils.validateParameter(callback, "callback"); URI uri = new URI(redirectURL); String query = uri.getQuery(); if (null == query) { callback.completed(new ParsedDiscoveryRedirect(null, null, null)); return; } List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), null); String mcc_mnc = HttpUtils.getParameterValue(parameters, Constants.MCC_MNC_PARAMETER_NAME); String subscriber_id = HttpUtils.getParameterValue(parameters, Constants.SUBSCRIBER_ID_PARAMETER_NAME); String mcc = null; String mnc = null; if (null != mcc_mnc) { String[] parts = mcc_mnc.split("_"); if (parts.length == 2) { mcc = parts[0]; mnc = parts[1]; } } callback.completed(new ParsedDiscoveryRedirect(mcc, mnc, subscriber_id)); }
From source file:com.serphacker.serposcope.scraper.google.scraper.GoogleScraper.java
protected String extractLink(Element element) { if (element == null) { return null; }/*from w w w . ja va 2s .c o m*/ String attr = element.attr("href"); if (attr == null) { return null; } if ((attr.startsWith("http://www.google") || attr.startsWith("https://www.google"))) { if (attr.contains("/aclk?")) { return null; } } if (attr.startsWith("http://") || attr.startsWith("https://")) { return attr; } if (attr.startsWith("/url?")) { try { List<NameValuePair> parse = URLEncodedUtils.parse(attr.substring(5), Charset.forName("utf-8")); Map<String, String> map = parse.stream() .collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue)); return map.get("q"); } catch (Exception ex) { return null; } } return null; }
From source file:de.geeksfactory.opacclient.apis.Heidi.java
private SearchRequestResult parse_search(String html, int page) { Document doc = Jsoup.parse(html); doc.setBaseUri(opac_url);/*from w ww .j av a 2s . co m*/ int results_total = 0; if (doc.select("#heiditreffer").size() > 0) { String resstr = doc.select("#heiditreffer").text(); String resnum = resstr.replaceAll("\\(([0-9.]+)([^0-9]*)\\)", "$1").replace(".", ""); results_total = Integer.parseInt(resnum); } Elements table = doc.select("table.treffer tr"); List<SearchResult> results = new ArrayList<>(); for (int i = 0; i < table.size(); i++) { Element tr = table.get(i); SearchResult sr = new SearchResult(); StringBuilder description = null; String author = ""; for (Element link : tr.select("a")) { String kk = getQueryParamsFirst(link.absUrl("href")).get("katkey"); if (kk != null) { sr.setId(kk); break; } } if (tr.select("span.Z3988").size() == 1) { // Luckily there is a <span class="Z3988"> item which provides // data in a standardized format. List<NameValuePair> z3988data; boolean hastitle = false; try { description = new StringBuilder(); z3988data = URLEncodedUtils .parse(new URI("http://dummy/?" + tr.select("span.Z3988").attr("title")), "UTF-8"); for (NameValuePair nv : z3988data) { if (nv.getValue() != null) { if (!nv.getValue().trim().equals("")) { if (nv.getName().equals("rft.btitle") && !hastitle) { description.append("<b>").append(nv.getValue()).append("</b>"); hastitle = true; } else if (nv.getName().equals("rft.atitle") && !hastitle) { description.append("<b>").append(nv.getValue()).append("</b>"); hastitle = true; } else if (nv.getName().equals("rft.au")) { author = nv.getValue(); } else if (nv.getName().equals("rft.aufirst")) { author = author + ", " + nv.getValue(); } else if (nv.getName().equals("rft.aulast")) { author = nv.getValue(); } else if (nv.getName().equals("rft.date")) { description.append("<br />").append(nv.getValue()); } } } } } catch (URISyntaxException e) { description = null; } } if (!"".equals(author)) { author = author + "<br />"; } sr.setInnerhtml(author + description.toString()); if (tr.select(".kurzstat").size() > 0) { String stattext = tr.select(".kurzstat").first().text(); if (stattext.contains("ausleihbar")) { sr.setStatus(Status.GREEN); } else if (stattext.contains("online")) { sr.setStatus(Status.GREEN); } else if (stattext.contains("entliehen")) { sr.setStatus(Status.RED); } else if (stattext.contains("Prsenznutzung")) { sr.setStatus(Status.YELLOW); } else if (stattext.contains("bestellen")) { sr.setStatus(Status.YELLOW); } } if (tr.select(".typbild").size() > 0) { String typtext = tr.select(".typbild").first().text(); if (typtext.contains("Buch")) { sr.setType(MediaType.BOOK); } else if (typtext.contains("DVD-ROM")) { sr.setType(MediaType.CD_SOFTWARE); } else if (typtext.contains("Online-Ressource")) { sr.setType(MediaType.EDOC); } else if (typtext.contains("DVD")) { sr.setType(MediaType.DVD); } else if (typtext.contains("Film")) { sr.setType(MediaType.MOVIE); } else if (typtext.contains("Zeitschrift")) { sr.setType(MediaType.MAGAZINE); } else if (typtext.contains("Musiknoten")) { sr.setType(MediaType.SCORE_MUSIC); } else if (typtext.contains("Bildliche Darstellung")) { sr.setType(MediaType.ART); } else if (typtext.contains("Zeitung")) { sr.setType(MediaType.NEWSPAPER); } else if (typtext.contains("Karte")) { sr.setType(MediaType.MAP); } else if (typtext.contains("Mehrteilig")) { sr.setType(MediaType.PACKAGE_BOOKS); } } results.add(sr); } // TODO return new SearchRequestResult(results, results_total, page); }
From source file:com.android.vending.licensing.ServerManagedPolicy.java
private Map<String, String> decodeExtras(String extras) { Map<String, String> results = new HashMap<String, String>(); try {/*from w ww . j a v a2s . c o m*/ URI rawExtras = new URI("?" + extras); List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8"); for (NameValuePair item : extraList) { results.put(item.getName(), item.getValue()); } } catch (URISyntaxException e) { Log.w(TAG, "Invalid syntax error while decoding extras data from server."); } return results; }
From source file:org.zaizi.oauth2utils.OAuthUtils.java
public static Map handleURLEncodedResponse(HttpResponse response) { Map<String, Charset> map = Charset.availableCharsets(); Map<String, String> oauthResponse = new HashMap<String, String>(); Set<Map.Entry<String, Charset>> set = map.entrySet(); Charset charset = null;//from w w w . j a v a 2 s. c o m HttpEntity entity = response.getEntity(); System.out.println(); System.out.println("********** Response Received **********"); for (Map.Entry<String, Charset> entry : set) { System.out.println(String.format(" %s = %s", entry.getKey(), entry.getValue())); if (entry.getKey().equalsIgnoreCase(HTTP.UTF_8)) { charset = entry.getValue(); } } try { List<NameValuePair> list = URLEncodedUtils.parse(EntityUtils.toString(entity), Charset.forName(HTTP.UTF_8)); for (NameValuePair pair : list) { System.out.println(String.format(" %s = %s", pair.getName(), pair.getValue())); oauthResponse.put(pair.getName(), pair.getValue()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new RuntimeException("Could not parse URLEncoded Response"); } return oauthResponse; }