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.GWikiNewElementMacro.java

protected void renderNewPageLink(GWikiContext ctx, MacroAttributes attrs) {
    GWikiElement el = ctx.getCurrentElement();
    if (title != null) {
        ctx.append("&title=").append(StringEscapeUtils.escapeXml(title));
    }//from   www.java  2  s  .  com
    if (pageId != null) {
        ctx.append("&pageId=").append(StringEscapeUtils.escapeXml(pageId));
    }
    if (StringUtils.isNotEmpty(metaTemplate) == true) {
        ctx.append("&metaTemplatePageId=").append(StringEscapeUtils.escapeXml(metaTemplate));
    }
    if (parentPage == null) {
        parentPage = el.getElementInfo().getId();
    }
    ctx.append("&parentPageId=").append(StringEscapeUtils.escapeXml(parentPage));
}

From source file:de.micromata.genome.gwiki.page.impl.GWikiWikiPageEditorArtefakt.java

@Override
public boolean renderWithParts(GWikiContext ctx) {
    String thisPageId = null;/* w w  w.  ja  v a 2  s.  c  o  m*/
    if (editBean.isNewPage() == false) {
        thisPageId = editBean.getPageId();
    }
    String pn = partName;
    String html;
    if (useDivEditor == true) {
        String text = textPage.getStorageData();
        text = StringEscapeUtils.escapeXml(text);
        text = StringUtils.replace(text, "\n", "<br/>\n");
        html = Html.div(
                Xml.attrs("id", "textarea" + partName, "class", "wikiEditorTextArea", "contenteditable", "true",
                        "style", "width:100%;height:100%"), //
                Xml.code(text)).toString();
    } else {
        html = Html.textarea(
                Xml.attrs("id", "textarea" + partName, "class", "wikiEditorTextArea", "rows", "30", "cols",
                        "100", "name", partName + ".wikiText", "style", "width:100%;height:100%"), //
                Xml.text(textPage.getStorageData())).toString();

    }
    String tabs = "<div id=\"gwikiWikiEditorFrame" + pn + "\" style=\"width: 100%; height: 100%\">"
            + "<div id='gwikiwktabs" + pn + "'>" + "<ul><li><a href='#WikiEdit" + pn
            + "'><span>Wiki</span></a></li><li>" + "<a href='#WikiRte" + pn
            + "'><span>Rich Text</span></a></li><li><a href='#WikiPreview" + pn
            + "'><span>Preview</span></a></li></ul>" + "<div id='WikiEdit" + pn + "'>" + html + "</div>"
            + "<div id='WikiRte" + pn + "'></div>" + "<div id='WikiPreview" + pn
            + "' style=\"width: 100%; height: 100%; overflow: scroll;\">" // overflow: scroll;
            + "</div>" + "</div>" + "</div>";
    ctx.append(tabs);

    ctx.append("<script type=\"text/javascript\">\n",
            "jQuery(document).ready(function(){\n" + " jQuery(\"#textarea" + pn + "\").gwikiedit({\n",
            "linkAutoCompleteUrl: '", ctx.localUrl("edit/PageSuggestions"), "', partName: '", partName, "' ");
    if (thisPageId != null) {
        ctx.append(", parentPageId: '", thisPageId, "'");
    }
    ctx.append("});\n" + "  gwikicreateEditTab('" + partName + "'); } );\n");
    ctx.append("saveHandlers.push(function(){\n")//
            .append("  gwikiRestoreFromRte(gwikiCurrentPart);\n ")//
            .append("  gwikiUnsetContentChanged();\n")//
            .append("});\n");

    ctx.append("</script>");
    return true;
}

From source file:de.micromata.genome.gwiki.controls.GWikiUserRightsPropsDescriptorValue.java

@Override
public String render(GWikiPropsEditorArtefakt<?> editor, PropsEditContext pct) {
    GWikiAuthorization auth = pct.getWikiContext().getWikiWeb().getAuthorization();
    if ((auth instanceof GWikiAuthorizationExt) == false) {
        return super.render(editor, pct);
    }/*from w  w w  . ja v a 2s. c  o  m*/
    GWikiAuthorizationExt authx = (GWikiAuthorizationExt) auth;
    SortedMap<String, GWikiRight> systemRights = authx.getSystemRights(pct.getWikiContext());
    String pval = pct.getPropsValue();
    SortedMap<String, GWikiRight> usr = authx.getUserRight(pct.getWikiContext(), systemRights, pval);
    for (Map.Entry<String, GWikiRight> me : usr.entrySet()) {
        if (systemRights.containsKey(me.getKey()) == false) {
            systemRights.put(me.getKey(), me.getValue());
        }
    }
    Map<String, List<GWikiRight>> groups = new TreeMap<String, List<GWikiRight>>();

    for (Map.Entry<String, GWikiRight> me : systemRights.entrySet()) {
        List<GWikiRight> gr = groups.get(me.getValue().getCategory());
        if (gr == null) {
            gr = new ArrayList<GWikiRight>();
            groups.put(me.getValue().getCategory(), gr);
        }
        gr.add(me.getValue());
    }

    StringBuilder sb = new StringBuilder();
    sb.append("<ul>\n");

    for (Map.Entry<String, List<GWikiRight>> ge : groups.entrySet()) {
        sb.append("<li>").append(ge.getKey()).append("<br/><ul>");
        for (GWikiRight r : ge.getValue()) {
            if (r.isPrivateRight() == true) {
                continue;
            }
            sb.append("<li><input type=\"checkbox\" name=\"right.").append(r.getName()).append("\"");
            if (usr.containsKey(r.getName()) == true) {
                sb.append(" checked=\"checked\"");
            }
            sb.append(">");
            if (StringUtils.isNotBlank(r.getDescription()) == true) {
                sb.append("<a href=\"#\" title=\"")
                        //
                        .append(StringEscapeUtils.escapeXml(r.getDescription())).append("\">")
                        .append(StringEscapeUtils.escapeXml(r.getName())).append("</a>");
            } else {
                sb.append(StringEscapeUtils.escapeXml(r.getName()));
            }
            sb.append("</li>\n");
        }
        sb.append("</ul></li>\n");
    }
    // for (Map.Entry<String, GWikiRight> me : systemRights.entrySet()) {
    //      
    // }
    sb.append("</ul>\n");
    return sb.toString();// + super.render(editor, pct);
}

From source file:hoot.services.controllers.wps.MarkItemsReviewedWpsTest.java

@Override
protected String getWpsRequestXml(final String mapId) throws Exception {
    return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
            + "<wps:Execute service=\"WPS\" version=\"1.0.0\" "
            + "xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" "
            + "xmlns:ows=\"http://www.opengis.net/ows/1.1\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
            + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
            + "xsi:schemaLocation=\"http://www.opengis../wpsExecute_request.xsd\">" + "<ows:Identifier>"
            + processId + "</ows:Identifier>" + "<wps:DataInputs>" + "<wps:Input>"
            + "<ows:Identifier>mapId</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>"
            + String.valueOf(mapId) + "</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>"
            + "<ows:Identifier>markAll</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>"
            + String.valueOf(false) + "</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>"
            + "<ows:Identifier>reviewedItems</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>" +
            /*StringEscapeUtils.escapeXml(*/
            JsonUtils.objectToJson(ReviewTestUtils.createReviewedItems())/*)*/ + "</wps:LiteralData>"
            + "</wps:Data>" + "</wps:Input>" + "<wps:Input>"
            + "<ows:Identifier>reviewedItemsChangeset</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>"
            + StringEscapeUtils
                    .escapeXml(XmlDocumentBuilder.toString(ReviewTestUtils.createReviewedItemsChangeset()))
            + "</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "</wps:DataInputs>" + "<wps:ResponseForm>"
            + "<wps:ResponseDocument storeExecuteResponse=\"false\" status=\"false\">" + "<wps:Output>"
            + "<ows:Identifier>changesetUploadResponse</ows:Identifier>" + "</wps:Output>" + "<wps:Output>"
            + "<ows:Identifier>numItemsMarkedReviewed</ows:Identifier>" + "</wps:Output>" + "<wps:Output>"
            + "<ows:Identifier>changesetId</ows:Identifier>" + "</wps:Output>" + "</wps:ResponseDocument>"
            + "</wps:ResponseForm>" + "</wps:Execute>";
}

From source file:ezbake.thrift.utils.xml2thrift.sax.StringHandler.java

/**
 * This is an inherited SAX method. The handler extends it to parse XML.
 *///  w  w w .java  2s  .c  o  m
public void characters(char[] ch, int start, int length) {
    StringBuilder sb = new StringBuilder();
    sb.append(ch, start, length);
    String content = sb.toString();

    if (this.espace) {
        content = StringEscapeUtils.escapeXml(content);
    }

    sbEntry.append(content);
}

From source file:com.twilio.sdk.verbs.Verb.java

/**
 * Build the XML representation of the Verb.
 *
 * @param escape whether to escape the XML body
 * @return XML string/*  www .  j a v  a 2 s  .  c  o m*/
 */
private String toXML(final boolean escape) {
    String xml = "<" + this.tag;
    for (String key : attributes.keySet()) {
        xml += " " + key + "=\"" + attributes.get(key) + "\"";
    }
    xml += ">";
    if (this.body != null) {
        final String body = escape ? StringEscapeUtils.escapeXml(this.body) : this.body;
        xml += body;
    }
    for (Verb child : children) {
        xml += child.toXML(escape);
    }
    return xml += "</" + this.tag + ">";
}

From source file:com.quinsoft.zeidon.standardoe.WriteOisToXmlStream.java

private void startElement(final String elementName, final String value, final boolean close,
        final Object... attributes) {
    assert attributes.length % 2 == 0 : "Illegal number of attributes; should be an even number.";
    writeIndent();/* w  ww.j  a  v  a  2  s. c  o m*/
    write("<");
    write(elementName);

    if (attributes != null && attributes.length > 0) {
        for (int i = 0; i < attributes.length; i += 2) {
            // Don't bother printing null attributes.
            if (attributes[i + 1] == null)
                continue;

            String esc = StringEscapeUtils.escapeXml(attributes[i + 1].toString());
            // Don't bother printing if it's empty.
            if (!StringUtils.isBlank(esc))
                write(" %s=\"%s\"", attributes[i], esc);
        }
    }

    if (value != null) {
        String esc = StringEscapeUtils.escapeXml(value);
        write(">%s</%s>", esc, elementName);
        if (!options.isCompressed())
            write("\n");
    } else {
        if (close)
            write("/>");
        else
            write(">");

        if (!options.isCompressed())
            write("\n");
    }
}

From source file:info.magnolia.ui.admincentral.shellapp.pulse.message.MessagesListViewImpl.java

private void constructTable() {
    final Table table = getItemTable();
    table.setCacheRate(1);//from w w  w .j  av  a  2 s.com
    table.addGeneratedColumn(MessageConstants.NEW_PROPERTY_ID, new PulseNewItemColumnGenerator());
    table.setColumnWidth(MessageConstants.NEW_PROPERTY_ID, 100);
    table.addGeneratedColumn(MessageConstants.TYPE_PROPERTY_ID, new MessageTypeColumnGenerator());
    table.setColumnWidth(MessageConstants.TYPE_PROPERTY_ID, 50);
    table.addGeneratedColumn(MessageConstants.TEXT_PROPERTY_ID, new MessageSubjectColumnGenerator());
    table.setColumnWidth(MessageConstants.TEXT_PROPERTY_ID, 450);
    table.addGeneratedColumn(MessageConstants.DATE_PROPERTY_ID, new DateColumnFormatter(null));
    table.setColumnWidth(MessageConstants.DATE_PROPERTY_ID, 150);
    getItemTable().setSortAscending(false);

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

        @Override
        public String generateDescription(Component source, Object itemId, Object propertyId) {
            if (MessageConstants.TEXT_PROPERTY_ID.equals(propertyId)) {
                String subject = (String) ((AbstractSelect) source)
                        .getContainerProperty(itemId, MessageConstants.SUBJECT_PROPERTY_ID).getValue();
                return StringEscapeUtils.escapeXml(subject);
            }
            return null;
        }
    });
}

From source file:com.zyz.mobile.book.UserSpan.java

public String toXML() {
    switch (mType) {
    case BOOKMARK:
        return String.format("<%s %s='%d' %s='%s'/>", UserBookData.Element.BOOKMARK, Attribute.POSITION, mStart,
                Attribute.DESCRIPTION, StringEscapeUtils.escapeXml(mDescription));
    case NOTE://  w  w w  .j a  v a  2 s. co m
        break;
    case HIGHLGHT:
    case UNDERLINE:
        return String.format("<%s %s='%d' %s='%d' %s='%d' %s='%d' %s='%s'/>", UserBookData.Element.SPAN,
                Attribute.TYPE, mType.toValue(), Attribute.COLOR, mColor, Attribute.START, mStart,
                Attribute.END, mEnd, Attribute.DESCRIPTION, StringEscapeUtils.escapeXml(mDescription));
    }
    return "";
}

From source file:com.sunsprinter.diffunit.core.translators.ToXmlTranslator.java

@Override
protected String doTranslate(final T object) throws TranslationException {
    String currentPropertyName = "DIFFUNIT UNKNOWN";
    try {//from  w  w  w  . j  av  a 2 s  .  c om
        final StringBuilder sb = new StringBuilder();

        if (getIncludeEnclosingTags()) {
            sb.append(createStartTag(object.getClass().getSimpleName(), object,
                    getIncludeOuterElementInstanceNumber()));
        }

        final Collection<PropertyDescriptor> eligibleProperties = determinePropertiesEligibleForTranslation(
                object);
        for (final PropertyDescriptor propertyDescriptor : eligibleProperties) {
            currentPropertyName = propertyDescriptor.getName();
            final Object propertyValue = propertyDescriptor.getReadMethod().invoke(object);
            String propertyValueAsString = getDelegateTranslator().translate(propertyValue);
            if (getEscapePropertyValues()) {
                propertyValueAsString = StringEscapeUtils.escapeXml(propertyValueAsString);
            }
            sb.append(String.format("%s%s%s",
                    createStartTag(propertyDescriptor.getName(), propertyValue,
                            getIncludeInnerElementInstanceNumber()),
                    propertyValueAsString, createEndTag(propertyDescriptor.getName())));
        }

        if (getIncludeEnclosingTags()) {
            sb.append(createEndTag(object.getClass().getSimpleName()));
        }

        return sb.toString();
    } catch (final Exception e) {
        throw new TranslationException(object, String.format("Unable to translate property '%s' of object '%s'",
                currentPropertyName, getInstanceTracker().getObjectId(object)), e);
    }
}