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.xwiki.wysiwyg.internal.plugin.alfresco.server.UrlNodeReferenceParser.java
@Override public NodeReference parse(String url) { String nodeReference = null;/*from ww w. j a v a2 s . c o m*/ try { // First look at the query string for the nodeRef parameter. for (NameValuePair parameter : URLEncodedUtils.parse(new URI(url), "UTF-8")) { if ("nodeRef".equals(parameter.getName())) { nodeReference = parameter.getValue(); break; } } } catch (URISyntaxException e) { // Ignore. } if (nodeReference == null) { // Look in the URL path. Matcher matcher = NODE_REF_PATH.matcher(url); if (matcher.find()) { return new NodeReference(matcher.group(3), new StoreReference(matcher.group(1), matcher.group(2))); } } return nodeReferenceParser.parse(nodeReference); }
From source file:org.apache.atlas.web.util.Servlets.java
public static String getDoAsUser(HttpServletRequest request) { if (StringUtils.isNoneEmpty(request.getQueryString())) { List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (DO_AS.equals(nv.getName())) { return nv.getValue(); }/*from w ww . j a v a 2s . c om*/ } } } return null; }
From source file:org.apache.marmotta.ldclient.provider.phpbb.mapping.PHPBBTopicHrefMapper.java
/** * Take the selected value, process it according to the mapping definition, and create Sesame Values using the * factory passed as argument.// w w w. j a v a2 s.c o m * * @param resourceUri * @param selectedValue * @param factory * @return */ @Override public List<Value> map(String resourceUri, Element selectedValue, ValueFactory factory) { String baseUriSite = resourceUri.substring(0, resourceUri.lastIndexOf('/')); String baseUriTopic = baseUriSite + "/viewtopic.php?"; try { URI uri = new URI(selectedValue.absUrl("href")); Map<String, String> params = new HashMap<String, String>(); for (NameValuePair p : URLEncodedUtils.parse(uri, "UTF-8")) { params.put(p.getName(), p.getValue()); } return Collections.singletonList((Value) factory.createURI(baseUriTopic + "t=" + params.get("t"))); } catch (URISyntaxException ex) { throw new RuntimeException("invalid syntax for URI", ex); } }
From source file:com.frostwire.android.gui.httpserver.DesktopUploadHandler.java
@Override public void handle(HttpExchange exchange) throws IOException { assertUPnPActive();/* ww w . ja v a 2 s. c o m*/ String filePath = null; String token = null; try { List<NameValuePair> query = URLEncodedUtils.parse(exchange.getRequestURI(), "UTF-8"); for (NameValuePair item : query) { if (item.getName().equals("filePath")) { filePath = item.getValue(); } if (item.getName().equals("token")) { token = item.getValue(); } } if (filePath == null || token == null) { sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.REJECTED); exchange.sendResponseHeaders(Code.HTTP_BAD_REQUEST, 0); return; } if (!durAllowed(filePath, token, exchange.getRemoteAddress().getAddress().getHostAddress())) { sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.REJECTED); exchange.sendResponseHeaders(Code.HTTP_FORBIDDEN, 0); return; } if (!readFile(exchange.getRequestBody(), filePath, token)) { sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.REJECTED); exchange.sendResponseHeaders(Code.HTTP_FORBIDDEN, 0); return; } exchange.sendResponseHeaders(Code.HTTP_OK, 0); } catch (Throwable e) { Log.e(TAG, String.format("Error receiving file from desktop: fileName=%s, token=%s", filePath, token), e); } finally { exchange.close(); } }
From source file:org.apache.oodt.cas.product.jaxrs.filters.BackwardsCompatibleInterceptor.java
@Override public void handleMessage(Message message) throws Fault { String base = (String) message.get(Message.BASE_PATH); String uri = (String) message.get(Message.REQUEST_URI); String query = (String) message.get(Message.QUERY_STRING); base += base.endsWith("/") ? "" : "/"; String request = uri.replaceAll("^" + base, ""); // Parse the query string into a map of parameters. // [Note: this will overwrite multiple parameters that have the same name.] List<NameValuePair> params = URLEncodedUtils.parse(query, Charset.forName("UTF-8")); Map<String, String> map = new ConcurrentHashMap<String, String>(); for (NameValuePair pair : params) { map.put(pair.getName(), pair.getValue()); }// ww w . j ava 2 s . co m // Maps "data?productID=<product ID>" URI to either // "reference.file?productId=<product ID>" or // "product.zip?productId=<product ID>" if (request.equals("data")) { String format = map.get("format"); request = "application/x-zip".equals(format) || "application/zip".equals(format) ? "product.zip" : "reference.file"; query = "productId=" + map.get("productID"); query += map.containsKey("refIndex") ? "&refIndex=" + map.get("refIndex") : ""; } // Maps "dataset?typeID=<product type ID>" to // "dataset.zip?productTypeId=<product type ID>" else if (request.equals("dataset") && map.containsKey("typeID")) { request = "dataset.zip"; query = "productTypeId=" + map.get("typeID"); } // Maps "rdf?type=ALL" or "rdf?id=<product type ID>" to // "dataset.rdf?productTypeId=<ALL or product type ID>" else if (request.equals("rdf")) { request = "dataset.rdf"; String type = map.get("type"); query = "productTypeId="; query += "ALL".equals(type) ? type : map.get("id"); } // Maps "rdf/dataset?type=ALL" or "rdf/dataset?typeID=<product type ID>" to // "dataset.rdf?productTypeId=<ALL or product type ID>" else if (request.equals("rdf/dataset")) { request = "dataset.rdf"; String type = map.get("type"); query = "productTypeId="; query += "ALL".equals(type) ? type : map.get("typeID"); query += map.containsKey("filter") ? "&filter=" + map.get("filter") : ""; } // Maps "viewRecent?channel=ALL" or "viewRecent?id=<product type ID>" to // "dataset.rss?productTypeId=<ALL or product type ID>" else if (request.equals("viewRecent")) { request = "dataset.rss"; String channel = map.get("channel"); query = "productTypeId="; query += "ALL".equals(channel) ? channel : map.get("id"); query += map.containsKey("topn") ? "&limit=" + map.get("topn") : ""; } // Maps "viewTransfers" to "transfers.rss?productId=ALL" else if (request.equals("viewTransfers")) { request = "transfers.rss"; query = "productId=ALL"; } // Store the new URI and query in the message map. uri = base + request; message.put(Message.REQUEST_URI, uri); message.put(Message.QUERY_STRING, query); }
From source file:com.masstransitproject.crosstown.EndpointAddressImpl.java
/** * Check whether the URI has a transactional hint specified by an argument * named "tx"//w w w . j a v a 2s . com * * @param uri * @param defaultTransactional * @return */ protected static boolean checkForTransactionalHint(URI uri, boolean defaultTransactional) { List<NameValuePair> params = URLEncodedUtils.parse(uri, null); for (NameValuePair nvp : params) { if ("tx".equals(nvp.getName())) { return "true".equalsIgnoreCase(nvp.getValue()); } } return false; }
From source file:com.apifest.oauth20.TokenRequest.java
public TokenRequest(HttpRequest request) { String content = request.getContent().toString(CharsetUtil.UTF_8); List<NameValuePair> values = URLEncodedUtils.parse(content, Charset.forName("UTF-8")); Map<String, String> params = new HashMap<String, String>(); for (NameValuePair pair : values) { params.put(pair.getName(), pair.getValue()); }/* w w w . j a v a2s . co m*/ this.grantType = params.get(GRANT_TYPE); this.code = params.get(CODE); this.redirectUri = params.get(REDIRECT_URI); this.clientId = params.get(CLIENT_ID); this.clientSecret = params.get(CLIENT_SECRET); if (this.clientId == null && this.clientSecret == null) { String[] clientCredentials = AuthorizationServer.getBasicAuthorizationClientCredentials(request); this.clientId = clientCredentials[0]; this.clientSecret = clientCredentials[1]; } this.refreshToken = params.get(REFRESH_TOKEN); this.scope = params.get(SCOPE); this.username = params.get(USERNAME); this.password = params.get(PASSWORD); }
From source file:org.piraso.ui.api.views.URLTabView.java
@Override protected void populateMessage(MessageAwareEntry m) throws Exception { List<URI> urls = URLParser.parseUrls(m.getMessage()); int i = 0;//from www. ja v a 2s .c o m for (URI uri : urls) { try { if (i != 0) { insertKeyword(txtEditor, "\n\n"); } insertKeyword(txtEditor, String.format("[%d] Scheme: ", ++i)); insertCode(txtEditor, uri.getScheme()); insertKeyword(txtEditor, "\n Host: "); insertCode(txtEditor, uri.getHost()); if (uri.getPort() > 80) { insertKeyword(txtEditor, "\n Port: "); insertCode(txtEditor, String.valueOf(uri.getPort())); } insertKeyword(txtEditor, "\n Path: "); insertCode(txtEditor, uri.getPath()); String queryString = uri.getQuery(); if (StringUtils.isNotBlank(queryString)) { List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8"); insertKeyword(txtEditor, "\n Query String: "); for (NameValuePair nvp : params) { insertCode(txtEditor, "\n "); insertIdentifier(txtEditor, nvp.getName() + ": "); insertCode(txtEditor, nvp.getValue()); } } } catch (Exception e) { e.printStackTrace(); } } }