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.fragment.GWikiFragmentImage.java

@Override
@SuppressWarnings("unchecked")
public boolean render(GWikiContext ctx) {
    if (RenderModes.NoImages.isSet(ctx.getRenderMode()) == true) {
        return true;
    }// ww  w  . j  ava 2s. c  o m
    String lwidth = width;
    String ltarget = target;
    if (RenderModes.LocalImageLinks.isSet(ctx.getRenderMode()) == true) {

        String o = ObjectUtils.toString(ctx.getRequestAttribute(WIKI_MAX_IMAGE_WIDTH));
        if (o != null && lwidth == null) {
            lwidth = o;
        }
    }
    Set<String> set = (Set<String>) ctx.getRequestAttribute(WIKIGENINCLUDEDIMAGES);
    if (set != null) {
        set.add(ltarget);
    }
    if (StringUtils.isNotEmpty(thumbnail) == true) {
        ctx.append("<a class='showimage' href='" + StringEscapeUtils.escapeXml(ltarget) + "'>");
    }
    if (GWikiFragmentLink.isGlobalUrl(target) == true) {
        // ctx.append("<img src='", target, "'>");
    } else {
        if (RenderModes.GlobalImageLinks.isSet(ctx.getRenderMode()) == true) {
            ltarget = ctx.globalUrl(target);
        } else if (RenderModes.LocalImageLinks.isSet(ctx.getRenderMode()) == true) {
            ltarget = target;
        } else {
            ltarget = ctx.localUrl(target);
        }
    }
    ctx.append("<img src='", StringEscapeUtils.escapeXml(ltarget), "'");
    if (StringUtils.isNotEmpty(lwidth) == true) {
        ctx.append(" width='", StringEscapeUtils.escapeXml(lwidth), "'");
    }
    if (StringUtils.isNotEmpty(height) == true) {
        ctx.append(" height='", StringEscapeUtils.escapeXml(height), "'");
    }
    if (StringUtils.isNotEmpty(border) == true) {
        ctx.append(" border='", StringEscapeUtils.escapeXml(border), "'");
    }
    if (StringUtils.isNotEmpty(alt) == true) {
        ctx.append(" alt='", StringEscapeUtils.escapeXml(alt), "'");
    } else {
        ctx.append(" alt=''");
    }
    if (StringUtils.isNotEmpty(hspace) == true) {
        ctx.append(" hspace='", StringEscapeUtils.escapeXml(hspace), "'");
    }
    if (StringUtils.isNotEmpty(width) == true) {
        ctx.append(" width='", StringEscapeUtils.escapeXml(width), "'");
    }
    if (StringUtils.isNotEmpty(style) == true) {
        ctx.append(" style='", StringEscapeUtils.escapeXml(style), "'");
    }

    String tstyleClass = "weditimg";
    if (StringUtils.isNotEmpty(styleClass) == true) {
        tstyleClass += " " + styleClass;
    }
    if (StringUtils.isNotEmpty(thumbnail) == true) {
        if (thumbnail.equals("small") == true || thumbnail.equals("large") == true) {
            tstyleClass += " " + thumbnail;
        } else {
            tstyleClass += " mediumThumb";
        }
    }
    ctx.append(" class='", StringEscapeUtils.escapeXml(tstyleClass), "'");
    if (RenderModes.ForRichTextEdit.isSet(ctx.getRenderMode()) == true) {
        ctx.append(" data-wiki-url='", StringEscapeUtils.escapeXml(target), "'");
        ctx.append(" data-wiki-height='", StringEscapeUtils.escapeXml(height), "'");
        ctx.append(" data-wiki-width='", StringEscapeUtils.escapeXml(width), "'");
        ctx.append(" data-wiki-style='", StringEscapeUtils.escapeXml(style), "'");
        ctx.append(" data-wiki-styleClass='", StringEscapeUtils.escapeXml(styleClass), "'");
        ctx.append(" data-wiki-thumbnail='", StringEscapeUtils.escapeXml(thumbnail), "'");

    }
    ctx.append("/>");
    if (StringUtils.isNotEmpty(thumbnail) == true) {
        ctx.append("</a>");
    }
    return true;
}

From source file:ee.ria.xroad.common.message.SoapFault.java

/**
 * Creates a SOAP fault message.//from w ww  .  j a v a 2  s .  c o m
 * @param faultCode code of the new SOAP fault
 * @param faultString string of the new SOAP fault
 * @param faultActor actor of the new SOAP fault
 * @param detail detail of the new SOAP fault
 * @return a String containing XML of the SOAP fault represented by the given parameters
 */
public static String createFaultXml(String faultCode, String faultString, String faultActor, String detail) {
    return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\""
            + SOAP_NS_SOAP_ENV + "\">" + "<SOAP-ENV:Body>" + "<SOAP-ENV:Fault>" + "<faultcode>" + faultCode
            + "</faultcode>" + "<faultstring>" + StringEscapeUtils.escapeXml(faultString) + "</faultstring>"
            + (faultActor != null ? "<faultactor>" + StringEscapeUtils.escapeXml(faultActor) + "</faultactor>"
                    : "")
            + (detail != null
                    ? "<detail><faultDetail xmlns=\"\">" + StringEscapeUtils.escapeXml(detail)
                            + "</faultDetail>" + "</detail>"
                    : "")
            + "</SOAP-ENV:Fault>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";
}

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

@Override
public boolean renderImpl(GWikiContext ctx, MacroAttributes attrs) {
    if (RenderModes.ForIndex.isSet(ctx.getRenderMode()) == true) {
        ctx.append(WebUtils.escapeHtml(attrs.getBody()));
        return true;
    }/*w  w w. j ava  2s .  c o  m*/
    String body = attrs.getBody();
    body = StringUtils.trim(body);
    String clang = determineLang(body);
    if (RenderModes.ForRichTextEdit.isSet(ctx.getRenderMode()) == true) {
        ctx.append("<pre");
        if (StringUtils.isNotBlank(clang) == true) {
            ctx.append(" class='language-" + clang + "'");
        }
        ctx.append(" contenteditable='false'>");
        ctx.append(WebUtils.escapeHtml(body));
        ctx.append("</pre>");
        return true;

    }
    //      // TODO attributes rendering
    //      String body = attrs.getBody();
    //
    //      body = WebUtils.escapeHtml(body);
    //
    //      ctx.append("<pre class=\"wikiCode\"");
    //      Html2WikiTransformInfo.renderMacroArgs(ctx, attrs);
    //      ctx.append(">").append(body).append("</pre>");
    //      return true;
    //    }

    boolean forText = RenderModes.ForText.isSet(ctx.getRenderMode());

    ctx.append("<pre><code");

    if (StringUtils.isNotBlank(clang) == true) {
        ctx.append(" class='language-" + clang + "'");
    }
    if (forText == false) {
        body = StringEscapeUtils.escapeXml(body);
    }
    ctx.append(">").append(body).append("</code></pre>");

    return true;
}

From source file:de.topobyte.osm4j.xml.output.OsmXmlOutputStream.java

@Override
public void write(OsmRelation relation) {
    out.print("  <relation id=\"" + relation.getId() + "\"");
    if (printMetadata) {
        OsmMetadata metadata = relation.getMetadata();
        printMetadata(metadata);/*from  ww  w. j  a  v a2s .  co  m*/
    }
    if (relation.getNumberOfTags() == 0 && relation.getNumberOfMembers() == 0) {
        out.println("/>");
    } else {
        out.println(">");
        for (int i = 0; i < relation.getNumberOfMembers(); i++) {
            OsmRelationMember member = relation.getMember(i);
            EntityType type = member.getType();
            String t = type == EntityType.Node ? "node" : type == EntityType.Way ? "way" : "relation";
            String role = member.getRole();
            role = StringEscapeUtils.escapeXml(role);
            out.println(
                    "    <member type=\"" + t + "\" ref=\"" + member.getId() + "\" role=\"" + role + "\"/>");
        }
        printTags(relation);
        out.println("  </relation>");
    }
}

From source file:info.magnolia.ui.admincentral.shellapp.pulse.task.TasksListViewImpl.java

private void constructTable() {
    Table table = getItemTable();/*  w w w.  ja  va 2  s.com*/
    table.setCacheRate(1);
    table.addGeneratedColumn(NEW_PROPERTY_ID, new PulseNewItemColumnGenerator());
    table.setColumnWidth(NEW_PROPERTY_ID, 100);
    table.addGeneratedColumn(TASK_PROPERTY_ID, new TaskSubjectColumnGenerator());
    table.setColumnWidth(TASK_PROPERTY_ID, 220);
    table.addGeneratedColumn(STATUS_PROPERTY_ID, new TaskStatusColumnGenerator());
    table.setColumnWidth(STATUS_PROPERTY_ID, 80);
    table.addGeneratedColumn(SENT_TO_PROPERTY_ID, new SentToColumnGenerator());
    table.setColumnWidth(SENT_TO_PROPERTY_ID, 100);
    table.addGeneratedColumn(LAST_CHANGE_PROPERTY_ID, new DateColumnFormatter(null));
    table.setColumnWidth(LAST_CHANGE_PROPERTY_ID, 140);
    table.setSortAscending(false);

    // tooltips
    table.setItemDescriptionGenerator(new AbstractSelect.ItemDescriptionGenerator() {

        @Override
        public String generateDescription(Component source, Object itemId, Object propertyId) {
            if (String.valueOf(itemId).startsWith(PulseConstants.GROUP_PLACEHOLDER_ITEMID)) {
                return null;
            }

            if (TASK_PROPERTY_ID.equals(propertyId)) {
                String task = (String) ((AbstractSelect) source).getContainerProperty(itemId, TASK_PROPERTY_ID)
                        .getValue();
                if (StringUtils.isNotBlank(task)) {
                    // title only
                    String title = task.split("\\|")[0];
                    return StringEscapeUtils.escapeXml(title);
                }

            } else if (SENT_TO_PROPERTY_ID.equals(propertyId)) {
                String sentTo = (String) ((AbstractSelect) source)
                        .getContainerProperty(itemId, SENT_TO_PROPERTY_ID).getValue();
                if (StringUtils.isNotBlank(sentTo)) {
                    // prepare group/user labels
                    String[] parts = sentTo.split("\\|");
                    String groups = parts[0];
                    String users = "";
                    if (parts.length == 2) {
                        users = parts[1];
                    }
                    return groups + " " + users;
                }
            }
            return null;
        }
    });
}

From source file:de.micromata.genome.gwiki.plugin.blog_1_0.GWikiBlogActionBean.java

protected void deliverRss() {
    // <?xml version="1.0"?>
    // <rss version="2.0">
    // <channel>
    // <title>Liftoff News</title>
    // <link>http://liftoff.msfc.nasa.gov/</link>
    // <description>Liftoff to Space Exploration.</description>
    // <language>en-us</language>
    // <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
    ///*from  w  w w  .jav  a2s  . c  o  m*/
    // <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
    // <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    // <generator>Weblog Editor 2.0</generator>
    // <managingEditor>editor@example.com</managingEditor>
    // <webMaster>webmaster@example.com</webMaster>
    // <item>
    //
    // <title>Star City</title>
    // <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
    // <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in
    // culture, language and protocol at Russia's &lt;a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm"&gt;Star City&lt;/a&gt;.</description>
    // <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
    // <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>
    //
    // </item>
    //         
    // </channel>
    // </rss>
    wikiContext.getResponse().setContentType("text/xml");
    wikiContext.append("<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n").append("<channel>\n") //
            .append("<title>" + StringEscapeUtils.escapeXml(blogPage.getTitle()) + "</title>\n") //
            .append("<link>" + wikiContext.getWikiWeb().getWikiConfig().getPublicURL()
                    + StringEscapeUtils.escapeXml(blogPage.getId()) + "</link>\n") //

    ;
    // <description>Liftoff to Space Exploration.</description>
    // <language>en-us</language>
    // <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
    //
    // <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
    // <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    // <generator>Weblog Editor 2.0</generator>
    // <managingEditor>editor@example.com</managingEditor>
    // <webMaster>webmaster@example.com</webMaster>
    for (GWikiElementInfo ei : blogEntries) {
        wikiContext.append("<item>\n")//
                .append("<title>" + StringEscapeUtils.escapeXml(ei.getTitle()) + "</title>\n") //
                .append("<link>" + wikiContext.getWikiWeb().getWikiConfig().getPublicURL()
                        + StringEscapeUtils.escapeXml(ei.getId()) + "</link>\n") //
                .append("</item>\n") //
        ;
    }
    wikiContext.append("</channel>\n</rss>\n");
    wikiContext.flush();
}

From source file:com.gdo.util.XmlWriter.java

/**
 * Writes attribute to the opened tag (the value is XML escaped).
 * //from   w  w  w  . ja v a 2 s  .  com
 * @param name
 *            attribute's name.
 * @param value
 *            string attribute's value.
 */
public void writeAttribute(String name, Object value) throws IOException {
    if (StringUtils.isEmpty(name)) {
        throw new NullPointerException("XML attribute name must not be null");
    }
    if (value != null) {
        _writer.write(' ');
        _writer.write(name);
        _writer.write("=\"");
        _writer.write(StringEscapeUtils.escapeXml(value.toString()));
        _writer.write('"');
    }
}

From source file:edu.eurac.commul.pepperModules.mmax2.SaltExtendedFileGenerator.java

protected static String EscapeString(String original) throws MMAX2WrapperException {
    String copy = original + "";
    return EscapeStringSimple(StringEscapeUtils.escapeXml(copy));
}

From source file:net.mindengine.oculus.frontend.web.controllers.api.report.ApiReportSuiteController.java

private String serializeSuiteRunParameters(Map<String, String> parameters) {
    if (parameters != null) {
        StringBuffer serializedParameters = new StringBuffer();
        for (Map.Entry<String, String> parameter : parameters.entrySet()) {
            serializedParameters.append("<p>");
            serializedParameters.append(StringEscapeUtils.escapeXml(parameter.getKey()));
            serializedParameters.append("<v>");
            serializedParameters.append(StringEscapeUtils.escapeXml(parameter.getValue()));
            serializedParameters.append("<p>");
        }// w w w.  ja  va2 s .  c o m
        return serializedParameters.toString();
    } else
        return "";
}

From source file:com.nuance.expertassistant.ContentExtractor.java

public static String stripNonValidXMLCharacters(String in) {

    String output = in.replaceAll(">>", "");

    output = output.replaceAll(">>", "").replaceAll("\n", "").replaceAll("\"", "").replaceAll("\u201c", "")
            .replaceAll("\u201d", "").replaceAll("\u2022", "").replaceAll("&", "");

    return StringEscapeUtils.escapeXml(output);

    /*// w  ww  .java 2s. c om
     * StringBuffer out = new StringBuffer(); // Used to hold the output.
     * char current; // Used to reference the current character.
     *
     * if (in == null || in.equalsIgnoreCase("")) { return null; }
     *
     * for (int i = 0; i < in.length(); i++) { current = in.charAt(i); //
     * NOTE: No IndexOutOfBoundsException caught here; it should not happen.
     * if ((current == 0x9) || (current == 0xA) || (current == 0xD) ||
     * ((current >= 0x20) && (current <= 0xD7FF)) || ((current >= 0xE000) &&
     * (current <= 0xFFFD)) || ((current >= 0x10000) && (current <=
     * 0x10FFFF))) { out.append(current); } }
     *
     * return out.toString().replaceAll(">>", "");
     */

}