本文整理了Java中org.apache.commons.text.StringEscapeUtils.escapeEcmaScript()
方法的一些代码示例,展示了StringEscapeUtils.escapeEcmaScript()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeEcmaScript()
方法的具体详情如下:
包路径:org.apache.commons.text.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeEcmaScript
暂无
代码示例来源:origin: igniterealtime/Openfire
response.addHeader("Pragma", "no-cache");
content = "_BOSH_(\"" + StringEscapeUtils.escapeEcmaScript(content) + "\")";
代码示例来源:origin: org.apache.commons/commons-text
/**
* Tests https://issues.apache.org/jira/browse/LANG-708
*
* @throws IOException
* if an I/O error occurs
*/
@Test
public void testLang708() throws IOException {
final byte[] inputBytes = Files.readAllBytes(Paths.get("src/test/resources/stringEscapeUtilsTestData.txt"));
final String input = new String(inputBytes, StandardCharsets.UTF_8);
final String escaped = StringEscapeUtils.escapeEcmaScript(input);
// just the end:
assertTrue(escaped.endsWith("}]"), escaped);
// a little more:
assertTrue(escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"), escaped);
}
代码示例来源:origin: Erudika/para
/**
* Escapes JavaScript.
* @param str a javascript string
* @return the escaped javascript string
*/
public static String escapeJavascript(String str) {
return (str == null) ? "" : StringEscapeUtils.escapeEcmaScript(str);
}
代码示例来源:origin: dhis2/dhis2-core
/**
* JavaScript-escaped the given String.
* @param object the String.
* @return a JavaScript-escaped representation.
*/
public String jsEncode( String object )
{
return StringEscapeUtils.escapeEcmaScript( object );
}
代码示例来源:origin: pwm-project/pwm
public static String escapeJS( final String input )
{
return StringEscapeUtils.escapeEcmaScript( input );
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testEscapeEcmaScript() {
assertNull(StringEscapeUtils.escapeEcmaScript(null));
try {
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null);
fail("Exception expected!");
} catch (final IOException ex) {
fail("Exception expected!");
} catch (final IllegalArgumentException ex) {
}
try {
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null);
fail("Exception expected!");
} catch (final IOException ex) {
fail("Exception expected!");
} catch (final IllegalArgumentException ex) {
}
assertEquals("He didn\\'t say, \\\"stop!\\\"", StringEscapeUtils.escapeEcmaScript("He didn't say, \"stop!\""));
assertEquals("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';",
StringEscapeUtils.escapeEcmaScript(
"document.getElementById(\"test\").value = '<script>alert('aaa');</script>';"));
}
代码示例来源:origin: theonedev/onedev
@Override
public CharSequence getPrecondition(Component component) {
return String.format("return confirm('%s');", StringEscapeUtils.escapeEcmaScript(message));
}
代码示例来源:origin: theonedev/onedev
public ConfirmOnClick(String message) {
super("onclick", String.format("return confirm('%s');", StringEscapeUtils.escapeEcmaScript(message)));
}
代码示例来源:origin: vmi/selenese-runner-java
@Override
public void mutate(Context context, String script, StringBuilder outputTo) {
if (pattern.matcher(script).find()) {
String value = dynamicValue.apply(context);
outputTo.append(declaration).append(StringEscapeUtils.escapeEcmaScript(value)).append("';");
}
}
}
代码示例来源:origin: theonedev/onedev
public void insertUrl(AjaxRequestTarget target, boolean isImage, String url,
String name, @Nullable String replaceMessage) {
String script = String.format("onedev.server.markdown.insertUrl('%s', %s, '%s', '%s', %s);",
container.getMarkupId(), isImage, StringEscapeUtils.escapeEcmaScript(url),
StringEscapeUtils.escapeEcmaScript(name),
replaceMessage!=null?"'"+replaceMessage+"'":"undefined");
target.appendJavaScript(script);
}
代码示例来源:origin: theonedev/onedev
@Override
public CharSequence getPrecondition(Component component) {
if (path != null) {
return String.format("return onedev.server.searchResult.confirmSwitchFileByPath('%s', %b);",
StringEscapeUtils.escapeEcmaScript(path), hasMark);
} else {
return String.format("return onedev.server.searchResult.confirmSwitchFileByLink('%s');",
component.getMarkupId(true));
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-router
private static String escape(String str) {
return escapeEcmaScript(escapeHtml4(str));
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common
/**
* Print strings escaping html.
* @param args the strings to print
*/
public void echo(Object... args) {
PrintWriter out = writer();
for (Object s : args) {
String escapedString = StringEscapeUtils.escapeEcmaScript(
StringEscapeUtils.escapeHtml4(s.toString()));
out.print(escapedString);
}
}
代码示例来源:origin: angular/clutz
/**
* Collect all literalInitializations with string literal values in the enum. Later we use these
* literal initializers to complete the type alias.
*/
private Set<String> collectAllLiterals(Map<String, Node> elements) {
Set<String> literalInitializers = new HashSet<>();
for (Node n : elements.values()) {
if (n.isString()) {
literalInitializers.add(escapeEcmaScript(n.getString()));
}
}
return literalInitializers;
}
代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-convert
protected Blob createIndexBlob() {
StringBuilder page = new StringBuilder("<html><body>");
page.append("<h1>")
.append(StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(zipBlob.getFilename())))
.append("</h1>");
page.append("<ul>");
for (Blob blob : blobs) {
String fn = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(blob.getFilename()));
page.append("<li><a href=\"").append(fn).append("\">");
page.append(fn);
page.append("</a></li>");
}
page.append("</ul></body></html>");
return Blobs.createBlob(page.toString());
}
}
代码示例来源:origin: com.premiumminds/pm-wicket-utils
@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));
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common
protected void initDialogs(List<String> list) {
String defaultInit = "{autoOpen: false, show: transfer, hide: explode}";
for (String id : split($(DIALOG_ID))) {
if (Html.isValidId(id)) {
String init = $(initID(DIALOG, id));
if (init.isEmpty()) {
init = defaultInit;
}
String opener = $(djoin(DIALOG, id, "opener"));
list.add(join(" $('#", id, "').dialog(", init, ");"));
if (!opener.isEmpty() && Html.isValidId(opener)) {
list.add(join(" $('#", opener, "').click(function() { ",
"$('#", id, "').dialog('open'); return false; });"));
}
}
}
String selector = $(DIALOG_SELECTOR);
if (!selector.isEmpty()) {
String init = $(initSelector(DIALOG));
if (init.isEmpty()) {
init = defaultInit;
}
list.add(join(" $('", escapeEcmaScript(selector),
"').click(function() { $(this).children('.dialog').dialog(",
init, "); return false; });"));
}
}
代码示例来源:origin: vmi/selenese-runner-java
@Override
protected Result executeImpl(Context context, String... curArgs) {
String locator = curArgs[ARG_LOCATOR];
String value = curArgs[ARG_VALUE];
WebDriver driver = context.getWrappedDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = context.getElementFinder().findElement(driver, locator);
String javascriptEscaped = StringEscapeUtils.escapeEcmaScript(value);
try {
js.executeScript("var el = arguments[0]; el.innerHTML = '" + javascriptEscaped + "';", element);
return SUCCESS;
} catch (JavascriptException e) {
return new Failure(e.getMessage());
}
}
}
代码示例来源:origin: com.reprezen.genflow/openapi-diagram
public CharSequence generateResponseHeader(final String headerName, final Header header) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("\"objecttype\": \"HeaderParameter\",");
_builder.newLine();
_builder.append(" ");
_builder.append("\"name\": \"");
String _escapeEcmaScript = StringEscapeUtils.escapeEcmaScript(headerName);
_builder.append(_escapeEcmaScript, " ");
_builder.append("\",");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("\"isProperty\": false,");
_builder.newLine();
_builder.append(" ");
_builder.append("\"propertyId\": \"<undefined>\",");
_builder.newLine();
_builder.append(" ");
_builder.append("\"required\": ");
boolean _isRequired = header.isRequired();
_builder.append(_isRequired, " ");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
return _builder;
}
代码示例来源:origin: com.reprezen.genflow/openapi-diagram
public CharSequence generateResponseHeader(final String headerName, final Property header) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("\"objecttype\": \"HeaderParameter\",");
_builder.newLine();
_builder.append(" ");
_builder.append("\"name\": \"");
String _escapeEcmaScript = StringEscapeUtils.escapeEcmaScript(headerName);
_builder.append(_escapeEcmaScript, " ");
_builder.append("\",");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("\"isProperty\": false,");
_builder.newLine();
_builder.append(" ");
_builder.append("\"propertyId\": \"<undefined>\",");
_builder.newLine();
_builder.append(" ");
_builder.append("\"required\": ");
boolean _required = header.getRequired();
_builder.append(_required, " ");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
return _builder;
}
内容来源于网络,如有侵权,请联系作者删除!