List of usage examples for java.io UnsupportedEncodingException toString
public String toString()
From source file:net.sf.jabref.importer.fetcher.ISBNtoBibTeXFetcher.java
@Override public boolean processQuery(String query, ImportInspector inspector, OutputPrinter status) { String q;// ww w . j a va 2s . c o m try { q = URLEncoder.encode(query, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { // this should never happen status.setStatus(Localization.lang("Error")); LOGGER.warn("Shouldn't happen...", e); return false; } String urlString = String.format(ISBNtoBibTeXFetcher.URL_PATTERN, q); // Send the request URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { LOGGER.warn("Bad URL when fetching ISBN info", e); return false; } try (InputStream source = url.openStream()) { String bibtexString; try (Scanner scan = new Scanner(source)) { bibtexString = scan.useDelimiter("\\A").next(); } BibEntry entry = BibtexParser.singleFromString(bibtexString); if (entry != null) { // Optionally add curly brackets around key words to keep the case entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { // Unit formatting if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) { title = unitsToLatexFormatter.format(title); } // Case keeping if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) { title = protectTermsFormatter.format(title); } entry.setField(FieldName.TITLE, title); }); inspector.addEntry(entry); return true; } return false; } catch (FileNotFoundException e) { // invalid ISBN --> 404--> FileNotFoundException status.showMessage(Localization.lang("No entry found for ISBN %0 at www.ebook.de", query)); LOGGER.debug("No ISBN info found", e); return false; } catch (UnknownHostException e) { // It is very unlikely that ebook.de is an unknown host // It is more likely that we don't have an internet connection status.showMessage(Localization.lang("No_internet_connection.")); LOGGER.debug("No internet connection", e); return false; } catch (Exception e) { status.showMessage(e.toString()); LOGGER.warn("Problem getting info for ISBN", e); return false; } }
From source file:org.ofbiz.passport.event.LinkedInEvents.java
/** * Parse LinkedIn login response and login the user if possible. * /* w ww.j a va2 s .c o m*/ * @return */ public static String parseLinkedInResponse(HttpServletRequest request, HttpServletResponse response) { String authorizationCode = request.getParameter(PassportUtil.COMMON_CODE); String state = request.getParameter(PassportUtil.COMMON_STATE); if (!state.equals(request.getSession().getAttribute(SESSION_LINKEDIN_STATE))) { String errMsg = UtilProperties.getMessage(resource, "LinkedInFailedToMatchState", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } if (UtilValidate.isEmpty(authorizationCode)) { String error = request.getParameter(PassportUtil.COMMON_ERROR); String errorDescpriton = request.getParameter(PassportUtil.COMMON_ERROR_DESCRIPTION); String errMsg = null; try { errMsg = UtilProperties.getMessage(resource, "FailedToGetLinkedInAuthorizationCode", UtilMisc.toMap(PassportUtil.COMMON_ERROR, error, PassportUtil.COMMON_ERROR_DESCRIPTION, URLDecoder.decode(errorDescpriton, "UTF-8")), UtilHttp.getLocale(request)); } catch (UnsupportedEncodingException e) { errMsg = UtilProperties.getMessage(resource, "GetLinkedInAuthorizationCodeError", UtilHttp.getLocale(request)); } request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } // Debug.logInfo("LinkedIn authorization code: " + authorizationCode, module); GenericValue oauth2LinkedIn = getOAuth2LinkedInConfig(request); if (UtilValidate.isEmpty(oauth2LinkedIn)) { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInConfigError", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } String clientId = oauth2LinkedIn.getString(PassportUtil.ApiKeyLabel); String secret = oauth2LinkedIn.getString(PassportUtil.SecretKeyLabel); String returnURI = oauth2LinkedIn.getString(envPrefix + PassportUtil.ReturnUrlLabel); // Grant token from authorization code and oauth2 token // Use the authorization code to obtain an access token String accessToken = null; HttpClient jsonClient = new HttpClient(); PostMethod postMethod = new PostMethod(TokenEndpoint + TokenServiceUri); try { HttpMethodParams params = new HttpMethodParams(); String queryString = "client_id=" + clientId + "&client_secret=" + secret + "&grant_type=authorization_code" + "&code=" + authorizationCode + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8"); // Debug.logInfo("LinkedIn get access token query string: " + queryString, module); postMethod.setQueryString(queryString); params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); postMethod.setParams(params); jsonClient.executeMethod(postMethod); // Debug.logInfo("LinkedIn get access token response code: " + postMethod.getStatusCode(), module); // Debug.logInfo("LinkedIn get access token response content: " + postMethod.getResponseBodyAsString(1024), module); if (postMethod.getStatusCode() == HttpStatus.SC_OK) { // Debug.logInfo("Json Response from LinkedIn: " + postMethod.getResponseBodyAsString(1024), module); JSON jsonObject = JSON.from(postMethod.getResponseBodyAsString(1024)); JSONToMap jsonMap = new JSONToMap(); Map<String, Object> userMap = jsonMap.convert(jsonObject); accessToken = (String) userMap.get("access_token"); // Debug.logInfo("Generated Access Token : " + accessToken, module); } else { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInAccessTokenError", UtilMisc.toMap("error", postMethod.getResponseBodyAsString()), UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } catch (UnsupportedEncodingException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (HttpException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ConversionException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { postMethod.releaseConnection(); } // Get User Profile GetMethod getMethod = new GetMethod(TokenEndpoint + UserApiUri + "?oauth2_access_token=" + accessToken); Document userInfo = null; try { userInfo = LinkedInAuthenticator.getUserInfo(getMethod, UtilHttp.getLocale(request)); } catch (HttpException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (AuthenticatorException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (SAXException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ParserConfigurationException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { getMethod.releaseConnection(); } // Debug.logInfo("LinkedIn User Info:" + userInfo, module); // Store the user info and check login the user return checkLoginLinkedInUser(request, userInfo, accessToken); }
From source file:org.apache.ofbiz.passport.event.LinkedInEvents.java
/** * Parse LinkedIn login response and login the user if possible. * /*from www . j ava2s . com*/ * @return */ public static String parseLinkedInResponse(HttpServletRequest request, HttpServletResponse response) { String authorizationCode = request.getParameter(PassportUtil.COMMON_CODE); String state = request.getParameter(PassportUtil.COMMON_STATE); if (!state.equals(request.getSession().getAttribute(SESSION_LINKEDIN_STATE))) { String errMsg = UtilProperties.getMessage(resource, "LinkedInFailedToMatchState", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } if (UtilValidate.isEmpty(authorizationCode)) { String error = request.getParameter(PassportUtil.COMMON_ERROR); String errorDescpriton = request.getParameter(PassportUtil.COMMON_ERROR_DESCRIPTION); String errMsg = null; try { errMsg = UtilProperties.getMessage(resource, "FailedToGetLinkedInAuthorizationCode", UtilMisc.toMap(PassportUtil.COMMON_ERROR, error, PassportUtil.COMMON_ERROR_DESCRIPTION, URLDecoder.decode(errorDescpriton, "UTF-8")), UtilHttp.getLocale(request)); } catch (UnsupportedEncodingException e) { errMsg = UtilProperties.getMessage(resource, "GetLinkedInAuthorizationCodeError", UtilHttp.getLocale(request)); } request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } // Debug.logInfo("LinkedIn authorization code: " + authorizationCode, module); GenericValue oauth2LinkedIn = getOAuth2LinkedInConfig(request); if (UtilValidate.isEmpty(oauth2LinkedIn)) { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInConfigError", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } String clientId = oauth2LinkedIn.getString(PassportUtil.ApiKeyLabel); String secret = oauth2LinkedIn.getString(PassportUtil.SecretKeyLabel); String returnURI = oauth2LinkedIn.getString(envPrefix + PassportUtil.ReturnUrlLabel); // Grant token from authorization code and oauth2 token // Use the authorization code to obtain an access token String accessToken = null; try { URI uri = new URIBuilder().setScheme(TokenEndpoint.substring(0, TokenEndpoint.indexOf(":"))) .setHost(TokenEndpoint.substring(TokenEndpoint.indexOf(":") + 3)).setPath(TokenServiceUri) .setParameter("client_id", clientId).setParameter("client_secret", secret) .setParameter("grant_type", "authorization_code").setParameter("code", authorizationCode) .setParameter("redirect_uri", returnURI).build(); HttpPost postMethod = new HttpPost(uri); CloseableHttpClient jsonClient = HttpClients.custom().build(); // Debug.logInfo("LinkedIn get access token query string: " + postMethod.getURI(), module); postMethod.setConfig(PassportUtil.StandardRequestConfig); CloseableHttpResponse postResponse = jsonClient.execute(postMethod); String responseString = new BasicResponseHandler().handleResponse(postResponse); // Debug.logInfo("LinkedIn get access token response code: " + postResponse.getStatusLine().getStatusCode(), module); // Debug.logInfo("LinkedIn get access token response content: " + responseString, module); if (postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Debug.logInfo("Json Response from LinkedIn: " + responseString, module); JSON jsonObject = JSON.from(responseString); JSONToMap jsonMap = new JSONToMap(); Map<String, Object> userMap = jsonMap.convert(jsonObject); accessToken = (String) userMap.get("access_token"); // Debug.logInfo("Generated Access Token : " + accessToken, module); } else { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInAccessTokenError", UtilMisc.toMap("error", responseString), UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } catch (UnsupportedEncodingException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ConversionException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (URISyntaxException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } // Get User Profile HttpGet getMethod = new HttpGet(TokenEndpoint + UserApiUri + "?oauth2_access_token=" + accessToken); Document userInfo = null; try { userInfo = LinkedInAuthenticator.getUserInfo(getMethod, UtilHttp.getLocale(request)); } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (AuthenticatorException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (SAXException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ParserConfigurationException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { getMethod.releaseConnection(); } // Debug.logInfo("LinkedIn User Info:" + userInfo, module); // Store the user info and check login the user return checkLoginLinkedInUser(request, userInfo, accessToken); }
From source file:org.ofbiz.passport.event.GitHubEvents.java
/** * Parse GitHub login response and login the user if possible. * //w w w . j av a 2 s . c om * @return */ public static String parseGitHubResponse(HttpServletRequest request, HttpServletResponse response) { String authorizationCode = request.getParameter(PassportUtil.COMMON_CODE); String state = request.getParameter(PassportUtil.COMMON_STATE); if (!state.equals(request.getSession().getAttribute(SESSION_GITHUB_STATE))) { String errMsg = UtilProperties.getMessage(resource, "GitHubFailedToMatchState", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } if (UtilValidate.isEmpty(authorizationCode)) { String error = request.getParameter(PassportUtil.COMMON_ERROR); String errorDescpriton = request.getParameter(PassportUtil.COMMON_ERROR_DESCRIPTION); String errMsg = null; try { errMsg = UtilProperties.getMessage(resource, "FailedToGetGitHubAuthorizationCode", UtilMisc.toMap(PassportUtil.COMMON_ERROR, error, PassportUtil.COMMON_ERROR_DESCRIPTION, URLDecoder.decode(errorDescpriton, "UTF-8")), UtilHttp.getLocale(request)); } catch (UnsupportedEncodingException e) { errMsg = UtilProperties.getMessage(resource, "GetGitHubAuthorizationCodeError", UtilHttp.getLocale(request)); } request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } Debug.logInfo("GitHub authorization code: " + authorizationCode, module); GenericValue oauth2GitHub = getOAuth2GitHubConfig(request); if (UtilValidate.isEmpty(oauth2GitHub)) { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubConfigError", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } String clientId = oauth2GitHub.getString(PassportUtil.COMMON_CLIENT_ID); String secret = oauth2GitHub.getString(PassportUtil.COMMON_CLIENT_SECRET); String returnURI = oauth2GitHub.getString(PassportUtil.COMMON_RETURN_RUL); // Grant token from authorization code and oauth2 token // Use the authorization code to obtain an access token String accessToken = null; String tokenType = null; HttpClient jsonClient = new HttpClient(); PostMethod postMethod = new PostMethod(TokenEndpoint + TokenServiceUri); try { HttpMethodParams params = new HttpMethodParams(); String queryString = "client_id=" + clientId + "&client_secret=" + secret + "&code=" + authorizationCode + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8"); // Debug.logInfo("GitHub get access token query string: " + queryString, module); postMethod.setQueryString(queryString); params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); postMethod.setParams(params); postMethod.setRequestHeader(PassportUtil.ACCEPT_HEADER, "application/json"); jsonClient.executeMethod(postMethod); // Debug.logInfo("GitHub get access token response code: " + postMethod.getStatusCode(), module); // Debug.logInfo("GitHub get access token response content: " + postMethod.getResponseBodyAsString(1024), module); if (postMethod.getStatusCode() == HttpStatus.SC_OK) { // Debug.logInfo("Json Response from GitHub: " + postMethod.getResponseBodyAsString(1024), module); JSON jsonObject = JSON.from(postMethod.getResponseBodyAsString(1024)); JSONToMap jsonMap = new JSONToMap(); Map<String, Object> userMap = jsonMap.convert(jsonObject); accessToken = (String) userMap.get("access_token"); tokenType = (String) userMap.get("token_type"); // Debug.logInfo("Generated Access Token : " + accessToken, module); // Debug.logInfo("Token Type: " + tokenType, module); } else { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubAccessTokenError", UtilMisc.toMap("error", postMethod.getResponseBodyAsString()), UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } catch (UnsupportedEncodingException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (HttpException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ConversionException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { postMethod.releaseConnection(); } // Get User Profile GetMethod getMethod = new GetMethod(ApiEndpoint + UserApiUri); Map<String, Object> userInfo = null; try { userInfo = GitHubAuthenticator.getUserInfo(getMethod, accessToken, tokenType, UtilHttp.getLocale(request)); } catch (HttpException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (AuthenticatorException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { getMethod.releaseConnection(); } // Debug.logInfo("GitHub User Info:" + userInfo, module); // Store the user info and check login the user return checkLoginGitHubUser(request, userInfo, accessToken); }
From source file:org.apache.ofbiz.passport.event.GitHubEvents.java
/** * Parse GitHub login response and login the user if possible. * // ww w . j a v a2s .c om * @return */ public static String parseGitHubResponse(HttpServletRequest request, HttpServletResponse response) { String authorizationCode = request.getParameter(PassportUtil.COMMON_CODE); String state = request.getParameter(PassportUtil.COMMON_STATE); if (!state.equals(request.getSession().getAttribute(SESSION_GITHUB_STATE))) { String errMsg = UtilProperties.getMessage(resource, "GitHubFailedToMatchState", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } if (UtilValidate.isEmpty(authorizationCode)) { String error = request.getParameter(PassportUtil.COMMON_ERROR); String errorDescpriton = request.getParameter(PassportUtil.COMMON_ERROR_DESCRIPTION); String errMsg = null; try { errMsg = UtilProperties.getMessage(resource, "FailedToGetGitHubAuthorizationCode", UtilMisc.toMap(PassportUtil.COMMON_ERROR, error, PassportUtil.COMMON_ERROR_DESCRIPTION, URLDecoder.decode(errorDescpriton, "UTF-8")), UtilHttp.getLocale(request)); } catch (UnsupportedEncodingException e) { errMsg = UtilProperties.getMessage(resource, "GetGitHubAuthorizationCodeError", UtilHttp.getLocale(request)); } request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } Debug.logInfo("GitHub authorization code: " + authorizationCode, module); GenericValue oauth2GitHub = getOAuth2GitHubConfig(request); if (UtilValidate.isEmpty(oauth2GitHub)) { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubConfigError", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } String clientId = oauth2GitHub.getString(PassportUtil.COMMON_CLIENT_ID); String secret = oauth2GitHub.getString(PassportUtil.COMMON_CLIENT_SECRET); String returnURI = oauth2GitHub.getString(PassportUtil.COMMON_RETURN_RUL); // Grant token from authorization code and oauth2 token // Use the authorization code to obtain an access token String accessToken = null; String tokenType = null; try { URI uri = new URIBuilder().setScheme(TokenEndpoint.substring(0, TokenEndpoint.indexOf(":"))) .setHost(TokenEndpoint.substring(TokenEndpoint.indexOf(":") + 3)).setPath(TokenServiceUri) .setParameter("client_id", clientId).setParameter("client_secret", secret) .setParameter("code", authorizationCode).setParameter("redirect_uri", returnURI).build(); HttpPost postMethod = new HttpPost(uri); CloseableHttpClient jsonClient = HttpClients.custom().build(); // Debug.logInfo("GitHub get access token query string: " + postMethod.getURI(), module); postMethod.setConfig(PassportUtil.StandardRequestConfig); postMethod.setHeader(PassportUtil.ACCEPT_HEADER, "application/json"); CloseableHttpResponse postResponse = jsonClient.execute(postMethod); String responseString = new BasicResponseHandler().handleResponse(postResponse); // Debug.logInfo("GitHub get access token response code: " + postResponse.getStatusLine().getStatusCode(), module); // Debug.logInfo("GitHub get access token response content: " + responseString, module); if (postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Debug.logInfo("Json Response from GitHub: " + responseString, module); JSON jsonObject = JSON.from(responseString); JSONToMap jsonMap = new JSONToMap(); Map<String, Object> userMap = jsonMap.convert(jsonObject); accessToken = (String) userMap.get("access_token"); tokenType = (String) userMap.get("token_type"); // Debug.logInfo("Generated Access Token : " + accessToken, module); // Debug.logInfo("Token Type: " + tokenType, module); } else { String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubAccessTokenError", UtilMisc.toMap("error", responseString), UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } catch (UnsupportedEncodingException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (ConversionException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } catch (URISyntaxException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } // Get User Profile HttpGet getMethod = new HttpGet(ApiEndpoint + UserApiUri); Map<String, Object> userInfo = null; try { userInfo = GitHubAuthenticator.getUserInfo(getMethod, accessToken, tokenType, UtilHttp.getLocale(request)); } catch (AuthenticatorException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { getMethod.releaseConnection(); } // Debug.logInfo("GitHub User Info:" + userInfo, module); // Store the user info and check login the user return checkLoginGitHubUser(request, userInfo, accessToken); }
From source file:org.kuali.test.utils.Utils.java
public static String decodeParameterName(String input) { String retval = input;//w ww . ja v a 2 s .co m if (StringUtils.isNotBlank(input)) { try { retval = stripXY(URLDecoder.decode(input, CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { LOG.warn(ex.toString(), ex); } } return retval; }
From source file:org.kuali.test.utils.Utils.java
public static String buildUrlEncodedParameterString(List<NameValuePair> nvplist, boolean decode) throws UnsupportedEncodingException { StringBuilder retval = new StringBuilder(512); String paramSeparator = ""; for (NameValuePair nvp : nvplist) { retval.append(paramSeparator);//from w w w .j a v a 2s. c o m if (decode) { try { retval.append(URLDecoder.decode(nvp.getName(), CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { retval.append(nvp.getName()); LOG.warn(ex.toString(), ex); } } else { retval.append(nvp.getName()); } retval.append(Constants.SEPARATOR_EQUALS); if (nvp.getValue() == null) { retval.append(""); } else { if (decode) { try { retval.append(URLDecoder.decode(nvp.getValue(), CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { retval.append(nvp.getValue()); LOG.warn(ex.toString(), ex); } } else { retval.append(nvp.getValue()); } } paramSeparator = Constants.SEPARATOR_AMPERSTAND; } return retval.toString(); }
From source file:org.kuali.test.utils.Utils.java
public static String buildMultipartParameterString(List<NameValuePair> nvplist, boolean decode) { StringBuilder retval = new StringBuilder(512); String paramSeparator = ""; for (NameValuePair nvp : nvplist) { retval.append(paramSeparator);// w w w . j a va2 s . c om if (decode) { try { retval.append(URLDecoder.decode(nvp.getName(), CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { retval.append(nvp.getName()); LOG.warn(ex.toString(), ex); } } else { retval.append(nvp.getName()); } retval.append(Constants.MULTIPART_NAME_VALUE_SEPARATOR); if (nvp.getValue() == null) { retval.append(""); } else { if (decode) { try { retval.append(URLDecoder.decode(nvp.getValue(), CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { retval.append(nvp.getValue()); LOG.warn(ex.toString(), ex); } } else { retval.append(nvp.getValue()); } } paramSeparator = Constants.MULTIPART_PARAMETER_SEPARATOR; } return retval.toString(); }
From source file:org.kuali.test.utils.Utils.java
public static List<NameValuePair> getNameValuePairsFromMultipartParams(String paramString, boolean decode) { List<NameValuePair> retval = new ArrayList<NameValuePair>(); if (StringUtils.isNotBlank(paramString)) { StringTokenizer st1 = new StringTokenizer(paramString, Constants.MULTIPART_PARAMETER_SEPARATOR); while (st1.hasMoreTokens()) { StringTokenizer st2 = new StringTokenizer(st1.nextToken(), Constants.MULTIPART_NAME_VALUE_SEPARATOR); if (st2.countTokens() > 0) { String name = st2.nextToken().trim(); String value = ""; if (st2.hasMoreTokens()) { value = st2.nextToken(); }//from w ww . j a v a 2s . c om if (StringUtils.isNotBlank(value)) { if (decode) { try { retval.add(new NameValuePair(name, URLDecoder.decode(value.trim(), CharEncoding.UTF_8))); } catch (UnsupportedEncodingException ex) { retval.add(new NameValuePair(name, value.trim())); LOG.warn(ex.toString(), ex); } } else { retval.add(new NameValuePair(name, value.trim())); } } else { retval.add(new NameValuePair(name, "")); } } } } return retval; }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
private void addTorrentByIntent(Intent intent) { String urlTorrent = intent.getDataString(); if (urlTorrent != null && urlTorrent.length() != 0) { if (urlTorrent.substring(0, 7).equals("content")) { urlTorrent = "file://" + getFilePathFromUri(this, Uri.parse(urlTorrent)); }/* www. j a v a 2 s .co m*/ if (urlTorrent.substring(0, 4).equals("file")) { // File addTorrentFile(Uri.parse(urlTorrent).getPath()); } else { try { addTorrent(Uri.decode(URLEncoder.encode(urlTorrent, "UTF-8"))); } catch (UnsupportedEncodingException e) { Log.e("Debug", "Check URL: " + e.toString()); } } } try { if (intent.getStringExtra("from").equals("NotifierService")) { // drawerList.setItemChecked(2, true); // setTitle(navigationDrawerItemTitles[2]); mRecyclerView.findViewHolderForAdapterPosition(3).itemView.performClick(); refresh("completed"); } } catch (NullPointerException npe) { } }