List of usage examples for java.net URLEncoder encode
public static String encode(String s, Charset charset)
From source file:edu.rit.chrisbitler.ritcraft.slackintegration.rtm.RTMClient.java
/** * Send a slack message to a channel via the web api * @param text The text to send to the channel * @param channel The channel ID to send it to (usually the relay channel) *//* w ww . java 2s. c o m*/ public void sendSlackMessage(String text, String channel) { try { URL chat = new URL("https://slack.com/api/chat.postMessage?token=" + SlackIntegration.BOT_TOKEN + "&channel=" + channel + "&text=" + URLEncoder.encode(text, "UTF-8")); HttpURLConnection conn = (HttpURLConnection) chat.openConnection(); conn.connect(); conn.getContent(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.appdynamics.cloudstack.CloudStackApiClient.java
public String encodeUrl(String value) throws Exception { try {//from ww w .jav a 2 s.c o m if (value != null) { return URLEncoder.encode(value.trim(), "UTF-8").replaceAll("\\+", "%20"); } else { return null; } } catch (Exception e) { throw e; } }
From source file:de.hybris.platform.cuppytrail.forgotpassword.actions.GenerateEmailAction.java
@Override public void executeAction(final ForgotPasswordProcessModel process) throws RetryLaterException, Exception { final PlayerModel player = playerService.getPlayerForEmail(process.getEmailAddress()); final EmailMessageModel message = createEmailMessage(); message.setRecipientAddress(player.getEMail()); final String key = process.getKey(); final String encodedKey = URLEncoder.encode(key, "UTF-8"); final String url = "http://" + domain + "/resetpassword.zul?key=" + encodedKey; message.setSubject(l10nService.getLocalizedString("mail.forgotpassword.subject")); final String body = l10nService.getLocalizedString("mail.forgotpassword.body", new Object[] { player.getName(), url }); message.setBody(body);//from www.j ava 2s .com process.setEmailMessage(message); getModelService().save(process); }
From source file:com.stimulus.archiva.presentation.DownloadMessageBean.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String fileName = request.getParameter("name"); //String fileName = ((MessageBean)form).getOriginalMessageFileName(); logger.debug("download original email {fileName='" + fileName + "'}"); String agent = request.getHeader("USER-AGENT"); if (null != agent && -1 != agent.indexOf("MSIE")) { String codedfilename = URLEncoder.encode(fileName, "UTF8"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else if (null != agent && -1 != agent.indexOf("Mozilla")) { String codedfilename = MimeUtility.encodeText(fileName, "UTF8", "B"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else {/* ww w . j av a2 s .c o m*/ response.setHeader("Content-Disposition", "attachment;filename=" + fileName); } String contentType = "message/rfc822"; //String filePath = ((MessageBean)form).getOriginalMessageFilePath(); String filePath = Config.getFileSystem().getViewPath() + File.separatorChar + fileName; File file = new File(filePath); response.setContentLength((int) file.length()); Config.getFileSystem().getTempFiles().markForDeletion(file); return new FileStreamInfo(contentType, file); }
From source file:vn.chodientu.component.imboclient.util.TextUtils.java
/** * URL-encode the given input string// w ww . jav a 2 s. com * * @param value Input value * @return URL-encoded string */ public static String urlEncode(String value) { try { return URLEncoder.encode(value, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!") .replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")") .replaceAll("\\%7E", "~"); } catch (UnsupportedEncodingException e) { // This really should not happen, but if it does, use the raw value return value; } }
From source file:com.enonic.cms.core.xslt.XsltResource.java
private String getUri() { if (this.name.contains(":/")) { return this.name; }/*from www. j a v a2s .co m*/ try { return "dummy:/" + URLEncoder.encode(this.name, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.wrml.runtime.rest.RestUtils.java
public static final URI encodeUri(final URI uri) { String uriString;//from w w w. j a v a2 s .c o m try { uriString = URLEncoder.encode(uri.toString(), DEFAULT_ENCODING); } catch (final UnsupportedEncodingException e) { return null; } return URI.create(uriString); }
From source file:io.github.retz.protocol.GetFileRequest.java
@Override public String resource() { String encodedFile = file;//from ww w .ja v a2 s.co m try { encodedFile = URLEncoder.encode(file, "UTF-8"); } catch (UnsupportedEncodingException e) { } StringBuilder builder = new StringBuilder("/job/").append(id).append("/file").append("?path=") .append(encodedFile).append("&offset=").append(offset).append("&length=").append(length); return builder.toString(); }
From source file:com.lyncode.jtwig.functions.internal.string.UrlEncode.java
private String encode(String value) throws FunctionException { try {/*from w w w . java 2 s . c o m*/ return URLEncoder.encode(value, Charset.defaultCharset().displayName()); } catch (UnsupportedEncodingException e) { throw new FunctionException(e); } }
From source file:com.dss886.nForumSDK.service.SearchService.java
/** * ??/* w ww . ja v a2 s. c om*/ * ????utf-8 * @param keyword ???? * @return ? * @throws JSONException * @throws NForumException * @throws IOException */ public Search searchBoard(String keyword) throws JSONException, NForumException, IOException { String board = URLEncoder.encode(keyword, "GBK"); ParamOption params = new ParamOption().addParams("board", board); String url = host + "search/board" + returnFormat + appkey + params; GetMethod getMethod = new GetMethod(httpClient, auth, url); return Search.parse(getMethod.getJSON()); }