Example usage for org.apache.commons.text StringEscapeUtils unescapeXml

List of usage examples for org.apache.commons.text StringEscapeUtils unescapeXml

Introduction

In this page you can find the example usage for org.apache.commons.text StringEscapeUtils unescapeXml.

Prototype

public static final String unescapeXml(final String input) 

Source Link

Document

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Usage

From source file:ch.cyberduck.core.s3.S3ExceptionMappingService.java

@Override
public BackgroundException map(final ServiceException e) {
    if (e.getCause() instanceof ServiceException) {
        return this.map((ServiceException) e.getCause());
    }/*  www .j a  va2s .c  o m*/
    final StringBuilder buffer = new StringBuilder();
    if (StringUtils.isNotBlank(e.getErrorMessage())) {
        // S3 protocol message parsed from XML
        this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage()));
    } else {
        this.append(buffer, e.getResponseStatus());
        this.append(buffer, e.getMessage());
    }
    switch (e.getResponseCode()) {
    case HttpStatus.SC_FORBIDDEN:
        if (StringUtils.isNotBlank(e.getErrorCode())) {
            switch (e.getErrorCode()) {
            case "SignatureDoesNotMatch":
            case "InvalidAccessKeyId":
            case "InvalidClientTokenId":
            case "InvalidSecurity":
            case "MissingClientTokenId":
            case "MissingAuthenticationToken":
                return new LoginFailureException(buffer.toString(), e);
            }
        }
    case HttpStatus.SC_BAD_REQUEST:
        if (StringUtils.isNotBlank(e.getErrorCode())) {
            switch (e.getErrorCode()) {
            case "RequestTimeout":
                return new ConnectionTimeoutException(buffer.toString(), e);
            }
        }
    }
    if (e.getCause() instanceof IOException) {
        return new DefaultIOExceptionMappingService().map((IOException) e.getCause());
    }
    if (e.getCause() instanceof SAXException) {
        return new InteroperabilityException(buffer.toString(), e);
    }
    return new HttpResponseExceptionMappingService()
            .map(new HttpResponseException(e.getResponseCode(), buffer.toString()));
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static List<String> validateCategory(final XmlPullParser parser) throws OPMLParserException {
    final String category = StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, CATEGORY));

    if (!TextUtils.isEmpty(category)) {
        final String[] categories = category.split(",");
        final List<String> result = new ArrayList<>(categories.length);

        for (final String subCategory : categories) {
            result.add(subCategory.substring(1));
        }/*  ww w .jav a2 s .co m*/

        return result;
    }

    return null;
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static String validateDescription(final XmlPullParser parser) {
    return StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, DESCRIPTION));
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static String validateText(final XmlPullParser parser) throws OPMLParserException {
    final String text = StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, TEXT));

    if (!TextUtils.isEmpty(text)) {
        return StringEscapeUtils.unescapeXml(text);
    } else {//www  .  ja  va  2s  .com
        throw new OPMLParserException(parser);
    }
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static String validateTitle(final XmlPullParser parser) throws OPMLParserException {
    final String title = StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, TITLE));

    if (!TextUtils.isEmpty(title)) {
        return StringEscapeUtils.unescapeXml(title);
    } else {/*from ww  w. jav  a 2s.  c o m*/
        throw new OPMLParserException(parser);
    }
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static String validateUrl(final XmlPullParser parser, final String element, final int mode)
        throws OPMLParserException {
    final String url = StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, element));

    if (!TextUtils.isEmpty(url)) {
        if (!URLUtil.isValidUrl(url)) {
            throw new OPMLParserException(parser);
        }/*  w  ww.  j  ava  2 s.com*/
    }

    return url;
}

From source file:org.jgrapht.io.DOTImporter.java

/**
 * Unescape an HTML string DOT identifier.
 *
 * @param input the input//from   w ww  . jav  a 2 s  .  co  m
 * @return the unescaped output
 */
private static String unescapeHtmlString(String input) {
    if (input.charAt(0) != '<' || input.charAt(input.length() - 1) != '>') {
        return input;
    }
    String noQuotes = input.subSequence(1, input.length() - 1).toString();
    String unescaped = StringEscapeUtils.unescapeXml(noQuotes);
    return unescaped;
}