List of usage examples for org.apache.commons.lang StringUtils abbreviate
public static String abbreviate(String str, int maxWidth)
Abbreviates a String using ellipses.
From source file:net.sf.zekr.engine.bookmark.ui.BookmarkUtils.java
private static int chooseBookmarkItem(Shell parent, BookmarkItem bookmarkItem) { final Shell shell = new Shell(parent, lang.getSWTDirection() | SWT.TOOL); FillLayout fl = new FillLayout(); fl.marginHeight = fl.marginWidth = 2; shell.setLayout(fl);/*w w w. j av a2 s. c o m*/ _listIndex = -1; Group body = new Group(shell, SWT.NONE); body.setText(StringUtils.abbreviate(bookmarkItem.getName(), GlobalConfig.MAX_MENU_STRING_LENGTH)); fl = new FillLayout(); fl.marginHeight = fl.marginWidth = 2; body.setLayout(fl); final org.eclipse.swt.widgets.List list; list = new org.eclipse.swt.widgets.List(body, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); try { list.setItems( (String[]) CollectionUtils.toStringArray(bookmarkItem.getLocations(), "toDetailedString")); } catch (Exception e) { logger.log(e); } list.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (list.getSelectionCount() != 1) return; if (e.keyCode == '\r') { _listIndex = list.getSelectionIndex(); shell.close(); } } }); list.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { if (list.getSelectionCount() != 1) return; _listIndex = list.getSelectionIndex(); shell.close(); } }); shell.pack(); if (shell.getSize().y > 300) shell.setSize(shell.getSize().x, 300); shell.setLocation(FormUtils.getCenter(parent, shell)); shell.open(); shell.addShellListener(new ShellAdapter() { public void shellDeactivated(ShellEvent e) { shell.close(); } }); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) { shell.getDisplay().sleep(); } } parent.forceActive(); return _listIndex; }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryItemEntity.java
private void initFrom(MimeMessage message) { try {/*from www. j ava2 s.c o m*/ String decodedFrom = null; try { decodedFrom = StringUtils.join( EmailAddressUtils.addressesToStrings(message.getFrom(), true /* mime decode */), ", "); } catch (MessagingException e) { /* * Fallback to raw headers */ decodedFrom = message.getHeader("from", ", "); } fromHeader = StringUtils.abbreviate(decodedFrom, FROM_MAX_LENGTH); } catch (MessagingException e) { logger.debug("Error getting from.", e); } }
From source file:eu.databata.engine.dao.PropagationDAO.java
public void insertHistoryLog(String moduleName, HistoryLogEntry entry) { String sqlText = StringUtils.abbreviate(entry.getSqlText(), MAX_SQLTEXT_LENGTH); String errorText = StringUtils.abbreviate(entry.getSqlErrorText(), MAX_ERRORTEXT_LENGTH); getJdbcTemplate().update("INSERT INTO " + historyLogTable + "(MODULE_NAME, DB_CHANGE_CODE, SQL_TEXT, ROWS_UPDATED, ERROR_CODE, ERROR_TEXT, UPDATE_TIME, EXECUTION_TIME) VALUES(?,?,?,?,?,?,?,?) ", new Object[] { moduleName, entry.getDbChange() == null ? "" : entry.getDbChange(), sqlText, entry.getSqlRows(), entry.getSqlErrorCode(), errorText, entry.getDate(), entry.getExecutionTime() }); }
From source file:net.sf.zekr.engine.translation.TranslationData.java
public String getName(String transNameMode, boolean rtl) { String s = "english".equals(transNameMode) ? name : localizedName; s = StringUtils.abbreviate((rtl ? I18N.RLE + "" : "") + "[" + locale.getLanguage() + "]" + " " + (rtl ? I18N.RLM + "" : "") + s, GlobalConfig.MAX_MENU_STRING_LENGTH); return s;/*from ww w. j ava 2 s. c o m*/ }
From source file:ch.ksfx.web.pages.admin.note.ManageNote.java
public String getAbbreviatedNoteFileComment() { if (noteFile.getComment() != null) { return StringUtils.abbreviate(noteFile.getComment(), 100); }/* ww w .j ava 2s . co m*/ return ""; }
From source file:de.tudarmstadt.lt.lm.app.LineProbPerp.java
void processLine(String line, ModelPerplexity<String> perp, ModelPerplexity<String> perp_oov) { if (line.trim().isEmpty()) { println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); return;/*www . j av a 2s .co m*/ } List<String>[] ngrams; try { List<String> tokens = _lm_prvdr.tokenizeSentence(line); if (tokens == null || tokens.isEmpty()) { println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); return; } ngrams = _lm_prvdr.getNgramSequence(tokens); if (ngrams == null || ngrams.length == 0) { println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); return; } } catch (Exception e) { LOG.error("{}: Could not get ngrams from line '{}'.", _rmi_string, StringUtils.abbreviate(line, 100), e); return; } perp.reset(); perp_oov.reset(); for (List<String> ngram : ngrams) { if (ngram.isEmpty()) continue; try { perp_oov.addLog10Prob(ngram); if (!_lm_prvdr.ngramEndsWithOOV(ngram)) perp.addLog10Prob(ngram); } catch (Exception e) { LOG.error("{}: Could not add ngram '{}' to perplexity.", _rmi_string, ngram); continue; } } println(getOutputLine(line, perp_oov.getN(), perp_oov.getN() - perp.getN(), perp_oov.getLog10Probs(), perp_oov.get(), perp.getLog10Probs(), perp.get())); }
From source file:net.bpelunit.framework.control.util.ActivityUtil.java
/** * Returns a name suitable for displaying to the user. This includes * additional info like operation names etc. so that a user can easily see * which activity is meant//from w w w . ja v a 2 s . c o m * * @param presumedActivity * @return */ public static String getUIName(Object presumedActivity) { if (presumedActivity instanceof XMLSoapActivity && ActivityUtil.getParentActivityFor(presumedActivity) == null) { XMLSoapActivity xml = (XMLSoapActivity) presumedActivity; String operation = xml.getOperation(); operation = operation != null ? operation : "n/a"; return operation + " (" + ActivityUtil.getNiceName(presumedActivity) + ")"; } if (presumedActivity instanceof XMLCompleteHumanTaskActivity) { XMLCompleteHumanTaskActivity xml = (XMLCompleteHumanTaskActivity) presumedActivity; return xml.getTaskName() + " (" + ActivityUtil.getNiceName(presumedActivity) + ")"; } if (ActivityUtil.isActivity(presumedActivity)) { return ActivityUtil.getNiceName(presumedActivity); } else if (presumedActivity instanceof XMLMapping) { return "Data Copy"; } else if (presumedActivity instanceof XMLHeaderProcessor) { return "Header Processor (" + ((XMLHeaderProcessor) presumedActivity).getName() + ")"; } else if (presumedActivity instanceof XMLCondition) { return "Condition (" + StringUtils.abbreviate( BPELUnitUtil.removeSpaceLineBreaks(((XMLCondition) presumedActivity).getExpression()), 100) + ")"; } if (presumedActivity != null) { return presumedActivity.toString(); } else { return ""; } }
From source file:de.tudarmstadt.lt.lm.app.Ngrams.java
public void run_within_sentences(Reader r, String f) { LineIterator liter = new LineIterator(r); for (long lc = 0; liter.hasNext();) { if (++lc % 1000 == 0) LOG.info("Processing line {}:{}", f, lc); try {/*from w w w .j a v a 2 s . c o m*/ String line = liter.next(); if (line.trim().isEmpty()) continue; List<String> sentences = _prvdr.splitSentences(line); if (sentences == null || sentences.isEmpty()) continue; for (String sentence : sentences) { if (sentence == null || sentence.trim().isEmpty()) continue; for (int n = _order_from; n <= _order_to; n++) { List<String>[] ngrams = null; try { List<String> tokens = _prvdr.tokenizeSentence(sentence); if (tokens == null || tokens.isEmpty()) continue; ngrams = _prvdr.getNgramSequence(tokens, n); if (ngrams == null || ngrams.length < 1) continue; } catch (Exception e) { LOG.warn( "Could not get ngram of cardinality {} from String '{}' in line '{}' from file '{}'.", n, StringUtils.abbreviate(line, 100), lc, f); continue; } for (List<String> ngram : ngrams) { if (ngram == null || ngram.isEmpty()) continue; _pout.println(StringUtils.join(ngram, " ")); } _pout.flush(); _num_ngrams += ngrams.length; } } } catch (Exception e) { LOG.warn("Could not process line '{}' in file '{}'.", lc, f); } } }
From source file:eu.uqasar.model.tree.Project.java
@JsonIgnore public String getAbbreviatedName(int maxLength) { return StringUtils.abbreviate(getName(), maxLength); }
From source file:de.iteratec.iteraplan.presentation.tags.IteratecWriteTag.java
/** * Process the start tag./* www .j a v a 2s . co m*/ * * @exception JspException * if a JSP exception has occurred */ @Override public int doStartTagInternal() throws JspException { // Look up the requested bean (if necessary) if (ignore && TagUtils.lookup(pageContext, name, scope) == null) { return SKIP_BODY; // Nothing to output } // Look up the requested property value Object value = TagUtils.lookup(pageContext, name, property, scope); if (value == null) { return SKIP_BODY; // Nothing to output } // Convert value to the String with some formatting String output = formatValue(value); if (this.dashboardText) { IteraplanSyntaxParserService syntaxParserService = getRequestContext().getWebApplicationContext() .getBean(IteraplanSyntaxParserService.class); output = syntaxParserService.convertIteraplanSyntax(output, userAgent); } if (this.wikiText) { WikiParserService wikiParserService = getRequestContext().getWebApplicationContext() .getBean(WikiParserService.class); output = wikiParserService.convertWikiText(output); } if (this.plainText) { WikiParserService wikiParserService = getRequestContext().getWebApplicationContext() .getBean(WikiParserService.class); output = wikiParserService.convertWikiTextToPlainText(output); } if (this.escapeXml) { output = TagUtils.filter(output); } if (this.breaksAndSpaces) { output = TagUtils.breaksAndSpaces(output); } if (this.truncateText) { output = StringUtils.abbreviate(output, DEFAULT_DESCRIPTION_TRUNCATE_AFTER); } TagUtils.write(pageContext, output); // Continue processing this page return SKIP_BODY; }