Example usage for org.apache.commons.lang3 StringUtils chomp

List of usage examples for org.apache.commons.lang3 StringUtils chomp

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils chomp.

Prototype

public static String chomp(final String str) 

Source Link

Document

Removes one newline from end of a String if it's there, otherwise leave it alone.

Usage

From source file:org.benjp.services.mongodb.ChatServiceImpl.java

public void edit(String room, String user, String messageId, String message) {
    DBCollection coll = db().getCollection(M_ROOM_PREFIX + room);

    message = StringUtils.chomp(message);
    message = message.replaceAll("&", "&#38");
    message = message.replaceAll("<", "&lt;");
    message = message.replaceAll(">", "&gt;");
    message = message.replaceAll("\"", "&quot;");
    message = message.replaceAll("\n", "<br/>");
    message = message.replaceAll("\\\\", "&#92");

    BasicDBObject query = new BasicDBObject();
    query.put("_id", new ObjectId(messageId));
    query.put("user", user);
    DBCursor cursor = coll.find(query);/*from ww w.  j  ava2 s. c  o  m*/
    if (cursor.hasNext()) {
        DBObject dbo = cursor.next();
        dbo.put("message", message);
        dbo.put("type", TYPE_EDITED);
        coll.save(dbo, WriteConcern.NONE);
    }
}

From source file:org.dbgl.model.conf.Autoexec.java

private void insertCustomSection(final StringBuffer sb, final int sectionNr) {
    if (StringUtils.isNotEmpty(customSections[sectionNr])) {
        sb.append(CUSTOM_SECTION_MARKERS[sectionNr * 2 + 0]).append(PlatformUtils.EOLN);
        sb.append(StringUtils.chomp(customSections[sectionNr])).append(PlatformUtils.EOLN);
        sb.append(CUSTOM_SECTION_MARKERS[sectionNr * 2 + 1]).append(PlatformUtils.EOLN);
    }//from   w w  w.  j a  v a 2 s  .c  om
}

From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java

public void write(String message, String user, String room, String isSystem, String options) {
    DBCollection coll = db().getCollection(M_ROOM_PREFIX + room);

    message = StringUtils.chomp(message);
    message = message.replaceAll("&", "&#38");
    message = message.replaceAll("<", "&lt;");
    message = message.replaceAll(">", "&gt;");
    message = message.replaceAll("\"", "&quot;");
    message = message.replaceAll("\n", "<br/>");
    message = message.replaceAll("\\\\", "&#92");
    message = message.replaceAll("\t", "  ");

    BasicDBObject doc = new BasicDBObject();
    doc.put("user", user);
    doc.put("message", message);
    doc.put("time", new Date());
    doc.put("timestamp", System.currentTimeMillis());
    doc.put("isSystem", isSystem);
    if (options != null) {
        options = options.replaceAll("<", "&lt;");
        options = options.replaceAll(">", "&gt;");
        doc.put("options", options);
    }// w w  w  .  jav a2s  .c  o  m
    coll.insert(doc);

    this.updateRoomTimestamp(room);
}

From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java

public void edit(String room, String user, String messageId, String message) {
    DBCollection coll = db().getCollection(M_ROOM_PREFIX + room);

    message = StringUtils.chomp(message);
    message = message.replaceAll("&", "&#38");
    message = message.replaceAll("<", "&lt;");
    message = message.replaceAll(">", "&gt;");
    message = message.replaceAll("\"", "&quot;");
    message = message.replaceAll("\n", "<br/>");
    message = message.replaceAll("\\\\", "&#92");

    BasicDBObject query = new BasicDBObject();
    query.put("_id", new ObjectId(messageId));
    query.put("user", user);
    DBCursor cursor = coll.find(query);//from  w  ww  . j ava  2  s  . c o m
    if (cursor.hasNext()) {
        DBObject dbo = cursor.next();
        dbo.put("message", message);
        dbo.put("type", TYPE_EDITED);
        dbo.put("lastUpdatedTimestamp", System.currentTimeMillis());
        coll.save(dbo, WriteConcern.NONE);
    }
}

From source file:org.exoplatform.chat.services.mongodb.NotificationServiceImpl.java

public void addNotification(String user, String from, String type, String category, String categoryId,
        String content, String link, String options) {
    DBCollection coll = db().getCollection(M_NOTIFICATIONS);
    BasicDBObject doc = new BasicDBObject();

    content = StringUtils.chomp(content);
    content = content.replaceAll("&", "&#38");
    content = content.replaceAll("<", "&lt;");
    content = content.replaceAll(">", "&gt;");
    content = content.replaceAll("\"", "&quot;");
    content = content.replaceAll("\n", "<br/>");
    content = content.replaceAll("\\\\", "&#92");
    content = content.replaceAll("\t", "  ");

    doc.put("timestamp", System.currentTimeMillis());
    doc.put("user", user);
    doc.put("from", from);
    doc.put("type", type);
    doc.put("category", category);
    doc.put("categoryId", categoryId);
    doc.put("content", content);
    if (options != null) {
        options = options.replaceAll("<", "&lt;");
        options = options.replaceAll(">", "&gt;");
        options = options.replaceAll("'", "\\\\\"");
        //      options = options.replaceAll("\"", "&quot;");
        //      options = options.replaceAll("\\\\", "&#92");
        doc.put("options", options);
    }//from w  w  w .  j  av  a  2 s .c  o  m
    doc.put("link", link);
    doc.put("isRead", false);

    coll.insert(doc);
}

From source file:org.htmlcleaner.XWikiDOMSerializer.java

/**
 * Perform CDATA transformations if the user has specified to use CDATA inside scripts and style elements.
 *
 * @param document the W3C Document to use for creating new DOM elements
 * @param element the W3C element to which we'll add the text content to
 * @param bufferedContent the buffered text content on which we need to perform the CDATA transformations
 * @param item the current HTML Cleaner node being processed
 *///  www  .ja v a2 s  .co m
private void flushContent(Document document, Element element, StringBuffer bufferedContent, Object item) {
    if (bufferedContent.length() > 0 && !(item instanceof ContentNode)) {
        // Flush the buffered content
        boolean specialCase = this.props.isUseCdataForScriptAndStyle() && isScriptOrStyle(element);
        String content = bufferedContent.toString();

        if (this.escapeXml && !specialCase) {
            content = Utils.escapeXml(content, this.props, true);
        } else if (specialCase) {
            content = processCDATABlocks(content);
        }

        // Generate a javascript comment in front on the CDATA block so that it works in IE and when
        // serving XHTML under a mimetype of HTML.
        if (specialCase) {
            if (SCRIPT_TAG_NAME.equalsIgnoreCase(element.getNodeName())) {
                // JS
                element.appendChild(document.createTextNode(JS_COMMENT));
                element.appendChild(document.createCDATASection(NEW_LINE + content + NEW_LINE + JS_COMMENT));
            } else {
                // CSS
                element.appendChild(document.createTextNode(CSS_COMMENT_START));
                element.appendChild(document.createCDATASection(
                        CSS_COMMENT_END + StringUtils.chomp(content) + NEW_LINE + CSS_COMMENT_START));
                element.appendChild(document.createTextNode(CSS_COMMENT_END));
            }
        } else {
            element.appendChild(document.createTextNode(content));
        }

        bufferedContent.setLength(0);
    }
}

From source file:org.kalypso.commons.java.lang.Strings.java

/**
 * @deprecated removes last letter of an string literal (see perl, ruby, etc.)
 */// www  .  j  a  v  a 2s . c  o  m
@Deprecated
public static String chomp(final String s) {
    return StringUtils.chomp(s);
}

From source file:org.kalypso.zml.core.table.binding.ZmlRuleResolver.java

private String getUrl(final String url) {
    final RETokenizer tokenizer = new RETokenizer(new Pattern("#.*"), url); //$NON-NLS-1$

    return StringUtils.chomp(tokenizer.nextToken());
}

From source file:org.kalypso.zml.core.table.binding.ZmlRuleResolver.java

private String getAnchor(final String url) {
    final RETokenizer tokenizer = new RETokenizer(new Pattern(".*#"), url); //$NON-NLS-1$

    return StringUtils.chomp(tokenizer.nextToken());
}

From source file:org.kalypso.zml.ui.table.nat.tooltip.ZmlTableTooltip.java

private String getRuleTooltip(final IZmlModelValueCell cell) throws SensorException {
    final ZmlCellRule[] rules = cell.findActiveRules(m_viewport);
    if (ArrayUtils.isEmpty(rules))
        return null;

    final StringBuffer buffer = new StringBuffer();
    buffer.append(Messages.ZmlTableTooltip_0);

    for (final ZmlCellRule rule : rules) {
        buffer.append(String.format("    - %s\n", rule.getLabel(cell)));//$NON-NLS-1$
    }/*from w  w  w  .j a  v  a2  s .  co  m*/

    return StringUtils.chomp(buffer.toString());
}