本文整理了Java中org.apache.commons.lang.StringEscapeUtils
类的一些代码示例,展示了StringEscapeUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils
类的具体详情如下:
包路径:org.apache.commons.lang.StringEscapeUtils
类名称:StringEscapeUtils
[英]Escapes and unescapes String
s for Java, Java Script, HTML, XML, and SQL.
#ThreadSafe#
[中]对Java、Java脚本、HTML、XML和SQL进行转义和取消转义String
s。
#线程安全#
代码示例来源:origin: internetarchive/heritrix3
/**
* Write the paged HTML.
*
* @see org.restlet.resource.Representation#write(java.io.Writer)
*/
@Override
public void write(Writer writer) throws IOException {
loadLines();
PrintWriter pw = new PrintWriter(writer);
pw.println("<b>Paged view:</b> "+file);
emitControls(pw);
pw.println("<pre>");
emitBumper(pw, true);
for(String line : lines) {
StringEscapeUtils.escapeHtml(pw,line);
pw.println();
}
emitBumper(pw, false);
pw.println("</pre>");
emitControls(pw);
pw.close();
}
代码示例来源:origin: SonarSource/sonarqube
private static void appendRuleParameter(Writer writer, ActiveRuleParam activeRuleParam) throws IOException {
if (StringUtils.isNotBlank(activeRuleParam.getValue())) {
writer.append("<parameter><key>");
StringEscapeUtils.escapeXml(writer, activeRuleParam.getKey());
writer.append("</key><value>");
StringEscapeUtils.escapeXml(writer, activeRuleParam.getValue());
writer.append("</value>");
writer.append("</parameter>");
}
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* UnEscape HTML content. i.e. replace characters with &values;
*
* @param content
* content
* @return unescaped content
*/
public static String unEscapeHtml( String content ) {
if ( Utils.isEmpty( content ) ) {
return content;
}
return StringEscapeUtils.unescapeHtml( content );
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
private void printHeader(PrintWriter out, String nodeName) {
out.print("<html><head>");
out.printf("<title>%s Reconfiguration Utility</title>%n",
StringEscapeUtils.escapeHtml(nodeName));
out.print("</head><body>\n");
out.printf("<h1>%s Reconfiguration Utility</h1>%n",
StringEscapeUtils.escapeHtml(nodeName));
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-common
protected void printAttr(String name, String value) {
sb.setLength(0);
sb.append(' ').append(name);
if (value != null) {
sb.append("=\"").append(escapeHtml(value)).append("\"");
}
out.print(sb.toString());
}
代码示例来源:origin: paoding-code/paoding-rose
@Override
public void doRender(Invocation inv) throws Exception {
String message = resolvePlaceHolder(this.message, inv);
message = StringEscapeUtils.escapeHtml(message); //输出到页面之前对HTML转义,防止XSS注入
if (StringUtils.isEmpty(message)) {
inv.getResponse().sendError(code);
} else {
inv.getResponse().sendError(code, message);
}
}
代码示例来源:origin: org.apache.jspwiki/jspwiki-main
private void print( String s )
{
s = StringEscapeUtils.unescapeHtml( s );
m_out.print( s );
}
代码示例来源:origin: apache/storm
.filter(fName -> !StringUtils.equals(fileName, fName))
.collect(toList());
reorderedFilesStr.add(fileName);
String logString = isTxtFile(fileName) ? escapeHtml(pageFile(path, isZipFile, fileLength, start, length)) :
escapeHtml("This is a binary file and cannot display! You may download the full file.");
if (StringUtils.isNotEmpty(grep)) {
String matchedString = String.join("\n", Arrays.stream(logString.split("\n"))
.filter(str -> str.contains(grep)).collect(toList()));
代码示例来源:origin: apache/storm
private DomContent logTemplate(List<DomContent> bodyContents, String fileName, String user) {
List<DomContent> finalBodyContents = new ArrayList<>();
if (StringUtils.isNotBlank(user)) {
finalBodyContents.add(div(p("User: " + user)).withClass("ui-user"));
}
finalBodyContents.add(div(p("Note: the drop-list shows at most 1024 files for each worker directory.")).withClass("ui-note"));
finalBodyContents.add(h3(escapeHtml(fileName)));
finalBodyContents.addAll(bodyContents);
return html(
head(
title(escapeHtml(fileName) + " - Storm Log Viewer"),
link().withRel("stylesheet").withHref("/css/bootstrap-3.3.1.min.css"),
link().withRel("stylesheet").withHref("/css/jquery.dataTables.1.10.4.min.css"),
link().withRel("stylesheet").withHref("/css/style.css")
),
body(
finalBodyContents.toArray(new DomContent[]{})
)
);
}
代码示例来源:origin: youseries/uflo
protected String unescape(String str){
if(StringUtils.isEmpty(str))return str;
str=StringEscapeUtils.escapeXml(str);
return StringEscapeUtils.unescapeXml(str);
}
}
代码示例来源:origin: org.apache.tajo/tajo-storage-hdfs
public static byte[] getNullCharsAsBytes(TableMeta meta, String key, String defaultVal) {
byte [] nullChars;
String nullCharacters = StringEscapeUtils.unescapeJava(meta.getOption(key, defaultVal));
if (StringUtils.isEmpty(nullCharacters)) {
nullChars = NullDatum.get().asTextBytes();
} else {
nullChars = nullCharacters.getBytes(Bytes.UTF8_CHARSET);
}
return nullChars;
}
代码示例来源:origin: SonarSource/sonarqube
private static void processProperty(String key, @Nullable String val, String text, StringBuilder xml) {
xml.append("<" + PROPERTY + "><" + PROPERTY_KEY + ">");
xml.append(StringEscapeUtils.escapeXml(key));
xml.append("</" + PROPERTY_KEY + ">");
if (val != null) {
xml.append("<" + PROPERTY_VALUE + ">");
xml.append(val);
xml.append("</" + PROPERTY_VALUE + ">");
}
if (StringUtils.isNotEmpty(text)) {
xml.append("<" + PROPERTY_TEXT_VALUE + ">");
xml.append(StringEscapeUtils.escapeXml(text));
xml.append("</" + PROPERTY_TEXT_VALUE + ">");
}
xml.append("</" + PROPERTY + ">");
}
代码示例来源:origin: pentaho/big-data-plugin
private String normalizePath( final String path ) {
if ( StringUtils.isNotBlank( path ) ) {
return path.replaceAll( "/", StringEscapeUtils.escapeJava( "/" ) )
.replaceAll( "\\\\", StringEscapeUtils.escapeJava( "/" ) );
}
return path;
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-portal-core
private void appendKeywords(ResourceData resource, YElement yElement) {
for (KeywordsData keywordsData : resource.getKeywords()) {
if (StringUtils.isNotEmpty(keywordsData.getContentString())) {
YTagList tagList = new YTagList(keywordsData.getLanguage().getyLanguage(), TagTypes.TG_KEYWORD);
for (Renderable tag : keywordsData.getData()) {
tagList.addValue(StringEscapeUtils.unescapeHtml(tag.toString()));//TODO QQQ
}
yElement.addTagList(tagList);
}
}
}
代码示例来源:origin: KronicDeth/intellij-elixir
private Stream<String> headerHTMLLineStream(@Nullable String header) {
Stream<String> htmlLineStream;
if (header != null) {
htmlLineStream = Stream.of("<h2>" + escapeHtml(header) + "</h2>");
} else {
htmlLineStream = Stream.empty();
}
return htmlLineStream;
}
代码示例来源:origin: info.magnolia/magnolia-module-templating
public String getString() {
final String str = StringEscapeUtils.escapeHtml(super.getString());
if(transformLineBreaks){
return StringUtils.replace(str, "\n", "<br/>");
}
return str;
}
代码示例来源:origin: internetarchive/heritrix3
private static String replace(String meta, String find, String replace) {
replace = StringUtils.defaultString(replace);
replace = StringEscapeUtils.escapeXml(replace);
return meta.replace(find, replace);
}
代码示例来源:origin: pentaho/pentaho-kettle
public String sanitizeText( String txt ) {
// resolve all RELEASE characters
if ( txt.indexOf( "?" ) >= 0 ) {
txt = txt.replace( "?+", "+" );
txt = txt.replace( "?:", ":" );
txt = txt.replace( "?'", "'" );
txt = txt.replace( "??", "?" );
}
// enocde XML entities
return StringEscapeUtils.escapeXml( txt );
}
代码示例来源:origin: commons-lang/commons-lang
/**
* <p>Escapes any values it finds into their String form.</p>
*
* <p>So a tab becomes the characters <code>'\\'</code> and
* <code>'t'</code>.</p>
*
* <p>As of Lang 2.0, this calls {@link StringEscapeUtils#escapeJava(String)}
* behind the scenes.
* </p>
* @see StringEscapeUtils#escapeJava(java.lang.String)
* @param str String to escape values in
* @return String with escaped values
* @throws NullPointerException if str is <code>null</code>
* @deprecated Use {@link StringEscapeUtils#escapeJava(String)}
* This method will be removed in Commons Lang 3.0
*/
public static String escape(String str) {
return StringEscapeUtils.escapeJava(str);
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-checkstyle-plugin
private void appendModule(Writer writer, ActiveRule activeRule) throws IOException {
String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/");
writer.append("<module name=\"");
StringEscapeUtils.escapeXml(writer, moduleName);
writer.append("\">");
if (activeRule.getRule().getTemplate() != null) {
appendModuleProperty(writer, "id", activeRule.getRuleKey());
}
appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity()));
appendRuleParameters(writer, activeRule);
writer.append("</module>");
}
内容来源于网络,如有侵权,请联系作者删除!