Java Code Examples for org.apache.commons.text.StringEscapeUtils#escapeEcmaScript()
The following examples show how to use
org.apache.commons.text.StringEscapeUtils#escapeEcmaScript() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BootstrapFeedbackPopover.java From pm-wicket-utils with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void renderHead(IHeaderResponse response) { super.renderHead(response); List<FeedbackMessage> msgs = model.getObject(); if(msgs.size()>0){ for(Component component: messages.keySet()){ StringBuffer sb = new StringBuffer(); for(FeedbackMessage msg : messages.get(component)){ sb.append(msg.getMessage()+"\n"); msg.markRendered(); } String script = "$(\"#"+component.getMarkupId()+"\")" + ".popover({ 'trigger': 'focus', " + "'placement': 'top', " + "'content': \""+StringEscapeUtils.escapeEcmaScript(sb.toString())+"\", " + "'template': '<div class=\"popover feedback-popover\"><div class=\"arrow\"></div><div class=\"popover-inner\"><h3 class=\"popover-title\"></h3><div class=\"popover-content\"><p></p></div></div></div>'" + "});"; script += "$(\"#"+component.getMarkupId()+"\").keypress(function(){ $(\"#"+this.getMarkupId()+"\").removeClass('has-error'); $(this).popover('destroy'); });"; response.render(OnDomReadyHeaderItem.forScript(script)); } } }
Example 2
Source File: AgnMessageTag.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private String escape(String message) throws JspException { switch (resolveEscapeMode()) { case ESCAPE_MODE_HTML: return Functions.escapeXml(message); case ESCAPE_MODE_JS: return StringEscapeUtils.escapeEcmaScript(message); default: return message; } }
Example 3
Source File: MarkdownEditor.java From onedev with MIT License | 5 votes |
@Override public void renderHead(IHeaderResponse response) { super.renderHead(response); response.render(JavaScriptHeaderItem.forReference(new MarkdownResourceReference())); String encodedAttachmentSupport; if (getAttachmentSupport() != null) { encodedAttachmentSupport = Base64.encodeBase64String(SerializationUtils.serialize(getAttachmentSupport())); encodedAttachmentSupport = StringUtils.deleteWhitespace(encodedAttachmentSupport); encodedAttachmentSupport = StringEscapeUtils.escapeEcmaScript(encodedAttachmentSupport); encodedAttachmentSupport = "'" + encodedAttachmentSupport + "'"; } else { encodedAttachmentSupport = "undefined"; } String callback = ajaxBehavior.getCallbackFunction(explicit("action"), explicit("param1"), explicit("param2"), explicit("param3")).toString(); String autosaveKey = getAutosaveKey(); if (autosaveKey != null) autosaveKey = "'" + JavaScriptEscape.escapeJavaScript(autosaveKey) + "'"; else autosaveKey = "undefined"; String script = String.format("onedev.server.markdown.onDomReady('%s', %s, %d, %s, %d, %b, %b, '%s', %s);", container.getMarkupId(), callback, ATWHO_LIMIT, encodedAttachmentSupport, getAttachmentSupport()!=null?getAttachmentSupport().getAttachmentMaxSize():0, getUserMentionSupport() != null, getReferenceSupport() != null, JavaScriptEscape.escapeJavaScript(ProjectNameValidator.PATTERN.pattern()), autosaveKey); response.render(OnDomReadyHeaderItem.forScript(script)); script = String.format("onedev.server.markdown.onWindowLoad('%s');", container.getMarkupId()); response.render(OnLoadHeaderItem.forScript(script)); }
Example 4
Source File: LinkTrackerProducer.java From sakai with Educational Community License v2.0 | 5 votes |
public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) { TrackerViewParameters params = (TrackerViewParameters) viewparams; if (!simplePageBean.canReadPage()) return; UIOutput.make(tofill, "html").decorate(new UIFreeAttributeDecorator("lang", localeGetter.get().getLanguage())) .decorate(new UIFreeAttributeDecorator("xml:lang", localeGetter.get().getLanguage())); Long itemId = params.getItemId(); SimplePageItem i = simplePageToolDao.findItem(itemId); SimplePage page = simplePageBean.getCurrentPage(); if (i.getPageId() != page.getPageId()) { log.info("LinkTracker asked to track item not in current page"); return; } if (i != null && simplePageBean.isItemAvailable(i)) { simplePageBean.track(itemId, null); String URL = params.getURL(); if (lessonBuilderAccessService.needsCopyright(i.getSakaiId())) URL = "/access/require?ref=" + URLEncoder.encode("/content" + i.getSakaiId()) + "&url=" + URLEncoder.encode(URL.substring(7)); String js = "window.location = \"" + StringEscapeUtils.escapeEcmaScript(URL) + "\""; if (params.getRefresh()) js = "window.top.opener.location.reload(true);" + js; UIVerbatim.make(tofill, "redirect", js); } else { UIOutput.make(tofill, "error", messageLocator.getMessage("simplepage.error")); UIOutput.make(tofill, "errormsg", messageLocator.getMessage("simplepage.complete_required")); } }
Example 5
Source File: HttpBindServlet.java From Openfire with Apache License 2.0 | 5 votes |
public static void respond(HttpSession session, AsyncContext context, String content, boolean async) throws IOException { final HttpServletResponse response = ((HttpServletResponse) context.getResponse()); final HttpServletRequest request = ((HttpServletRequest) context.getRequest()); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("GET".equals(request.getMethod()) ? "text/javascript" : "text/xml"); response.setCharacterEncoding("UTF-8"); if ("GET".equals(request.getMethod())) { if (JiveGlobals.getBooleanProperty("xmpp.httpbind.client.no-cache.enabled", true)) { // Prevent caching of responses response.addHeader("Cache-Control", "no-store"); response.addHeader("Cache-Control", "no-cache"); response.addHeader("Pragma", "no-cache"); } content = "_BOSH_(\"" + StringEscapeUtils.escapeEcmaScript(content) + "\")"; } if (JiveGlobals.getBooleanProperty("log.httpbind.enabled", false)) { Log.info("HTTP SENT(" + session.getStreamID().getID() + "): " + content); } final byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); // BOSH communication should not use Chunked encoding. // This is prevented by explicitly setting the Content-Length header. response.setContentLength(byteContent.length); if (async) { response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent)); } else { context.getResponse().getOutputStream().write(byteContent); context.getResponse().getOutputStream().flush(); context.complete(); } }
Example 6
Source File: LinkTrackerProducer.java From sakai with Educational Community License v2.0 | 5 votes |
public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) { TrackerViewParameters params = (TrackerViewParameters) viewparams; if (!simplePageBean.canReadPage()) return; UIOutput.make(tofill, "html").decorate(new UIFreeAttributeDecorator("lang", localeGetter.get().getLanguage())) .decorate(new UIFreeAttributeDecorator("xml:lang", localeGetter.get().getLanguage())); Long itemId = params.getItemId(); SimplePageItem i = simplePageToolDao.findItem(itemId); SimplePage page = simplePageBean.getCurrentPage(); if (i.getPageId() != page.getPageId()) { log.info("LinkTracker asked to track item not in current page"); return; } if (i != null && simplePageBean.isItemAvailable(i)) { simplePageBean.track(itemId, null); String URL = params.getURL(); if (lessonBuilderAccessService.needsCopyright(i.getSakaiId())) URL = "/access/require?ref=" + URLEncoder.encode("/content" + i.getSakaiId()) + "&url=" + URLEncoder.encode(URL.substring(7)); String js = "window.location = \"" + StringEscapeUtils.escapeEcmaScript(URL) + "\""; if (params.getRefresh()) js = "window.top.opener.location.reload(true);" + js; UIVerbatim.make(tofill, "redirect", js); } else { UIOutput.make(tofill, "error", messageLocator.getMessage("simplepage.error")); UIOutput.make(tofill, "errormsg", messageLocator.getMessage("simplepage.complete_required")); } }
Example 7
Source File: StatisticsReportingStorage.java From sailfish-core with Apache License 2.0 | 4 votes |
@Override public Map<Long, List<ActionInfoRow>> generateTestCasesFailedActionsInfo(AggregateReportParameters params) { if (params.getTestCaseRunIds() == null || params.getTestCaseRunIds().isEmpty()) { return Collections.emptyMap(); } String queryString = "select " + "TCR.id, " + "AR.rank, " + "AR.description, " + "AR.failReason, " + "A.name, " + "M.name, " + "S.name, " + "AR.tag, " + "AR.status, " + "AR.hash " + "from ActionRun as AR " + "join AR.tcRun as TCR " + "left join AR.action as A " + "left join AR.service as S " + "left join AR.msgType as M " + "where TCR.id in (:tcrIds) and AR.status = 0 " + "order by AR.rank"; Session session = sessionFactory.openSession(); try (AutoCloseable ignore = session::close) { Query query = session.createQuery(queryString); query.setParameterList("ids", params.getTestCaseRunIds()); @SuppressWarnings("unchecked") List<Object[]> resultList = query.list(); Map<Long, List<ActionInfoRow>> testCaseToActionInfo = new HashMap<>(); for (Object[] resultRow : resultList) { Long tcrId = (Long) resultRow[0]; long rank = (long) resultRow[1]; //TODO: Remove escaping after release 3.1, because escaping is executed on save data String description = StringEscapeUtils.escapeEcmaScript((String) resultRow[2]); String failReason = (String) resultRow[3]; String actionName = (String) resultRow[4]; String msgType = (String) resultRow[5]; String service = (String) resultRow[6]; String tag = (String) resultRow[7]; Integer status = (Integer) resultRow[8]; Integer hash = (Integer) resultRow[9]; testCaseToActionInfo.computeIfAbsent(tcrId, id -> new ArrayList<>()) .add(new ActionInfoRow(rank, description, failReason, actionName, msgType, service, tag, status, hash)); } return testCaseToActionInfo; } catch (Exception e) { throw new EPSCommonException(e); } }
Example 8
Source File: FormattedTextImpl.java From sakai with Educational Community License v2.0 | 4 votes |
public String escapeJsQuoted(String value) { return StringEscapeUtils.escapeEcmaScript(value); }
Example 9
Source File: PrivateMessagesTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String getPlacementId() { return StringEscapeUtils.escapeEcmaScript("Main" + toolManager.getCurrentPlacement().getId()); }
Example 10
Source File: FormattedTextImpl.java From sakai with Educational Community License v2.0 | 4 votes |
public String escapeJsQuoted(String value) { return StringEscapeUtils.escapeEcmaScript(value); }
Example 11
Source File: PrivateMessagesTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String getPlacementId() { return StringEscapeUtils.escapeEcmaScript("Main" + toolManager.getCurrentPlacement().getId()); }
Example 12
Source File: Encoder.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * JavaScript-escaped the given String. * @param object the String. * @return a JavaScript-escaped representation. */ public String jsEncode( String object ) { return StringEscapeUtils.escapeEcmaScript( object ); }
Example 13
Source File: Utils.java From para with Apache License 2.0 | 2 votes |
/** * Escapes JavaScript. * @param str a javascript string * @return the escaped javascript string */ public static String escapeJavascript(String str) { return (str == null) ? "" : StringEscapeUtils.escapeEcmaScript(str); }