本文整理了Java中org.apache.commons.lang.StringEscapeUtils.escapeXml()
方法的一些代码示例,展示了StringEscapeUtils.escapeXml()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeXml()
方法的具体详情如下:
包路径:org.apache.commons.lang.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeXml
[英]Escapes the characters in a String
using XML entities.
For example: "bread" & "butter" => "bread" & "butter".
Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.
Note that unicode characters greater than 0x7f are currently escaped to their numerical \u equivalent. This may change in future releases.
[中]使用XML实体转义String
中的字符。
例如:“面包”和“黄油”;“面包”&&引用;黄油;。
仅支持五个基本XML实体(gt、lt、QUOTE、amp、apos)。不支持DTD或外部实体。
请注意,大于0x7f的unicode字符当前会转义为其等效的数字\u。这在未来的版本中可能会发生变化。
代码示例来源: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: 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: SonarSource/sonarqube
private static void appendHeader(RulesProfile profile, Writer writer) throws IOException {
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<!-- Generated by SonarQube -->"
+ "<profile><name>");
StringEscapeUtils.escapeXml(writer, profile.getName());
writer.append("</name><language>");
StringEscapeUtils.escapeXml(writer, profile.getLanguage());
writer.append("</language>");
}
代码示例来源: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
/**
* Escape XML content. i.e. replace characters with &values;
*
* @param content
* content
* @return escaped content
*/
public static String escapeXML( String content ) {
if ( Utils.isEmpty( content ) ) {
return content;
}
return StringEscapeUtils.escapeXml( content );
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Mask XML content. i.e. replace characters with &values;
*
* @param content
* content
* @return masked content
*/
public static String escapeXml( String content ) {
if ( Utils.isEmpty( content ) ) {
return content;
}
return StringEscapeUtils.escapeXml( content );
}
代码示例来源:origin: SonarSource/sonarqube
private void appendDuplication(StringBuilder xml, String componentDbKey, TextBlock textBlock, boolean disableLink) {
int length = textBlock.getEnd() - textBlock.getStart() + 1;
xml.append("<b s=\"").append(textBlock.getStart())
.append("\" l=\"").append(length)
.append("\" t=\"").append(disableLink)
.append("\" r=\"").append(StringEscapeUtils.escapeXml(componentDbKey))
.append("\"/>");
}
}
代码示例来源:origin: SonarSource/sonarqube
private static void appendRule(ActiveRule activeRule, Writer writer) throws IOException {
writer.append("<rule><repositoryKey>");
writer.append(activeRule.getRepositoryKey());
writer.append("</repositoryKey><key>");
StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey());
writer.append("</key>");
if (activeRule.getSeverity() != null) {
writer.append("<priority>");
writer.append(activeRule.getSeverity().name());
writer.append("</priority>");
}
appendRuleParameters(activeRule, writer);
writer.append("</rule>");
}
代码示例来源:origin: spotbugs/spotbugs
return StringEscapeUtils.escapeXml(sb.toString());
代码示例来源:origin: SonarSource/sonarqube
private static void processRule(RuleDebt rule, StringBuilder xml) {
xml.append("<" + CHARACTERISTIC + ">");
xml.append("<" + REPOSITORY_KEY + ">");
xml.append(StringEscapeUtils.escapeXml(rule.ruleKey().repository()));
xml.append("</" + REPOSITORY_KEY + "><" + RULE_KEY + ">");
xml.append(StringEscapeUtils.escapeXml(rule.ruleKey().rule()));
xml.append("</" + RULE_KEY + ">");
String coefficient = rule.coefficient();
String offset = rule.offset();
processProperty(PROPERTY_FUNCTION, null, rule.function(), xml);
if (coefficient != null) {
String[] values = getValues(coefficient);
processProperty(PROPERTY_COEFFICIENT, values[0], values[1], xml);
}
if (offset != null) {
String[] values = getValues(offset);
processProperty(PROPERTY_OFFSET, values[0], values[1], xml);
}
xml.append("</" + CHARACTERISTIC + ">");
}
代码示例来源:origin: apache/cloudstack
public GraphicDef(String type, short port, boolean autoPort, String listenAddr, String passwd, String keyMap) {
_type = type;
_port = port;
_autoPort = autoPort;
_listenAddr = listenAddr;
_passwd = StringEscapeUtils.escapeXml(passwd);
_keyMap = keyMap;
}
代码示例来源:origin: org.netpreserve.commons/commons-web
/**
* Escapes a string so that it can be placed inside XML/HTML attribute.
* Replaces ampersand, less-than, greater-than, single-quote, and
* double-quote with escaped versions.
* @param s The string to escape
* @return The same string escaped.
*/
public static String escapeForMarkupAttribute(String s) {
return StringEscapeUtils.escapeXml(s);
}
代码示例来源:origin: sakaiproject/sakai
public static String getFatalResponse(String description, String message_id)
{
Date dt = new Date();
String messageId = ""+dt.getTime();
return String.format(fatalMessage,
StringEscapeUtils.escapeXml(messageId),
StringEscapeUtils.escapeXml(description),
StringEscapeUtils.escapeXml(message_id));
}
代码示例来源:origin: com.atlassian.support/stp
/**
* Escape a key that will be used as an XML element name, replacing colons with dashes to avoid "this:that" being
* interpreted as element "that" in namespace "this".
*
* @param key intended for use as an XML element name.
* @return The escaped value of the key.
*/
private String escapeXmlElementName(String key)
{
String escapedKey = StringEscapeUtils.escapeXml(key);
return escapedKey.replace(":", "-");
}
代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api
private 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: com.atlassian.jira/jira-core
/**
* Returns a string representation of the given date in DateTimeStyle#RSS_RFC822_DATE_TIME format.
*
* @param date a date/time to format
* @return an string containing the given date/time (XML-escaped)
*/
public String formatRSS(Date date)
{
return escapeXml(dateTimeFormatter.withStyle(DateTimeStyle.RSS_RFC822_DATE_TIME).format(date));
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
/**
* Returns a string representation of the given date/time in DateTimeStyle#RSS_RFC822_DATE_TIME format.
*
* @param date a date/time to format
* @return an string containing the given date/time (XML-escaped)
*/
public String formatRSS(Date date)
{
return escapeXml(dateTimeFormatter.forLoggedInUser().withStyle(DateTimeStyle.RSS_RFC822_DATE_TIME).format(date));
}
}
代码示例来源:origin: pentaho/pentaho-platform
public static Document createErrorDocument( String errorMsg ) {
Element rootElement = new DefaultElement( "web-service" );
Document doc = DocumentHelper.createDocument( rootElement );
rootElement.addElement( "error" ).addAttribute( "msg", StringEscapeUtils.escapeXml( errorMsg ) );
return doc;
}
代码示例来源:origin: pentaho/pentaho-platform
public static Document createStatusDocument( String statusMsg ) {
Element rootElement = new DefaultElement( "web-service" );
Document doc = DocumentHelper.createDocument( rootElement );
rootElement.addElement( "status" ).addAttribute( "msg", StringEscapeUtils.escapeXml( statusMsg ) );
return doc;
}
}
内容来源于网络,如有侵权,请联系作者删除!