本文整理了Java中org.apache.commons.lang3.StringEscapeUtils
类的一些代码示例,展示了StringEscapeUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils
类的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
[英]Escapes and unescapes Strings for Java, Java Script, HTML and XML.
#ThreadSafe#
[中]转义和取消转义Java、Java脚本、HTML和XML的字符串。
#线程安全#
代码示例来源:origin: Graylog2/graylog2-server
@Override
public String generate(Request request, int status, String reasonPhrase, String description, Throwable exception) {
final ImmutableMap.Builder<String, Object> modelBuilder = ImmutableMap.builder();
modelBuilder.put("reason", StringEscapeUtils.escapeHtml4(reasonPhrase));
if (description != null) {
modelBuilder.put("description", StringEscapeUtils.escapeHtml4(description));
}
if (exception != null) {
String stacktrace = "";
try (final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter)) {
exception.printStackTrace(printWriter);
printWriter.flush();
stringWriter.flush();
stacktrace = stringWriter.toString();
} catch (IOException ignored) {
// Ignore
}
modelBuilder
.put("exception", StringEscapeUtils.escapeHtml4(exception.getMessage()))
.put("stacktrace", StringEscapeUtils.escapeHtml4(stacktrace));
}
return engine.transform(template, modelBuilder.build());
}
}
代码示例来源:origin: springside/springside4
/**
* Html解码,将HTML4格式的字符串转码解码为普通字符串.
*
* 比如 "bread" & "butter"转化为"bread" & "butter"
*/
public static String unescapeHtml(String html) {
return StringEscapeUtils.unescapeHtml4(html);
}
}
代码示例来源:origin: gocd/gocd
public static String quoteJavascriptString(String s) {
return "\"" + StringEscapeUtils.escapeJava(s) + "\"";
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests https://issues.apache.org/jira/browse/LANG-911
*/
@Test
public void testLang911() {
final String bellsTest = "\ud83d\udc80\ud83d\udd14";
final String value = StringEscapeUtils.escapeJava(bellsTest);
final String valueTest = StringEscapeUtils.unescapeJava(value);
assertEquals(bellsTest, valueTest);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testEscapeSurrogatePairs() throws Exception {
assertEquals("\uD83D\uDE30", StringEscapeUtils.escapeCsv("\uD83D\uDE30"));
// Examples from https://en.wikipedia.org/wiki/UTF-16
assertEquals("\uD800\uDC00", StringEscapeUtils.escapeCsv("\uD800\uDC00"));
assertEquals("\uD834\uDD1E", StringEscapeUtils.escapeCsv("\uD834\uDD1E"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeCsv("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml3("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml4("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeXml("\uDBFF\uDFFD"));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeSurrogatePairs() throws Exception {
assertEquals("\uD83D\uDE30", StringEscapeUtils.unescapeCsv("\uD83D\uDE30"));
// Examples from https://en.wikipedia.org/wiki/UTF-16
assertEquals("\uD800\uDC00", StringEscapeUtils.unescapeCsv("\uD800\uDC00"));
assertEquals("\uD834\uDD1E", StringEscapeUtils.unescapeCsv("\uD834\uDD1E"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeCsv("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml3("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml4("\uDBFF\uDFFD"));
}
代码示例来源:origin: stanfordnlp/CoreNLP
out.println("<table id='Annotated'><tr><td>");
for (int i = 0; i < pieces.size(); ++i) {
if (tagged.get(i)) {
out.print("<span style=\"background-color: #FF8888\">");
out.print(StringEscapeUtils.escapeHtml4(pieces.get(i)));
out.print("</span>");
} else {
out.print(StringEscapeUtils.escapeHtml4(pieces.get(i)));
int end =
timexAnn.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
out.print("<td>" + StringEscapeUtils.escapeHtml4(query.substring(begin, end)) + "</td>");
out.print("<td>" + ((timex.value() != null)? StringEscapeUtils.escapeHtml4(timex.value()):"") + "</td>");
if (includeOffsets) {
out.print("<td>" + begin + "</td>");
out.print("<td>" + timexAnn.get(CoreAnnotations.TokenEndAnnotation.class) + "</td>");
out.print("<td>" + StringEscapeUtils.escapeHtml4(timex.toString()) + "</td>");
out.println("</tr>");
for (CoreLabel token : tokens) {
String tokenOutput =
StringEscapeUtils.escapeHtml4(token.word() + "/" + token.tag());
out.print(tokenOutput + " ");
代码示例来源:origin: stanfordnlp/CoreNLP
private static void outputByWriter(Consumer<StringWriter> printer, PrintWriter out) {
StringWriter output = new StringWriter();
printer.accept(output);
output.flush();
String escapedXml = StringEscapeUtils.escapeHtml4(output.toString());
String[] lines = escapedXml.split("\n");
out.print("<div><pre>");
for (String line : lines) {
int numSpaces = 0;
while (numSpaces < line.length() && line.charAt(numSpaces) == ' ') {
out.print(" ");
++numSpaces;
}
out.print(line.substring(numSpaces));
out.print("\n");
}
out.print("</pre></div>");
}
代码示例来源:origin: stanfordnlp/CoreNLP
PrintWriter out = response.getWriter();
if (dateError) {
out.println("<br><br>Warning: unparseable date " +
StringEscapeUtils.escapeHtml4(dateString));
if (timeAnnotator != null) {
Annotation anno = pipeline.process(query, dateString, timeAnnotator);
out.println("<h3>Annotated Text</h3> <em>(tagged using " + annotatorType + "</em>)");
displayAnnotation(out, query, anno, includeOffsets);
} else {
out.println("<br><br>Error creating annotator for " + StringEscapeUtils.escapeHtml4(annotatorType));
代码示例来源:origin: youseries/ureport
String bgStyle="";
String bgImage=context.getReport().getPaper().getBgImage();
if(StringUtils.isNotBlank(bgImage)){
bgStyle=";background:url("+bgImage+") no-repeat";
boolean hasLink=false;
String linkURL=cell.getLinkUrl();
if(StringUtils.isNotBlank(linkURL)){
Expression urlExpression=cell.getLinkUrlExpression();
if(urlExpression!=null){
if(StringUtils.isNotBlank(urlParameter)) {
if(linkURL.indexOf("?")==-1){
linkURL+="?"+urlParameter;
}else{
String text=obj.toString();
text=StringEscapeUtils.escapeHtml4(text);
text=text.replaceAll("\r\n", "<br>");
text=text.replaceAll("\n", "<br>");
代码示例来源:origin: pmd/pmd
private void glomRuleViolations(Writer writer, Iterator<RuleViolation> violations) throws IOException {
StringBuilder buf = new StringBuilder(500);
while (violations.hasNext()) {
RuleViolation rv = violations.next();
buf.setLength(0);
buf.append("<tr");
if (colorize) {
buf.append(" bgcolor=\"lightgrey\"");
}
colorize = !colorize;
buf.append("> " + PMD.EOL);
buf.append("<td align=\"center\">" + violationCount + "</td>" + PMD.EOL);
buf.append("<td width=\"*%\">"
+ maybeWrap(StringEscapeUtils.escapeHtml4(rv.getFilename()),
linePrefix == null ? "" : linePrefix + Integer.toString(rv.getBeginLine()))
+ "</td>" + PMD.EOL);
buf.append("<td align=\"center\" width=\"5%\">" + Integer.toString(rv.getBeginLine()) + "</td>" + PMD.EOL);
String d = StringEscapeUtils.escapeHtml4(rv.getDescription());
String infoUrl = rv.getRule().getExternalInfoUrl();
if (StringUtils.isNotBlank(infoUrl)) {
d = "<a href=\"" + infoUrl + "\">" + d + "</a>";
}
buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL);
buf.append("</tr>" + PMD.EOL);
writer.write(buf.toString());
violationCount++;
}
}
代码示例来源:origin: neuland/jade4j
if(!StringUtils.isBlank(value)) {
classes.add(value);
classEscaping.add(escaped);
value = expressionValue.toString();
if(escaped)
value = StringEscapeUtils.escapeHtml4(value);
代码示例来源:origin: com.atlassian.confluence.plugins/confluence-basic-macros
public String execute(Map<String, String> parameters, String body, ConversionContext conversionContext) {
String anchorName = defaultString(parameters.get("0"));
return StringUtils.isNotBlank(anchorName)
? "<span class=\"confluence-anchor-link\" id=\"" +
AbstractPageLink.generateAnchor(conversionContext.getPageContext(), anchorName) +
"\">" +
escapeHtml4(body) + /* To prevent XSS */
"</span>"
: "";
}
代码示例来源:origin: apache/hive
protected HiveDruidSplit[] getInputSplits(Configuration conf) throws IOException {
String address = HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_DRUID_BROKER_DEFAULT_ADDRESS);
String queryId = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYID);
if (StringUtils.isEmpty(address)) {
throw new IOException("Druid broker address not specified in configuration");
String druidQuery = StringEscapeUtils.unescapeJava(conf.get(Constants.DRUID_QUERY_JSON));
if (StringUtils.isEmpty(druidQuery)) {
代码示例来源:origin: qaprosoft/carina
public String formatFailReasonAsHtml(String reasonText) {
if (!StringUtils.isEmpty(reasonText)) {
reasonText = StringEscapeUtils.escapeHtml4(reasonText);
reasonText = reasonText.replace("\n", "<br/>");
}
return reasonText;
}
代码示例来源:origin: org.jboss.windup.graph/windup-graph-api
/**
* Gets a human readable description of the location in the file
*/
default String getDescription()
{
if (null == getSourceSnippit())
return "";
return StringEscapeUtils.escapeHtml4(
StringUtils.substringBefore(StringUtils.abbreviate(getSourceSnippit().trim(), MAX_DESC_WIDTH), System.lineSeparator()));
}
代码示例来源:origin: springside/springside4
/**
* Html转码,将字符串转码为符合HTML4格式的字符串.
*
* 比如 "bread" & "butter" 转化为 "bread" & "butter"
*/
public static String escapeHtml(String html) {
return StringEscapeUtils.escapeHtml4(html);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testEscapeHtmlVersions() throws Exception {
assertEquals("Β", StringEscapeUtils.escapeHtml4("\u0392"));
assertEquals("\u0392", StringEscapeUtils.unescapeHtml4("Β"));
// TODO: refine API for escaping/unescaping specific HTML versions
}
代码示例来源:origin: org.opensingular/singular-form-core
@Override
public String getAsString() throws TemplateModelException {
if (escapeContentHtml) {
return StringUtils.defaultString(StringEscapeUtils.escapeHtml4(getInstance().toStringDisplayDefault()));
} else {
return StringUtils.defaultString(getInstance().toStringDisplayDefault());
}
}
}
代码示例来源:origin: info.magnolia/magnolia-templating
@Override
public String getValueAsString() {
String val = getValue();
if (val.length() >= 100) {
val = StringUtils.substring(val, 0, 100);
val += "...";
}
return "\"" + StringEscapeUtils.escapeHtml4(val) + "\"";
}
内容来源于网络,如有侵权,请联系作者删除!