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

The following examples show how to use org.apache.commons.text.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: Dom4j.java    From cuba with Apache License 2.0 6 votes vote down vote up
public static void loadMap(Element mapElement, Map<String, String> map) {
    checkNotNullArgument(map, "map is null");

    for (Element entryElem : mapElement.elements("entry")) {
        String key = entryElem.attributeValue("key");
        if (key == null) {
            throw new IllegalStateException("No 'key' attribute");
        }

        String value = null;
        Element valueElem = entryElem.element("value");
        if (valueElem != null) {
            value = StringEscapeUtils.unescapeXml(valueElem.getText());
        }

        map.put(key, value);
    }
}
 
Example 2
Source File: AbstractCondition.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected AbstractCondition(Element element, String messagesPack, String filterComponentName, com.haulmont.chile.core.model.MetaClass metaClass) {
    this.messagesPack = messagesPack;
    this.filterComponentName = filterComponentName;
    name = element.attributeValue("name");
    text = StringEscapeUtils.unescapeXml(element.getText());
    this.metaClass = metaClass;
    if (text == null)
        text = "";

    caption = element.attributeValue("caption");
    MessageTools messageTools = AppBeans.get(MessageTools.class);
    locCaption = messageTools.loadString(messagesPack, caption);

    unary = Boolean.valueOf(element.attributeValue("unary"));
    inExpr = Boolean.valueOf(element.attributeValue("inExpr"));
    hidden = Boolean.valueOf(element.attributeValue("hidden"));
    required = Boolean.valueOf(element.attributeValue("required"));
    useUserTimeZone = Boolean.valueOf(element.attributeValue("useUserTimeZone"));
    entityParamWhere = element.attributeValue("paramWhere");
    entityParamView = element.attributeValue("paramView");
    this.entityAlias = element.attributeValue("entityAlias");
    width = Strings.isNullOrEmpty(element.attributeValue("width")) ? 1 : Integer.parseInt(element.attributeValue("width"));

    resolveParam(element);
}
 
Example 3
Source File: MessageHandlerImpl.java    From jeeves with MIT License 5 votes vote down vote up
@Override
    public void postAcceptFriendInvitation(Message message) throws IOException {
        logger.info("postAcceptFriendInvitation");
//        将该用户的微信号设置成他的昵称
        String content = StringEscapeUtils.unescapeXml(message.getContent());
        ObjectMapper xmlMapper = new XmlMapper();
        FriendInvitationContent friendInvitationContent = xmlMapper.readValue(content, FriendInvitationContent.class);
        wechatHttpService.setAlias(message.getRecommendInfo().getUserName(), friendInvitationContent.getFromusername());
    }
 
Example 4
Source File: SoapService.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SOAPMessage createSoapRequest(String envelope, String method, List<AppServiceHeader> header, String token) throws SOAPException, IOException, SAXException, ParserConfigurationException {
    String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);
    boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();

    MimeHeaders headers = new MimeHeaders();
    for (AppServiceHeader appServiceHeader : header) {
        headers.addHeader(appServiceHeader.getKey(), appServiceHeader.getValue());
    }

    InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8"));
    MessageFactory messageFactory = MessageFactory.newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL);
    return messageFactory.createMessage(headers, input);
}
 
Example 5
Source File: Strings.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Unescape XML entities and illegal characters in the given string. This
 * enhances the functionality of
 * org.apache.commons.lang.StringEscapeUtils.unescapeXml by unescaping
 * low-valued unprintable characters, which are not permitted by the W3C XML
 * 1.0 specification.
 *
 * @param s
 *            a string
 * @return the same string with XML entities/escape sequences unescaped
 * @see <a href="http://www.w3.org/TR/REC-xml/#charsets">Extensible Markup
 *      Language (XML) 1.0 (Fifth Edition)</a>
 * @see <a
 *      href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#unescapeXml(java.lang.String)">org.apache.commons.lang.StringEscapeUtils
 *      javadoc</a>
 */
public static String unescapeXml(String s) {

    initializeEscapeMap();

    /*
     * we can't escape the string if the pattern doesn't compile! (but that
     * should never happen since the pattern is static)
     */
    if (!initializeUnescapePattern()) {
        return s;
    }

    if (s == null || s.length() == 0) {
        return s;
    }

    /*
     * skip this expensive check entirely if there are no substrings
     * resembling Unicode escape sequences in the string to be unescaped
     */
    if (s.contains("\\u")) {
        StringBuffer sUnescaped = new StringBuffer();
        Matcher m = unescapePattern.matcher(s);
        while (m.find() == true) {
            String slashes = m.group(1);
            String digits = m.group(3);
            int escapeCode;
            try {
                escapeCode = Integer.parseInt(digits, 16);
            } catch (NumberFormatException nfe) {
                /*
                 * the static regular expression string should guarantee
                 * that this exception is never thrown
                 */
                System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number!  "
                        + "Exception: " + nfe.toString());
                return s;
            }
            if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) {
                Character escapedSequence = Character.valueOf((char) escapeCode);
                /*
                 * slashes are apparently escaped when the string buffer is
                 * converted to a string, so double them to make sure the
                 * correct number appear in the final representation
                 */
                m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString());
            }
        }
        m.appendTail(sUnescaped);
        s = sUnescaped.toString();
    }
    return StringEscapeUtils.unescapeXml(s);
}
 
Example 6
Source File: XMLUnescapeTransformer.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String transform(String string) {
    return StringEscapeUtils.unescapeXml(string);
}
 
Example 7
Source File: EncryptUtils.java    From platform with Apache License 2.0 4 votes vote down vote up
public static String unescapeXml(String xmlEscaped) {
    return StringEscapeUtils.unescapeXml(xmlEscaped);
}
 
Example 8
Source File: XmlUtility.java    From jstarcraft-core with Apache License 2.0 2 votes vote down vote up
/**
 * 对字符串执行XML1.0解密
 * 
 * @param string
 * @return
 */
public static final String unescapeXml10(String string) {
    return StringEscapeUtils.unescapeXml(string);
}
 
Example 9
Source File: XmlUtility.java    From jstarcraft-core with Apache License 2.0 2 votes vote down vote up
/**
 * 对字符串执行XML1.1解密
 * 
 * @param string
 * @return
 */
public static final String unescapeXml11(String string) {
    return StringEscapeUtils.unescapeXml(string);
}