Java Code Examples for org.apache.commons.lang3.StringEscapeUtils#unescapeXml()

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#unescapeXml() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueStrategy.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: AbstractFormItem.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@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);
}
 
Example 3
Source File: Passage.java    From uncc2014watsonsim with GNU General Public License v2.0 5 votes vote down vote up
/**
    * 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);
}
 
Example 4
Source File: StaticResourceVersionController.java    From es with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example 5
Source File: Phrase.java    From uncc2014watsonsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: TestCorrect.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: ScriptDetail.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String convertSpecialChars(String script) {
	script = StringEscapeUtils.unescapeHtml4(script);
	script = StringEscapeUtils.unescapeXml(script);
	return script;
}
 
Example 8
Source File: Encodes.java    From jee-universal-bms with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 9
Source File: LogStrategy.java    From JVoiceXML with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@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());
    }
}
 
Example 10
Source File: Encodes.java    From MultimediaDesktop with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 11
Source File: Encodes.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 12
Source File: Functions.java    From MLib with GNU General Public License v3.0 4 votes vote down vote up
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]);
}
 
Example 13
Source File: Encodes.java    From opencron with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
    return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 14
Source File: EncodeUtils.java    From base-framework with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 15
Source File: Encodes.java    From easyweb with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 16
Source File: WikipediaXMLParser.java    From gerbil with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * <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>
 * ...
 * &lt;redirects&gt;
 * ...
 * &lt;r from="title" to="redirected title"/&gt;
 * ...
 * &lt;/redirects&gt;
 * ...
 * </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));
}
 
Example 17
Source File: Functions.java    From MLib with GNU General Public License v3.0 4 votes vote down vote up
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]);
}
 
Example 18
Source File: Encodes.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String unescapeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 19
Source File: EncodeUtils.java    From frpMgr with MIT License 4 votes vote down vote up
/**
 * Xml 解码.
 */
public static String decodeXml(String xmlEscaped) {
	return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 20
Source File: EscapeUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * Xml转码,XML格式的字符串解码为普通字符串.
 * 
 * 比如 &quot;bread&quot; &amp; &quot;butter&quot; 转化为"bread" & "butter"
 */
public static String unescapeXml(String xml) {
	return StringEscapeUtils.unescapeXml(xml);
}