List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeEcmaScript
public static final String escapeEcmaScript(final String input)
Escapes the characters in a String using EcmaScript String rules.
Escapes any values it finds into their EcmaScript String form.
From source file:com.goody.backend.entities.Todo.java
/** * Escape any HTML and Javascript/*from www.j av a 2 s.c o m*/ */ public void cleanTitle() { this.title = StringEscapeUtils.escapeHtml4(StringEscapeUtils.escapeEcmaScript(this.title)); }
From source file:com.lyncode.jtwig.functions.builtin.StringFunctions.java
@JtwigFunction(name = "escape", aliases = { "e" }) public String escape(@Parameter String input, @Parameter String strategy) throws FunctionException { switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) { case HTML: return StringEscapeUtils.escapeHtml4(input); case JAVASCRIPT: return StringEscapeUtils.escapeEcmaScript(input); case XML:/*from www . j av a2 s . co m*/ return StringEscapeUtils.escapeXml(input); default: throw new FunctionException("Unknown escaping strategy " + strategy); } }
From source file:fr.mcc.ginco.rest.services.exceptions.AbstractExceptionMapper.java
protected Response toResponse(Throwable t, String messageKey, Object[] toFormat) { String msg;/*from w w w .jav a 2 s. com*/ if (toFormat != null) { msg = MessageFormat.format(LabelUtil.getResourceLabel(messageKey), toFormat); } else { msg = LabelUtil.getResourceLabel(messageKey); } logger.error("Exception in REST services : " + t.getMessage()); logger.debug("Exception in REST services : " + msg); msg = StringEscapeUtils.escapeEcmaScript(msg); return Response.status(Status.OK).entity("{\"success\":false, \"message\": \"" + msg + "\"}").build(); }
From source file:com.msopentech.thali.utilities.webviewbridge.BridgeManager.java
/** * However this method is implemented it MUST be thread safe. * @param handlerName/*from w w w. jav a 2s. c o m*/ * */ public void callBack(String handlerName, String jsonString) { String functionCall = callbackManager + "[\"" + handlerName + "\"]('" + StringEscapeUtils.escapeEcmaScript(jsonString) + "')"; this.executeJavascript(functionCall); }
From source file:com.netsteadfast.greenstep.action.RolePermittedManagementAction.java
private void init() throws ServiceException, Exception { this.permTypeMap.put(Constants.HTML_SELECT_NO_SELECT_ID, StringEscapeUtils.escapeEcmaScript(PleaseSelect.getLabel(this.getLocaleLang()))); this.permTypeMap.put("CONTROLLER", "Controller"); this.permTypeMap.put("COMPOMENT", "Compoment"); }
From source file:com.opensymphony.xwork3.DefaultActionProxy.java
/** * This constructor is private so the builder methods (create*) should be used to create an DefaultActionProxy. * <p/>/*from w w w.j a v a 2 s. c o m*/ * The reason for the builder methods is so that you can use a subclass to create your own DefaultActionProxy instance * (like a RMIActionProxy). */ protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean cleanupContext) { this.invocation = inv; this.cleanupContext = cleanupContext; if (LOG.isDebugEnabled()) { LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", namespace, actionName); } this.actionName = StringEscapeUtils.escapeHtml4(actionName); this.namespace = namespace; // this.executeResult = executeResult; this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName)); }
From source file:edu.psu.swe.scim.spec.protocol.filter.AttributeComparisonExpression.java
private String createCompareValueString() { String compareValueString;/*from w ww.j av a 2 s. c om*/ if (this.compareValue == null) { compareValueString = "null"; } else if (this.compareValue instanceof String) { // TODO change this to escapeJson() when dependencies get upgraded String escaped = StringEscapeUtils.escapeEcmaScript((String) this.compareValue) // StringEscapeUtils follows the outdated JSON spec requiring "/" to be escaped, this could subtly break things .replaceAll("\\\\/", "/") // We don't want single-quotes escaped, this will be unnecessary with escapeJson() .replaceAll("\\\\'", "'"); compareValueString = QUOTE + escaped + QUOTE; } else if (this.compareValue instanceof Date) { compareValueString = QUOTE + toDateTimeString((Date) this.compareValue) + QUOTE; } else if (this.compareValue instanceof LocalDate) { compareValueString = QUOTE + toDateString((LocalDate) this.compareValue) + QUOTE; } else if (this.compareValue instanceof LocalDateTime) { compareValueString = QUOTE + toDateTimeString((LocalDateTime) this.compareValue) + QUOTE; } else { compareValueString = this.compareValue.toString(); } return compareValueString; }
From source file:cloudlens.engine.CLIterator.java
public static CLIterator json(BlockEngine engine, InputStream inputStream, String path, boolean withHistory) { try {// w w w. j a v a 2s .c o m final InputStreamReader isr = new InputStreamReader(inputStream); final BufferedReader rd = new BufferedReader(isr); String line; final StringBuilder sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } final String s = StringEscapeUtils.escapeEcmaScript(sb.toString()); try { final String jsonPath = (path == null) ? "" : "." + path; final BlockObject jsStream = engine.eval("JSON.parse(\"" + s + "\")" + jsonPath); if (!engine.isArray(jsStream)) { throw new BlockException("Parse Error: the log stream " + path + " must be a json Array"); } final CLIterator res = new CLIterator(engine, jsStream.asList(), withHistory); if (withHistory) { res.iterate(); } return res; } catch (final BlockException e) { throw new CLException(e.getMessage()); } } catch (final IOException e) { throw new CLException(e.getMessage()); } }
From source file:com.opensymphony.xwork2.DefaultActionProxy.java
/** * This constructor is private so the builder methods (create*) should be used to create an DefaultActionProxy. * <p/>/* w ww . ja v a2s. c om*/ * The reason for the builder methods is so that you can use a subclass to create your own DefaultActionProxy instance * (like a RMIActionProxy). */ protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) { this.invocation = inv; this.cleanupContext = cleanupContext; if (LOG.isDebugEnabled()) { LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", namespace, actionName); } this.actionName = StringEscapeUtils.escapeHtml4(actionName); this.namespace = namespace; this.executeResult = executeResult; this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName)); }
From source file:de.elbe5.base.util.StringUtil.java
public static String toJs(String src) { if (src == null) { return ""; }/* w w w. java2 s . c o m*/ return StringEscapeUtils.escapeEcmaScript(src); }