Example usage for org.apache.commons.lang StringUtils abbreviate

List of usage examples for org.apache.commons.lang StringUtils abbreviate

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils abbreviate.

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:de.app.tradestory.elasticsearch.Content.java

public String getShortText() {
    return StringUtils.abbreviate(text, 200);
}

From source file:de.tudarmstadt.lt.ltbot.text.BoilerpipeTextExtractor.java

@Override
public String getPlaintext(final String htmltext) {
    try {/*w  w  w  .  ja  va2s  . c  om*/
        String plaintext = ArticleExtractor.getInstance().getText(htmltext);
        return plaintext;
    } catch (Throwable t) {
        for (int i = 1; t != null && i < 10; i++) {
            LOG.log(Level.SEVERE,
                    String.format("Failed to get plaintext from while '%s' (%d %s:%s).",
                            StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()),
                    t);
            t = t.getCause();
        }
        return "Failed to get plaintext content \n" + htmltext;
    }
}

From source file:de.tudarmstadt.lt.lm.service.BreakIteratorStringProvider.java

@Override
public List<String>[] getNgrams(String text, String language_code) throws Exception {
    LOG.trace(String.format("Computing ngrams from text: %s", StringUtils.abbreviate(text, 200)));
    List<String>[] ngrams = null;

    for (String sentence : splitSentences(text, language_code)) {
        List<String> tokens = tokenizeSentence(sentence, language_code);
        if (tokens.isEmpty())
            continue;
        LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(tokens.toString(), 200)));
        List<String>[] current_ngrams = getNgramSequenceFromSentence(tokens);

        LOG.trace(String.format("Current ngrams: %s",
                StringUtils.abbreviate(Arrays.toString(current_ngrams), 200)));
        if (ngrams == null)
            ngrams = current_ngrams;/*from   w  w  w.j  a  v  a 2s  .  c om*/
        else
            ngrams = ArrayUtils.getConcatinatedArray(ngrams, current_ngrams);
    }

    if (ngrams == null)
        ngrams = EMPTY_NGRAM_LIST;
    LOG.trace(String.format("Ngrams for text: '%s': %s ", StringUtils.abbreviate(text, 200),
            StringUtils.abbreviate(Arrays.toString(ngrams), 200)));
    return ngrams;
}

From source file:com.siemens.sw360.portal.tags.OutTag.java

public void setValue(Object value) {
    if (value instanceof String) {

        String candidate = ((String) value);

        if (maxChar > 4) {
            candidate = StringUtils.abbreviate(candidate, maxChar);
        }//from   w  w  w  .  j av a  2  s.c  o m

        this.value = candidate.replaceAll("[\r\n]+", " ");
    } else {
        this.value = value;
    }
}

From source file:mobi.chouette.model.NeptuneIdentifiedObject.java

public void setObjectId(String value) {
    objectId = StringUtils.abbreviate(value, 255);
}

From source file:com.marc.lastweek.extractionengine.extractors.EbayAnunciosProvinceExtractor.java

@Override
protected String getDescriptionFromDetailPage() throws SAXException {
    String description = "";
    HTMLElement descriptionDiv = this.getAdDetailWebResponse().getElementWithID("section1");
    description = StringUtils.abbreviate(descriptionDiv.getText(), 450);
    return description;
}

From source file:net.sf.zekr.engine.bookmark.ui.BookmarkUtils.java

public static void addBookmarkItemToMenu(Menu parentMenu, final BookmarkItem bookmarkItem) {
    final Shell shell = parentMenu.getShell();

    MenuItem menuItem;// ww w  .j a va  2s  .  c  o  m
    if (bookmarkItem.isFolder()) {
        menuItem = new MenuItem(parentMenu, SWT.CASCADE);
        menuItem.setText(StringUtils.abbreviate(bookmarkItem.getName(), GlobalConfig.MAX_MENU_STRING_LENGTH));
        menuItem.setImage(new Image(shell.getDisplay(), resource.getString("icon.menu.bookmark.closeFolder")));
        Menu menu = new Menu(shell, SWT.DROP_DOWN | lang.getSWTDirection());
        menuItem.setMenu(menu);
        // Windows paints the whole menu, if icon changes
        /*
        menu.addMenuListener(new MenuAdapter() {
           public void menuShown(MenuEvent e) {
              Menu m = (Menu) e.widget;
              MenuItem pmi = m.getParentItem();
              if (pmi != null) {
          pmi.setImage(new Image(shell.getDisplay(), resource.getString("icon.menu.bookmark.openFolder")));
              }
           }
                
           public void menuHidden(MenuEvent e) {
              Menu m = (Menu) e.widget;
              MenuItem pmi = m.getParentItem();
              if (pmi != null) {
          pmi.setImage(new Image(shell.getDisplay(), resource.getString("icon.menu.bookmark.closeFolder")));
              }
           }
        });
         */
        List<BookmarkItem> bmChildren = bookmarkItem.getChildren();
        for (BookmarkItem newBookmarkItem : bmChildren) {
            BookmarkUtils.addBookmarkItemToMenu(menu, newBookmarkItem);
        }
    } else {
        menuItem = new MenuItem(parentMenu, SWT.PUSH);
        menuItem.setImage(new Image(shell.getDisplay(), resource.getString("icon.menu.bookmark.item")));
        menuItem.setText(StringUtils.abbreviate(bookmarkItem.getName(), GlobalConfig.MAX_MENU_STRING_LENGTH)
                + " - " + StringUtils.abbreviate(bookmarkItem.getLocations().toString(), 15));
        menuItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                gotoBookmarkLocations(shell, bookmarkItem);
            }
        });
    }
}

From source file:com.neelo.glue.st.StringRenderer.java

public String toString(Object o, String format) {
    try {//from w ww . j a  va  2 s .c  o m
        String[] formats = format.split("[,]");
        String formatted = o.toString();

        for (String f : formats) {
            f = f.trim();

            if (f.equals("uppercase"))
                formatted = formatted.toUpperCase();
            else if (f.equals("lowercase"))
                formatted = formatted.toLowerCase();
            else if (f.equals("capitalize"))
                formatted = StringUtils.capitalize(formatted);
            else if (f.startsWith("abbreviate")) {
                String[] parts = f.split("[:]");
                if (parts.length == 2) {
                    formatted = StringUtils.abbreviate(formatted, Integer.parseInt(parts[1].trim()));
                }
            } else if (f.equals("encode"))
                formatted = URLEncoder.encode(o.toString(), "UTF-8");
            else if (f.equals("csv")) {
                formatted = formatted.replace("\"", "\"\"");
                formatted = "\"" + formatted + "\"";
            }
        }

        return formatted;
    } catch (Exception e) {
        return toString(o);
    }
}

From source file:dk.dma.msinm.common.audit.AuditService.java

/**
 * Asynchronous method for logging a new audit entry
 *
 * @param level the audit level//from   w w  w.  j av a 2  s.  c om
 * @param module the module
 * @param message the message
 * @param exception optionally, an exception
 */
@Asynchronous
public Future<AuditEntry> log(AuditEntry.Level level, String module, String message, Throwable exception) {
    AuditEntry entry = new AuditEntry();
    entry.setCreated(DateTime.now(DateTimeZone.UTC));
    entry.setMessage(StringUtils.abbreviate(message, 200));
    entry.setModule(module);
    entry.setLevel(level);

    if (exception != null) {
        StringWriter sw = new StringWriter();
        exception.printStackTrace(new PrintWriter(sw));
        entry.setStackTrace(StringUtils.abbreviate(sw.toString(), 4000));
    }

    AuditEntry result = saveEntity(entry);
    log.debug("Saved a new audit log " + result);
    return new AsyncResult<>(result);
}

From source file:com.siemens.sw360.portal.tags.DisplayDescription.java

private void abbreviateDescription() {
    if (maxChar > 4) {
        description = StringUtils.abbreviate(description, maxChar);
    }
}