下面列出了org.apache.commons.lang3.StringEscapeUtils#unescapeXml ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Retrieves the TTS output of this tag.
*
* @return Output of this tag, <code>null</code> if there is no text to
* output.
*
* @exception SemanticError
* Error evaluating an expression.
*/
private String getOutput() throws SemanticError {
final Object result = getAttribute(Value.ATTRIBUTE_EXPR);
if (result == null) {
LOGGER.warn("ignoring empty value result");
return null;
}
final String text = result.toString();
final String cleaned = text.trim();
if (cleaned.length() == 0) {
LOGGER.warn("ignoring empty value node");
return null;
}
return StringEscapeUtils.unescapeXml(cleaned);
}
/**
* {@inheritDoc}
*/
@Override
public final Object evaluateExpression(final DataModel model)
throws SemanticError {
final String expr = node.getAttribute("expr");
if (expr == null) {
return null;
}
final String unescapedExpr = StringEscapeUtils.unescapeXml(expr);
return model.evaluateExpression(unescapedExpr, Object.class);
}
/**
* Create a new Passage
*
* @param engine_name A simple lowercase string
* @param title
* @param text
* @param reference Specific to the engine, or a URL, for later lookup
*/
public Passage(String engine_name, String title, String text, String reference) {
super(text);
if (engine_name == null)
throw new NullPointerException("Engine name cannot be null.");
if (title == null)
throw new NullPointerException("Title cannot be null.");
if (reference == null)
throw new NullPointerException("Reference cannot be null.");
this.reference = reference;
this.engine_name = engine_name;
this.title = StringEscapeUtils.unescapeXml(title);
}
/**
* Create a new NLP parsed phrase.
* This will throw an NPE rather than take null text.
* The memo system is lazy and phrases are cached so this is quite cheap.
*/
public Phrase(String text) {
if (text == null)
throw new NullPointerException("Text cannot be null.");
Phrase cache_entry = recent.getIfPresent(text);
if (cache_entry != null) {
this.text = cache_entry.text;
// Memos are mutable but private and thread-safe.
this.memos = cache_entry.memos;
} else {
this.memos = new ConcurrentHashMap<>();
this.text = StringEscapeUtils.unescapeXml(text);
recent.put(text, this);
}
}
@Test
public void testEscapeItalic() {
String txt="<p>Est-ce que tu voudrais <em>pusher</em> ton code ?</p>";
String s = StringEscapeUtils.unescapeXml(txt);
String result = corrector.checkHtmlContent(s);
assertEquals(result, txt);
}
private String versionedStaticResourceContent(String fileRealPath, String content, String newVersion) throws IOException {
content = StringEscapeUtils.unescapeXml(content);
if(newVersion != null && newVersion.equals("1")) {
newVersion = "?" + newVersion;
}
File file = new File(fileRealPath);
List<String> contents = FileUtils.readLines(file);
for(int i = 0, l = contents.size(); i < l; i++) {
String fileContent = contents.get(i);
if(content.equals(fileContent)) {
Matcher matcher = scriptPattern.matcher(content);
if(!matcher.matches()) {
matcher = linkPattern.matcher(content);
}
if(newVersion == null) { //删除版本
content = matcher.replaceAll("$1$2$5");
} else {
content = matcher.replaceAll("$1$2$3" + newVersion + "$5");
}
contents.set(i, content);
break;
}
}
FileUtils.writeLines(file, contents);
return content;
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
/**
* Xml 解码.
*/
public static String decodeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
private static void unescapeTitel(DatenFilm film) {
// Titel
film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeXml(film.arr[DatenFilm.FILM_TITEL]);
film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeHtml4(film.arr[DatenFilm.FILM_TITEL]);
film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeJava(film.arr[DatenFilm.FILM_TITEL]);
}
/**
* <p>
* Extracts the value of the <code>to</code> attribute of the first redirect
* that it can find inside the given XML string.
* </p>
*
* <p>
* It is assumed that the given String looks like this: <code>
* ...
* <redirects>
* ...
* <r from="title" to="redirected title"/>
* ...
* </redirects>
* ...
* </code>
* </p>
*
* @param xmlString
* XML string from which the redirect should be parsed.
* @return The title to which the given title is redirected or null, if such
* a title couldn't be found.
*/
public String extractRedirect(String xmlString) {
if (xmlString == null) {
return null;
}
int startPos = xmlString.indexOf(XML_REDIRECTS_START_TAG);
if (startPos < 0) {
// couldn't find redirects tag
return null;
}
startPos += XML_REDIRECTS_START_TAG.length();
int redirectsEnd = xmlString.indexOf(XML_REDIRECTS_END_TAG, startPos);
if (redirectsEnd < 0) {
// couldn't find redirects end tag (no valid XML)
return null;
}
startPos = xmlString.indexOf(XML_REDIRECT_TAG_START, startPos);
if ((startPos < 0) || (startPos >= redirectsEnd)) {
// couldn't find redirect tag
return null;
}
startPos += XML_REDIRECT_TAG_START.length();
int tagEndPos = xmlString.indexOf(XML_REDIRECT_TAG_END, startPos);
if ((tagEndPos < 0) || (tagEndPos >= redirectsEnd)) {
// couldn't find the end of the redirect tag (no valid XML)
return null;
}
startPos = xmlString.indexOf(XML_REDIRECT_TO_ATTRIBUTE_START, startPos);
if ((startPos < 0) || (startPos >= tagEndPos)) {
// couldn't find the 'to' attribute
return null;
}
startPos += XML_REDIRECT_TO_ATTRIBUTE_START.length();
int endPos = xmlString.indexOf(XML_REDIRECT_TO_ATTRIBUTE_END, startPos);
if ((endPos < 0) || (endPos >= tagEndPos)) {
// couldn't find the end of the 'to' attribute value (no valid XML)
return null;
}
return StringEscapeUtils.unescapeXml(xmlString.substring(startPos, endPos));
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
public String convertSpecialChars(String script) {
script = StringEscapeUtils.unescapeHtml4(script);
script = StringEscapeUtils.unescapeXml(script);
return script;
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
private static void unescapeThema(DatenFilm film) {
// Thema
film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeXml(film.arr[DatenFilm.FILM_THEMA]);
film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeHtml4(film.arr[DatenFilm.FILM_THEMA]);
film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeJava(film.arr[DatenFilm.FILM_THEMA]);
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
/**
* {@inheritDoc}
*
* Logs the containing text as a message.
*/
public void execute(final VoiceXmlInterpreterContext context,
final VoiceXmlInterpreter interpreter,
final FormInterpretationAlgorithm fia, final FormItem item,
final VoiceXmlNode node) throws JVoiceXMLEvent {
final NodeList list = node.getChildNodes();
final StringBuilder outputText = new StringBuilder();
// get and write the label attribute
final String label = (String) getAttribute(Log.ATTRIBUTE_LABEL);
if (label != null) {
outputText.append(label);
outputText.append(": ");
}
final String expr = (String) getAttribute(Log.ATTRIBUTE_EXPR);
if (expr != null) {
outputText.append(expr);
}
// process children
final DataModel model = context.getDataModel();
for (int i = 0; i < list.getLength(); i++) {
final VoiceXmlNode current = (VoiceXmlNode) list.item(i);
if (current instanceof Text) {
// text node handling
final Text text = (Text) current;
final String msg = text.getNodeValue();
if (msg == null) {
LOGGER.warn("ignoring empty log node");
} else {
outputText.append(msg.trim());
}
}
if (current instanceof Value) {
// value node handling
final Value value = (Value) current;
String currentExpr = value.getExpr();
if (currentExpr != null) {
final String unescapedCurrentExpr = StringEscapeUtils
.unescapeXml(currentExpr);
if (!currentExpr.endsWith(";")) {
currentExpr += ";";
}
final Object eval = model.evaluateExpression(
unescapedCurrentExpr, Object.class);
final String evalReadable = model.toString(eval);
outputText.append(evalReadable);
}
}
}
// write the eventual tag-value to the class-logger,
// priority Level.INFO
if (outputText.length() > 0) {
LOGGER.info(outputText.toString());
}
}
/**
* Xml 解码.
*/
public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
}
/**
* Xml转码,XML格式的字符串解码为普通字符串.
*
* 比如 "bread" & "butter" 转化为"bread" & "butter"
*/
public static String unescapeXml(String xml) {
return StringEscapeUtils.unescapeXml(xml);
}