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

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

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml.

Prototype

@Deprecated
public static final String escapeXml(final String input) 

Source Link

Document

Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => "bread" & "butter" .

Usage

From source file:de.micromata.genome.gwiki.page.impl.wiki.macros.GWikiLocalAnchorMacroBean.java

@Override
public boolean renderImpl(GWikiContext ctx, MacroAttributes attrs) {
    if (RenderModes.NoToc.isSet(ctx.getRenderMode()) == true) {
        return true;
    }/*from w ww. ja v  a2 s . c o  m*/
    String localAnchor = attrs.getArgs().getStringValue("defaultValue");
    ctx.append("<a name='", StringEscapeUtils.escapeXml(localAnchor), "'></a>");
    return true;
}

From source file:cz.incad.kramerius.k5indexer.KrameriusPDFDocument.java

public String getPage(int page) throws Exception {
    logger.log(Level.INFO, "Getting page {0}", page);
    try {//from   www . jav  a2  s . c o m
        PDFTextStripper stripper = new PDFTextStripper(/*"UTF-8"*/);
        if (page != -1) {
            stripper.setStartPage(page);
            stripper.setEndPage(page);
        }

        return StringEscapeUtils.escapeXml(stripper.getText(pdDoc));
    } catch (Exception ex) {
        return "";
    }
}

From source file:main.java.com.surevine.rssimporter.connection.BuddycloudClient.java

public String createPost(String channel, String node, String content) throws IOException {
    StringEntity post = new StringEntity("<entry xmlns=\"http://www.w3.org/2005/Atom\"><content>"
            + StringEscapeUtils.escapeXml(content) + "</content></entry>");
    HttpPost httpPost = new HttpPost(host + "/" + channel + "/content/" + node);
    httpPost.setEntity(post);/*w  ww  .  j  a  va  2 s.  co  m*/
    HttpResponse response = this.execute(httpPost);
    if (response == null) {
        return null;
    }
    return "postid";
}

From source file:com.lyncode.jtwig.functions.builtin.StringFunctions.java

@JtwigFunction(name = "escape", aliases = { "e" })
public String escape(@Parameter String input, @Parameter String strategy) throws FunctionException {
    switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) {
    case HTML:
        return StringEscapeUtils.escapeHtml4(input);
    case JAVASCRIPT:
        return StringEscapeUtils.escapeEcmaScript(input);
    case XML://from   w  w  w  . java  2  s .c  om
        return StringEscapeUtils.escapeXml(input);
    default:
        throw new FunctionException("Unknown escaping strategy " + strategy);
    }
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.macros.GWikiColumnMacro.java

@Override
public boolean renderImpl(GWikiContext ctx, MacroAttributes attrs) {
    ctx.append("<td");
    for (String k : attrs.getArgs().getMap().keySet()) {
        ctx.append(" ").append(k).append("=\"")
                .append(StringEscapeUtils.escapeXml(attrs.getArgs().getStringValue(k))).append("\"");
    }/*from w  w  w .jav  a 2  s  .c o m*/

    ctx.append(">\n");
    if (attrs.getChildFragment() != null) {
        attrs.getChildFragment().render(ctx);
    }
    ctx.append("\n</td>");
    return true;
}

From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java

public static VirtualCollection doVC(String pid, FedoraAccess fedoraAccess, ArrayList<String> languages) {
    try {//from w w  w.j  a  v a 2  s.  com
        String xPathStr;
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr;

        ArrayList<String> langs = new ArrayList<String>();
        if (languages == null || languages.isEmpty()) {
            String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
            for (int i = 0; i < ls.length; i++) {
                String lang = ls[++i];
                langs.add(lang);
            }
        } else {
            langs = new ArrayList<String>(languages);
        }
        String name = "";
        boolean canLeave = true;
        fedoraAccess.getDC(pid);
        Document doc = fedoraAccess.getDC(pid);
        xPathStr = "//dc:title/text()";
        expr = xpath.compile(xPathStr);
        Node node = (Node) expr.evaluate(doc, XPathConstants.NODE);
        if (node != null) {
            name = StringEscapeUtils.escapeXml(node.getNodeValue());
        }

        xPathStr = "//dc:type/text()";
        expr = xpath.compile(xPathStr);
        node = (Node) expr.evaluate(doc, XPathConstants.NODE);
        if (node != null) {
            canLeave = Boolean.parseBoolean(StringEscapeUtils.escapeXml(node.getNodeValue()));
        }
        VirtualCollection vc = new VirtualCollection(name, pid, canLeave);

        for (String lang : langs) {
            String dsName = TEXT_DS_PREFIX + lang;
            String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName),
                    Charset.forName("UTF8"), true);
            vc.addDescription(lang, value);
        }
        return vc;
    } catch (Exception vcex) {
        logger.log(Level.WARNING, "Could not get virtual collection for  " + pid + ": " + vcex.toString());
        return null;
    }
}

From source file:com.thruzero.applications.faces.demo.beans.page.EscapeToolBean.java

public String escapeTextAction() {
    if ("xml".equals(escapeType)) {
        escapedText = StringEscapeUtils.escapeXml(inputText);
    } else if ("html4".equals(escapeType)) {
        escapedText = StringEscapeUtils.escapeHtml4(inputText);
    } else if ("java".equals(escapeType)) {
        escapedText = StringEscapeUtils.escapeJava(inputText);
    } else {/*w ww.j  ava  2  s.  c om*/
        throw new RuntimeException("Unknown Escape selection");
    }

    String flashHackKey = FlashUtils.saveFlashAttribute(escapedText);

    return "/apps/demo/escapeTool.jsf?faces-redirect=true&fhk=" + flashHackKey;
}

From source file:fr.mcc.ginco.imports.AbstractBuilder.java

/**
 * Returns the value of the given property for the given resource
 *
 * @param skosResource//from  w w  w  .ja v a 2  s .  c  o  m
 * @param prop
 * @param altProp      if prop is not found, try altProp
 * @return
 */
public final String getSimpleStringInfo(Resource skosResource, Property prop, Property altProp) {
    Statement stmt = skosResource.getProperty(prop);
    if (stmt != null) {
        String toReturn = stmt.getString();
        if (toReturn != null) {
            return StringEscapeUtils.escapeXml(toReturn.trim());
        }
    } else {
        if (altProp != null) {
            return getSimpleStringInfo(skosResource, altProp);
        }
    }
    return null;
}

From source file:com.xpn.xwiki.plugin.skinx.LinkExtensionPlugin.java

/**
 * {@inheritDoc}//from w  w w. ja  va 2s .c om
 * 
 * @see AbstractSkinExtensionPlugin#getLink(String, XWikiContext)
 */
@Override
public String getLink(String link, XWikiContext context) {
    Map<String, Object> params = getParametersForResource(link, context);
    StringBuilder result = new StringBuilder("<link href=\"" + StringEscapeUtils.escapeXml(link) + "\"");
    for (Entry<String, Object> entry : params.entrySet()) {
        result.append(" ");
        result.append(StringEscapeUtils.escapeXml(entry.getKey()));
        result.append("='");
        result.append(StringEscapeUtils.escapeXml(entry.getValue().toString()));
        result.append("'");
    }
    result.append("/>");
    return result.toString();
}

From source file:de.weltraumschaf.jebnf.ast.visitor.XmlVisitor.java

/**
 * Creates a opening tag string by name.
 *
 * @param name The tag name.//from  w  w  w  .  j  a  va 2 s  .  c  o  m
 * @param attributes Optional tag attributes.
 * @param block Whether the tag is in line or block.
 * @return Returns formatted tag string.
 */
public static String createOpenTag(final String name, final Map<NodeAttribute, String> attributes,
        final boolean block) {
    final StringBuilder tag = new StringBuilder();
    tag.append('<').append(name);

    if (null != attributes && !attributes.isEmpty()) {
        for (Map.Entry<NodeAttribute, String> attribute : attributes.entrySet()) {
            tag.append(String.format(" %s=\"%s\"", attribute.getKey().toString().toLowerCase(),
                    StringEscapeUtils.escapeXml(attribute.getValue())));
        }
    }

    if (!block) {
        tag.append('/');
    }

    return tag.append('>').toString();
}