List of usage examples for org.apache.commons.codec.net URLCodec URLCodec
public URLCodec(String charset)
From source file:corner.orm.tapestry.utils.ComponentResponseUtils.java
private static String processFileName(String fileName, String agent) throws IOException { String codedfilename = fileName; if (null != agent && -1 != agent.indexOf("MSIE")) {// IE //apachecodeC?: //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6437829 URLCodec codec = new URLCodec("UTF-8"); try {//from www . jav a2s . c o m codedfilename = codec.encode(fileName); } catch (EncoderException e) { log.warn(e); } } else if (null != agent && -1 != agent.indexOf("Mozilla")) { // Mozilla // firefox codedfilename = String.format(MOZILLA_DOWNLOAD_FILE_NAME, new String(Base64.encodeBase64(fileName.getBytes("UTF-8")))); } return codedfilename; }
From source file:de.schneider.dev.poi.service.OpenStreetMapGeoService.java
public void getGeoCoordinate(String location) throws EncoderException { LOG.info("Start GeoCoordination OpenStreetMap"); // create default HttpClient HttpClient httpClient = new DefaultHttpClient(); // get data from URI URLCodec urlCodec = new URLCodec("UTF-8"); HttpGet httpGet = new HttpGet(URI_String + urlCodec.encode(location) + "&format=json"); LOG.info("HttpGet: " + httpGet); LOG.debug(httpGet.toString());/*from w w w.j ava 2 s. c o m*/ LOG.debug("HttpGetURI: " + httpGet.getURI()); // get response try { HttpResponse httpResponse = httpClient.execute(httpGet); LOG.info("HttpResponse: " + httpResponse); LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode()); LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase()); HttpEntity httpEntity = httpResponse.getEntity(); LOG.info("HttpEntity: " + httpEntity); LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming()); if (httpEntity.isStreaming()) { InputStream inputStream = httpEntity.getContent(); String content = EntityUtils.toString(httpEntity); LOG.info(content); inputStream.close(); } } catch (ClientProtocolException cpe) { LOG.error(cpe.getMessage()); } catch (IOException ioe) { LOG.error(ioe.getMessage()); } }
From source file:de.schneider.dev.poi.service.GoogleMapGeoService.java
public void getGeoCoordinate(String location) throws EncoderException { LOG.info("Start GeoCoordination Google Map"); // create default HttpClient HttpClient httpClient = new DefaultHttpClient(); // get data from URI URLCodec urlCodec = new URLCodec("UTF-8"); HttpGet httpGet = new HttpGet(DEFAULT_JSON_URI + urlCodec.encode(location) + "&sensor=false"); LOG.info("HttpGet: " + httpGet); // get response try {//from w ww . j ava 2 s . c om HttpResponse httpResponse = httpClient.execute(httpGet); LOG.info("HttpResponse: " + httpResponse); LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode()); LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase()); HttpEntity httpEntity = httpResponse.getEntity(); LOG.info("HttpEntity: " + httpEntity); LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming()); if (httpEntity.isStreaming()) { InputStream inputStream = httpEntity.getContent(); String content = EntityUtils.toString(httpEntity); LOG.info(content); inputStream.close(); } } catch (ClientProtocolException cpe) { LOG.error(cpe.toString()); } catch (IOException ioe) { LOG.error(ioe.toString()); } }
From source file:org.beanfuse.utils.web.CookieUtils.java
/** * ?cookievalue<br>// w ww . j av a2 s . c o m * ?<br> * * @param request * @param cookieName * @return */ public static String getCookieValue(HttpServletRequest request, String cookieName) { try { Cookie cookie = getCookie(request, cookieName); if (null == cookie) { return null; } else { return new URLCodec("utf-8").decode(cookie.getValue()); } } catch (Exception e) { return null; } }
From source file:org.callimachusproject.xproc.DecodeTextStep.java
private String decodeText(XdmNode source_read) throws UnsupportedEncodingException, DecoderException { String text = extractText(source_read); if ("base64".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); }//ww w . j av a 2 s. com byte[] decoded = Base64.decodeBase64(text); return new String(decoded, charset); } else if ("base32".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = new Base32().decode(text); return new String(decoded, charset); } else if ("hex".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = Hex.decodeHex(text.toCharArray()); return new String(decoded, charset); } else if ("binary".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = BinaryCodec.fromAscii(text.toCharArray()); return new String(decoded, charset); } else if ("quoted-printable".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new QuotedPrintableCodec(charset).decode(text); } else if ("www-form-urlencoded".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new URLCodec(charset).decode(text); } else if (encoding != null && encoding.length() != 0) { throw new XProcException(step.getNode(), "Unexpected encoding: " + encoding); } else { return text; } }
From source file:org.callimachusproject.xproc.DeserializeCascadingStyleSheetStep.java
private String decodeText(XdmNode doc) throws UnsupportedEncodingException, DecoderException { String text = extractText(doc); if ("base64".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); }//from w w w . j a v a2s .c om byte[] decoded = Base64.decodeBase64(text); return new String(decoded, charset); } else if ("base32".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = new Base32().decode(text); return new String(decoded, charset); } else if ("hex".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = Hex.decodeHex(text.toCharArray()); return new String(decoded, charset); } else if ("binary".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = BinaryCodec.fromAscii(text.toCharArray()); return new String(decoded, charset); } else if ("quoted-printable".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new QuotedPrintableCodec(charset).decode(text); } else if ("www-form-urlencoded".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new URLCodec(charset).decode(text); } else if (encoding != null && encoding.length() != 0) { throw new XProcException(step.getNode(), "Unexpected encoding: " + encoding); } else { return text; } }
From source file:org.kuali.rice.krad.util.KRADUtils.java
/** * Generate the request parameter portion of the url based on the map of key value pairs passed in * * @param requestParameters the request parameters to use in the string * @return a request parameter string starting with "?" with "&" separators, or blank if the mapped passed in is * blank// w ww .jav a 2 s .c o m */ public static String getRequestStringFromMap(Map<String, String> requestParameters) { String requestString = ""; if (requestParameters.isEmpty()) { return requestString; } URLCodec urlCodec = new URLCodec(KRADConstants.DEFAULT_ENCODING); for (String key : requestParameters.keySet()) { String value = null; try { value = urlCodec.encode(requestParameters.get(key)); } catch (EncoderException e) { throw new RuntimeException("Unable to encode parameter name or value: " + key + "=" + value, e); } if (StringUtils.isNotBlank(requestString)) { requestString = requestString + "&"; } requestString = requestString + key + "=" + value; } return "?" + requestString; }
From source file:org.mule.module.pubsubhubbub.Utils.java
private static void addQueryStringToParameterMap(final String queryString, final Map<String, List<String>> paramMap, final String outputEncoding) throws DecoderException { final String[] pairs = queryString.split("&"); for (final String pair : pairs) { final String[] nameValue = pair.split("="); if (nameValue.length == 2) { final URLCodec codec = new URLCodec(outputEncoding); final String key = codec.decode(nameValue[0]); final String value = codec.decode(nameValue[1]); addToParameterMap(paramMap, key, value); }/*ww w .j a va 2 s . c o m*/ } }
From source file:org.mule.transport.http.transformers.HttpRequestBodyToParamMap.java
protected void addQueryStringToParameterMap(String queryString, Map<String, Object> paramMap, String outputEncoding) throws Exception { String[] pairs = queryString.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("="); if (nameValue.length == 2) { URLCodec codec = new URLCodec(outputEncoding); String key = codec.decode(nameValue[0]); String value = codec.decode(nameValue[1]); addToParameterMap(paramMap, key, value); }/*w w w. j a v a2 s . com*/ } }