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

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

Introduction

In this page you can find the example usage for org.apache.commons.lang3 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:org.kie.workbench.common.forms.migration.legacy.services.impl.util.XMLNode.java

public void loadFromXMLNode(Node node) {
    objectName = node.getNodeName();//from   w w w.java2 s.  c  o  m
    NamedNodeMap attributesMap = node.getAttributes();
    if (attributesMap != null) {
        for (int i = 0; i < attributesMap.getLength(); i++) {
            Node attribute = attributesMap.item(i);
            addAttribute(attribute.getNodeName(), StringEscapeUtils.unescapeXml(attribute.getNodeValue()));
        }
    }
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeName().equals("#text")) {
            String content = child.getNodeValue();
            if (content != null && content.trim().length() > 0) {
                setContent(Base64.decode(child.getNodeValue().trim()));
            }
        } else {
            XMLNode childNode = new XMLNode("?", this);
            childNode.loadFromXMLNode(child);
            addChild(childNode);
        }
    }
}

From source file:org.lockss.extractor.JsoupTagExtractor.java

/**
 * take the value for a selector from an xml page and perform the necessary
 * transformations to regularize it for storing in the article metadata.
 * this will unescape any escaped xml and remove any extra spaces.
 *
 * @param name the selector name/*w  w  w.  j  ava2 s  . c o m*/
 * @param value the value
 * @return the regularized value
 */
private String processXml(final String name, String value) {
    // remove character entities from content
    value = StringEscapeUtils.unescapeXml(value);
    // normalize multiple whitespaces to a single space character
    value = value.replaceAll("\\s+", " ");
    return value;
}

From source file:org.lockss.extractor.JsoupXmlTagExtractor.java

/**
 * take the value for a tag from an xml page and perform the necessary
 * transformations to regularize it for storing in the article metadata.
 * this will unescape any escaped xml and remove any extra spaces.
 *
 * @param name the tag name/*from  w  w w .j a  v  a  2  s  .  c  o m*/
 * @param value the value
 * @return the regularized value
 */
private String processXml(final String name, String value) {
    // remove character entities from content
    value = StringEscapeUtils.unescapeXml(value);
    // normalize multiple whitespaces to a single space character
    value = value.replaceAll("\\s+", " ");
    if (theLog.isDebug3())
        theLog.debug3("Add: " + name + " = " + value);
    return value;
}

From source file:org.lockss.extractor.SimpleXmlMetadataExtractor.java

protected void scanForTag(String line, String tag, ArticleMetadata ret) {
    int i = 0;/*from  w w  w.j  a va  2 s .com*/
    String begin = "<" + tag + ">";
    String end = "</" + tag + ">";
    log.debug2("Scan: " + tag);
    while ((i = StringUtil.indexOfIgnoreCase(line, begin, i)) >= 0) {
        i += begin.length();
        int j = StringUtil.indexOfIgnoreCase(line, end, i);
        if (j > i) {
            String value = line.substring(i, j);
            value = StringEscapeUtils.unescapeXml(value);
            log.debug2(tag + " = " + value);
            ret.putRaw(tag, value);
        }
    }
}

From source file:org.mashupmedia.service.MapperManagerImpl.java

@Override
public void saveXmltoSongs(MusicLibrary musicLibrary, String xml) throws Exception {

    String libraryPath = StringUtils.trimToEmpty(musicLibrary.getLocation().getPath());
    libraryPath = libraryPath.replaceFirst("/app/.*", "");

    List<Song> songs = new ArrayList<Song>();

    if (StringUtils.isBlank(xml)) {
        logger.error("Unable to save remote songs, xml is empty");
        return;//from  w  w w .j  a va2 s.co m
    }

    InputStream inputStream = new ByteArrayInputStream(xml.getBytes());

    PartialUnmarshaller<Song> partialUnmarshaller = new PartialUnmarshaller<Song>(inputStream, Song.class);

    while (partialUnmarshaller.hasNext()) {
        Song song = partialUnmarshaller.next();
        String title = StringEscapeUtils.unescapeXml(song.getTitle());
        song.setTitle(title);
        Album album = song.getAlbum();
        album.setId(0);

        songs.add(song);

        if (songs.size() == 10) {
            musicLibraryUpdateManager.saveSongs(musicLibrary, songs);
            songs.clear();
        }
    }

    partialUnmarshaller.close();
    musicLibraryUpdateManager.saveSongs(musicLibrary, songs);

}

From source file:org.miradi.utils.XmlUtilities2.java

public static String getXmlDecoded(String value) {
    if (isEmptyValue(value))
        return value;

    return StringEscapeUtils.unescapeXml(value);
}

From source file:org.n52.eventing.rest.templates.InstanceGenerator.java

public String generateFilterInstance(Template t, List<ParameterValue> values) {
    String content = t.getDefinition().getContent();

    if (content.contains("&lt;")) {
        content = StringEscapeUtils.unescapeXml(content);
    }//from  w w  w .  java 2  s  .  com

    for (ParameterValue param : values) {
        content = content.replace(String.format("${%s}", param.getName()), param.getValue().toString());
    }

    return content;
}

From source file:org.n52.ses.filter.epl.EPLFilterImpl.java

public EPLFilterImpl(XmlObject obj) throws SubscribeCreationFailedFault {
    if (obj instanceof EPLFiltersDocument) {
        this.filterXml = (EPLFiltersDocument) obj;
        EPLFilter[] filters = ((EPLFiltersDocument) obj).getEPLFilters().getEPLFilterArray();

        for (EPLFilter epl : filters) {
            String stmt = StringEscapeUtils.unescapeXml(epl.getStatement().getStringValue()).trim();
            int fromIndex = StringUtils.indexOfIgnoreCase(stmt, " from ");
            String subFrom = stmt.substring(fromIndex).trim();
            subFrom = subFrom.substring(subFrom.indexOf(" "), subFrom.length()).trim();

            fromIndex = subFrom.indexOf(" ");
            if (fromIndex > 0) {
                subFrom = subFrom.substring(0, fromIndex).trim();
            }/*w  ww  .jav a 2 s  .c o  m*/

            String streamName;
            if (subFrom.contains(".") || subFrom.contains(":")) {
                int i = Math.min(subFrom.indexOf("."), subFrom.indexOf(":"));
                streamName = subFrom.substring(0, i);
            } else {
                streamName = subFrom;
            }

            String statement = StringEscapeUtils.unescapeXml(epl.getStatement().getStringValue()).trim();

            String newEventName = null;
            if (epl.isSetNewEventName()) {
                newEventName = epl.getNewEventName();
            }

            boolean doOutput = false;
            if (epl.getStatement().isSetDoOutput()) {
                doOutput = epl.getStatement().getDoOutput();
            }

            boolean external = epl.getStatement().getExternalInput();
            if (external) {
                if (this.externalInputName != null && !this.externalInputName.equals(streamName)) {
                    throw new SubscribeCreationFailedFault(
                            "Multiple externalInputs set for one EPLFilter subscription");
                } else {
                    this.externalInputName = streamName;
                }
            }

            this.eplFilters.put(new EPLFilterInstance(statement, newEventName, doOutput, external), streamName);
        }
    } else {
        throw new SubscribeCreationFailedFault("Could not parse EPLFilter markup.");
    }
}

From source file:org.nerve.utils.encode.EncodeUtils.java

public static String xmlUnescape(String xmlEscaped) {
    return StringEscapeUtils.unescapeXml(xmlEscaped);
}

From source file:org.occupycincy.android.OccupyCincyActivity.java

private void parseOccupyFeed() {

    try {//from w w  w .j  a v  a  2 s .  c om
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(new File(getFullPath(getString(R.string.occupy_feed_file))));

        doc.getDocumentElement().normalize();

        NodeList nList = doc.getElementsByTagName("item");

        for (int i = 0; i < nList.getLength(); i++) {

            Node nNode = nList.item(i);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                Element eElement = (Element) nNode;

                HashMap<String, String> item = new HashMap<String, String>();

                item.put("title", getTagValue("title", eElement));
                item.put("link", getTagValue("link", eElement));
                item.put("description", StringEscapeUtils.unescapeXml(getTagValue("description", eElement)));

                feedItems.add(item);
            }
        }
    } catch (Exception e) {
        showAlert(e.getMessage());
    }
}