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:it.jugpadova.blo.EventResourceBo.java
public String manageEventLinkResource(Long eventResourceId, Long eventId, String url, String description, boolean canUserManageTheEvent) { EventLink link = null;/*from ww w. java 2 s . com*/ String display = null; if (eventResourceId == null) { // new resource link = new EventLink(); link.setEvent(eventDao.read(eventId)); display = "none"; logger.info("Creating new link resource for the event " + eventId + " (" + url + ")"); } else { // update resource link = eventLinkDao.read(eventResourceId); display = "block"; logger.info( "Updating link resource " + eventResourceId + " for the event " + eventId + " (" + url + ")"); } link.setDescription(description); link.setUrl(url); eventLinkDao.store(link); WebContext wctx = WebContextFactory.get(); String result = null; try { result = wctx.forwardToString("/WEB-INF/jsp/event/resources/link.jsp?id=" + link.getId() + "&url=" + URLEncoder.encode(link.getUrl(), "UTF-8") + "&abbreviatedUrl=" + URLEncoder.encode(StringUtils.abbreviate(link.getUrl(), 40), "UTF-8") + "&description=" + URLEncoder.encode(link.getDescription(), "UTF-8") + "&canUserManageTheEvent=" + canUserManageTheEvent + "&display=" + display); } catch (Exception ex) { logger.error("Error calling link page fragment", ex); } return result; }
From source file:de.fu_berlin.inf.dpp.concurrent.jupiter.internal.text.InsertOperation.java
/** * {@inheritDoc}/* w w w .j a v a2 s.com*/ */ @Override public String toString() { return "Insert(" + this.position + ",'" + StringEscapeUtils.escapeJava(StringUtils.abbreviate(this.text, 150)) + "'," + this.origin + ")"; }
From source file:mobi.chouette.model.Network.java
/** * set source name <br/>/*from ww w.ja v a2 s. c o m*/ * truncated to 255 characters if too long * * @param value * New value */ public void setSourceName(String value) { sourceName = StringUtils.abbreviate(value, 255); }
From source file:de.tudarmstadt.lt.n2n.io.SemEvalReader.java
public void parse(CAS aCas) throws CASException { String line = _last_line;//from w w w . ja v a 2 s . c o m while (!_semeval_sentence_pattern.matcher(line).matches()) { LOG.warn( "Error while parsing line {}: '{}'. Line format does not match the desired semeval sentence input format. Skipping line.", _line_iter.getCurentLineNumber(), line); if (!_line_iter.hasNext()) return; line = _line_iter.next(); } // new sentence == new cas initCas(aCas, _current_resource, String.valueOf(_line_iter.getCurentLineNumber())); JCas aJCas = aCas.getJCas(); LOG.trace("parsing line {}: '{}', treating as new sentence.", _line_iter.getCurentLineNumber(), StringUtils.abbreviate(line, 35)); Relation relation = new Relation(aJCas); try { int s_begin = line.indexOf("\""); int sentence_id = Integer.parseInt(line.substring(0, s_begin).trim()); s_begin += 1; int e1_begin = line.indexOf("<e1>") - s_begin; int e1_end = line.indexOf("</e1>") - s_begin - 4; int e2_begin = line.indexOf("<e2>") - s_begin - 4 - 5; int e2_end = line.indexOf("</e2>") - s_begin - 4 - 5 - 4; int s_end = line.lastIndexOf("\""); if (e1_begin < 0 || e1_end < 0 || e2_begin < 0 || e2_end < 0) throw new IllegalStateException( "Could not find occurrences of either <e1>, </e1>, <e2>, </e2> or \"."); String plaintext_sentence = line.substring(s_begin, s_end).replace("<e1>", "").replace("</e1>", "") .replace("<e2>", "").replace("</e2>", ""); Sentence sentence_annotation = null; if (_create_sentence_annos) { sentence_annotation = new Sentence(aJCas, 0, plaintext_sentence.length()); sentence_annotation.addToIndexes(); } if (_create_relation_annos) { Entity e1 = new Entity(aJCas, e1_begin, e1_end); e1.addToIndexes(); Entity e2 = new Entity(aJCas, e2_begin, e2_end); e2.addToIndexes(); relation.setE1(e1); relation.setE2(e2); relation.setCoveringSentence(sentence_annotation); relation.setBegin(0); relation.setEnd(plaintext_sentence.length()); relation.setId(sentence_id); relation.addToIndexes(); relation.setInfo(""); relation.setComment(""); } aJCas.setDocumentText(plaintext_sentence); } catch (Exception e) { LOG.warn("Error while parsing line {}: '{}'\n\t{}: {}", _line_iter.getCurentLineNumber(), line, e.getClass().getName(), e.getMessage()); } if (!_line_iter.hasNext()) return; line = _line_iter.next(); // read infos and comments while (!line.isEmpty() && !_semeval_sentence_pattern.matcher(line).matches()) { if (relation.getInfo() == null) { LOG.trace("parsing line {}: '{}', treating as info from sentence before.", _line_iter.getCurentLineNumber(), StringUtils.abbreviate(line, 35)); relation.setInfo(line); } else { LOG.trace("parsing line {}: '{}', treating as comment from sentence before.", _line_iter.getCurentLineNumber(), StringUtils.abbreviate(line, 35)); relation.setComment(relation.getComment() + line + "\n"); } if (!_line_iter.hasNext()) return; line = _line_iter.next(); } // skip empty lines while (line.isEmpty() && _line_iter.hasNext()) line = _line_iter.next(); _last_line = line; }
From source file:com.github.restdriver.serverdriver.http.response.DefaultResponse.java
private String createSummaryString(int truncateLength) { StrBuilder httpString = new StrBuilder(); httpString.append(protocolVersion).append(" ").append(statusCode).append(" ").append(statusMessage); httpString.appendNewLine();/*from w ww. j a v a 2 s .co m*/ httpString.appendWithSeparators(headers, SystemUtils.LINE_SEPARATOR); if (StringUtils.isNotEmpty(content)) { httpString.appendNewLine(); httpString.appendNewLine(); httpString.append(StringUtils.abbreviate(content, truncateLength)); } return httpString.toString(); }
From source file:com.mothsoft.alexis.domain.Tweet.java
@Override public String getTitle() { if (this.title == null) { this.title = StringUtils.abbreviate(getText(), 100); }//from w w w.ja v a2 s .c o m return this.title; }
From source file:com.sfs.captor.model.Estimate.java
/** * @return the description */ public String getDescriptionAbbrv() { return StringUtils.abbreviate(this.description, Constants.ABBRV_DESC_LEN); }
From source file:com.sfs.captor.model.ProductRelease.java
/** * @return the description abbreviated */ public String getDescriptionAbbrv() { return StringUtils.abbreviate(this.description, 80); }
From source file:com.evolveum.midpoint.wf.impl.util.SingleItemSerializationSafeContainerImpl.java
@Override public T getValue() { if (actualValue != null) { return actualValue; }//from w w w.ja v a2 s .c o m if (valueForStorageWhenNotEncoded != null) { actualValue = valueForStorageWhenNotEncoded; return actualValue; } if (valueForStorageWhenEncoded != null) { if (prismContext == null) { throw new IllegalStateException("PrismContext not set for SerializationSafeContainer holding " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH)); } if (encodingScheme == EncodingScheme.PRISM) { try { actualValue = (T) prismContext.parseAnyData(valueForStorageWhenEncoded, PrismContext.LANG_XML); if (actualValue instanceof Item) { Item item = (Item) actualValue; if (item.isEmpty()) { actualValue = null; } else if (item.size() == 1) { PrismValue itemValue = (PrismValue) item.getValues().get(0); if (itemValue instanceof PrismContainerValue) { actualValue = (T) ((PrismContainerValue) itemValue).asContainerable(); } else if (itemValue instanceof PrismPropertyValue) { actualValue = (T) ((PrismPropertyValue) itemValue).getValue(); } else if (itemValue instanceof PrismReferenceValue) { actualValue = (T) itemValue; // TODO: ok??? } else { throw new SchemaException("Unknown itemValue: " + itemValue); } } else { throw new SchemaException("More than one value after deserialization of " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH) + ": " + item.getValues().size() + " values"); } } } catch (SchemaException e) { throw new SystemException("Couldn't deserialize value from JAXB: " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH), e); } return actualValue; } else { throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme); } } return null; }
From source file:com.evolveum.midpoint.wf.impl.util.SerializationSafeContainer.java
public T getValue() { if (actualValue != null) { return actualValue; }/*from www . j a v a 2s .c o m*/ if (valueForStorageWhenNotEncoded != null) { actualValue = valueForStorageWhenNotEncoded; return actualValue; } if (valueForStorageWhenEncoded != null) { if (prismContext == null) { throw new IllegalStateException("PrismContext not set for SerializationSafeContainer holding " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH)); } if (encodingScheme == EncodingScheme.PRISM) { try { actualValue = (T) prismContext.parseAnyData(valueForStorageWhenEncoded, PrismContext.LANG_XML); if (actualValue instanceof Item) { Item item = (Item) actualValue; if (item.isEmpty()) { actualValue = null; } else if (item.size() == 1) { PrismValue itemValue = (PrismValue) item.getValues().get(0); if (itemValue instanceof PrismContainerValue) { actualValue = (T) ((PrismContainerValue) itemValue).asContainerable(); } else if (itemValue instanceof PrismPropertyValue) { actualValue = (T) ((PrismPropertyValue) itemValue).getValue(); } else if (itemValue instanceof PrismReferenceValue) { actualValue = (T) itemValue; // TODO: ok??? } else { throw new SchemaException("Unknown itemValue: " + itemValue); } } else { throw new SchemaException("More than one value after deserialization of " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH) + ": " + item.getValues().size() + " values"); } } } catch (SchemaException e) { throw new SystemException("Couldn't deserialize value from JAXB: " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH), e); } return actualValue; } else { throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme); } } return null; }