List of usage examples for org.springframework.web.util JavaScriptUtils javaScriptEscape
public static String javaScriptEscape(String input)
From source file:com.fengduo.bee.commons.util.StringEscapeEditor.java
@Override public void setAsText(String text) throws IllegalArgumentException { if (text == null) { setValue(null);//from ww w .j a v a 2 s . c o m } else { String value = text; if (escapeHTML) { value = HtmlUtils.htmlEscape(value); } if (escapeJavaScript) { value = JavaScriptUtils.javaScriptEscape(value); } setValue(value); } }
From source file:org.openmrs.module.metadatasharing.web.taglib.PrintJavaScriptTag.java
/** * @see javax.servlet.jsp.tagext.SimpleTag#doTag() *///from w w w . j ava 2 s .co m @Override public void doTag() throws JspException, IOException { String output; if (text == null || (text == "" && asString == false)) { output = "null"; } else { output = HtmlUtils.htmlEscape(JavaScriptUtils.javaScriptEscape(text)); if (asString == true) { output = "'" + output + "'"; } } getJspContext().getOut().print(output); }
From source file:org.openmrs.module.metadatasharing.web.taglib.PrintCollectionJavaScriptTag.java
/** * @see javax.servlet.jsp.tagext.SimpleTag#doTag() *//* w w w . j a va2s . com*/ @Override public void doTag() throws JspException, IOException { StringBuilder buffer = new StringBuilder(); if (var == null) { buffer.append("null"); } else { buffer.append("["); for (Object obj : var) { String str = HtmlUtils.htmlEscape(JavaScriptUtils.javaScriptEscape(obj.toString())); if (asString == true) buffer.append("'"); buffer.append(str); if (asString == true) buffer.append("'"); buffer.append(","); } buffer.deleteCharAt(buffer.length() - 1); buffer.append("]"); } getJspContext().getOut().print(buffer.toString()); }
From source file:com.gradecak.alfresco.mvc.JsonExceptionResolver.java
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {//from w w w . ja v a 2 s .c o m LOGGER.error("Error occurred for handler [" + handler + "]", ex); View view = new MappingJacksonJsonView(); Map<String, Object> res = new HashMap<String, Object>(); res.put("success", false); Map<String, Object> protocol = new HashMap<String, Object>(); protocol.put("event", "exception"); Map<String, Object> data = new HashMap<String, Object>(); data.put("exception", ex.getClass()); data.put("message", JavaScriptUtils.javaScriptEscape(ex.getMessage())); protocol.put("data", data); res.put("protocol", protocol); return new ModelAndView(view, res); }
From source file:se.softhouse.garden.orchid.spring.tags.OrchidMessageTag.java
@Override public int doEndTag() throws JspException { // Resolve the unescaped message. String msg = resolveMessage(); // HTML and/or JavaScript escape, if demanded. msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg; msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg; // Expose as variable, if demanded, else write to the page. String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, this.pageContext); if (resolvedVar != null) { String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, this.pageContext); this.pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope)); } else {/*w w w.ja va2 s .com*/ writeMessage(msg); } return EVAL_PAGE; }
From source file:com.gradecak.alfresco.mvc.webscript.DispatcherWebscript.java
private void convertExceptionToJson(Exception ex, HttpServletResponse res) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> params = new HashMap<String, Object>(); params.put("success", false); params.put("event", "exception"); params.put("exception", ex.getClass()); params.put("message", JavaScriptUtils.javaScriptEscape(ex.getMessage())); if (ex instanceof NestedServletException) { NestedServletException nestedServletException = (NestedServletException) ex; if (nestedServletException.getCause() != null) { params.put("cause", nestedServletException.getCause().getClass()); params.put("causeMessage", nestedServletException.getCause().getMessage()); }//from w w w . ja v a2 s. co m } objectMapper.writeValue(res.getOutputStream(), params); }
From source file:org.lanark.jsr303js.ValidationJavaScriptGenerator.java
protected void appendJsString(String string) throws IOException { writer.write('\''); if (string == null) { writer.write("null"); } else {/* w ww .ja v a 2 s . c o m*/ writer.write(JavaScriptUtils.javaScriptEscape(string)); } writer.write('\''); }
From source file:com.seajas.search.utilities.tags.MessageTag.java
/** * Put the actual internal processing in here. * //from w ww .j a v a2 s .com * @return * @throws JspException */ @Override public int doEndTag() throws JspException { try { // Resolve the unescaped message. String msg = resolveMessage(); // HTML and/or JavaScript escape, if demanded. msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg; msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg; // Expose as variable, if demanded, else write to the page. String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext); if (resolvedVar != null) { String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext); pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope)); } else { try { writeMessage(msg); } catch (IOException e) { throw new JspException(e); } } return super.doAfterBody(); } catch (NoSuchMessageException ex) { throw new JspTagException(getNoSuchMessageExceptionDescription(ex)); } }
From source file:com.ei.itop.common.tag.MessageTag.java
/** * Resolves the message, escapes it if demanded, * and writes it to the page (or exposes it as variable). * @see #resolveMessage()/* w ww. ja v a 2s.c o m*/ * @see org.springframework.web.util.HtmlUtils#htmlEscape(String) * @see org.springframework.web.util.JavaScriptUtils#javaScriptEscape(String) * @see #writeMessage(String) */ @Override protected final int doStartTagInternal() throws JspException, IOException { try { // Resolve the unescaped message. String msg = resolveMessage(); // HTML and/or JavaScript escape, if demanded. msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg; msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg; // Expose as variable, if demanded, else write to the page. String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext); if (resolvedVar != null) { String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext); pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope)); } else { writeMessage(msg); } return EVAL_BODY_INCLUDE; } catch (NoSuchMessageException ex) { throw new JspTagException(getNoSuchMessageExceptionDescription(ex)); } }
From source file:org.hdiv.web.servlet.tags.UrlTagHDIV.java
/** * Build the URL for the tag from the tag attributes and parameters. * @return the URL value as a String//w w w. ja v a2s . c om * @throws JspException */ private String createUrl() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); StringBuilder url = new StringBuilder(); if (this.type == UrlType.CONTEXT_RELATIVE) { // add application context to url if (this.context == null) { url.append(request.getContextPath()); } else { url.append(this.context); } } if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) { url.append("/"); } url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams)); url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1))); String urlStr = url.toString(); urlStr = HDIVRequestUtils.composeLinkUrl(urlStr, request); // HDIVConfig hdivConfig = (HDIVConfig) HDIVUtil.getHDIVConfig(pageContext.getServletContext()); // // if (!HDIVRequestUtils.hasExtensionToExclude(urlStr, hdivConfig.getExcludedURLExtensions())) // { // if (HDIVRequestUtils.hasActionOrServletExtension(urlStr, hdivConfig.getProtectedURLPatterns())) { // urlStr = HDIVRequestUtils.addHDIVParameterIfNecessary((HttpServletRequest) pageContext.getRequest(), // urlStr, hdivConfig.isValidationInUrlsWithoutParamsActivated()); // } // } if (this.type != UrlType.ABSOLUTE) { // Add the session identifier if needed // (Do not embed the session identifier in a remote link!) urlStr = response.encodeURL(urlStr); } // HTML and/or JavaScript escape, if demanded. urlStr = isHtmlEscape() ? HtmlUtils.htmlEscape(urlStr) : urlStr; urlStr = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr; return urlStr; }