List of usage examples for org.apache.commons.lang3 StringUtils abbreviate
public static String abbreviate(final String str, final int maxWidth)
Abbreviates a String using ellipses.
From source file:org.voyanttools.trombone.input.source.StringInputSource.java
/** * Create a new instance with a string (the content). * //from www . ja v a 2 s .c o m * @param string the content */ public StringInputSource(String string) { this.string = string; this.metadata = new DocumentMetadata(); this.metadata.setLocation("memory"); this.metadata.setSource(Source.STRING); this.metadata.setTitle(StringUtils.abbreviate(string.trim().replaceAll("\\s+", " "), 50)); this.id = DigestUtils.md5Hex(string); }
From source file:org.xwiki.annotation.io.internal.DefaultIOService.java
/** * {@inheritDoc}/*from w w w .j a v a 2s . c o m*/ * <p> * This implementation saves the added annotation in the document where the target of the annotation is. * </p> * * @see org.xwiki.annotation.io.IOService#addAnnotation(String, org.xwiki.annotation.Annotation) */ @Override public void addAnnotation(String target, Annotation annotation) throws IOServiceException { try { // extract the document name from the passed target // by default the fullname is the passed target String documentFullName = target; EntityReference targetReference = referenceResolver.resolve(target, EntityType.DOCUMENT); // try to get a document reference from the passed target reference EntityReference docRef = targetReference.extractReference(EntityType.DOCUMENT); if (docRef != null) { documentFullName = serializer.serialize(docRef); } // now get the document with that name XWikiContext deprecatedContext = getXWikiContext(); XWikiDocument document = deprecatedContext.getWiki().getDocument(documentFullName, deprecatedContext); // create a new object in this document to hold the annotation // Make sure to use a relative reference when creating the XObject, since we can`t use absolute references // for an object's class. This avoids ugly log warning messages. EntityReference annotationClassReference = configuration.getAnnotationClassReference(); annotationClassReference = annotationClassReference .removeParent(annotationClassReference.extractReference(EntityType.WIKI)); int id = document.createXObject(annotationClassReference, deprecatedContext); BaseObject object = document.getXObject(configuration.getAnnotationClassReference(), id); updateObject(object, annotation, deprecatedContext); // and set additional data: author to annotation author, date to now and the annotation target object.set(Annotation.DATE_FIELD, new Date(), deprecatedContext); // TODO: maybe we shouldn't trust what we receive from the caller but set the author from the context. // Or the other way around, set the author of the document from the annotations author. object.set(Annotation.AUTHOR_FIELD, annotation.getAuthor(), deprecatedContext); // store the target of this annotation, serialized with a local serializer, to be exportable and importable // in a different wiki // TODO: figure out if this is the best idea in terms of target serialization // 1/ the good part is that it is a fixed value that can be searched with a query in all objects in the wiki // 2/ the bad part is that copying a document to another space will not also update its annotation targets // 3/ if annotations are stored in the same document they annotate, the targets are only required for object // fields // ftm don't store the type of the reference since we only need to recognize the field, not to also read it. if (targetReference.getType() == EntityType.OBJECT_PROPERTY || targetReference.getType() == EntityType.DOCUMENT) { object.set(Annotation.TARGET_FIELD, localSerializer.serialize(targetReference), deprecatedContext); } else { object.set(Annotation.TARGET_FIELD, target, deprecatedContext); } // set the author of the document to the current user document.setAuthor(deprecatedContext.getUser()); // Note: We make sure to only provide a few characters of contextual information in order to control the // size of the comment (we display the first 30 characters). deprecatedContext.getWiki().saveDocument(document, "Added annotation on \"" + StringUtils.abbreviate(annotation.getSelection(), 30) + "\"", deprecatedContext); } catch (XWikiException e) { throw new IOServiceException("An exception message has occurred while saving the annotation", e); } }
From source file:org.xwiki.contrib.mail.MailContent.java
/** * {@inheritDoc}/*from w w w. j av a 2 s.co m*/ * * @see java.lang.Object#toString() */ @Override public String toString() { XWikiToStringBuilder builder = new XWikiToStringBuilder(this); builder.append("text", StringUtils.abbreviate(text.toString(), 10)); builder.append("html", StringUtils.abbreviate(html.toString(), 10)); builder.append("encrypted", encrypted); builder.append("signed", signed); builder.append("rawAttachments", rawAttachments != null ? rawAttachments.size() : "0"); builder.append("wikiAttachments", wikiAttachments != null ? wikiAttachments.size() : "0"); builder.append("attachedMails", attachedMails != null ? attachedMails.size() : "0"); return builder.toString(); }
From source file:org.xwiki.velocity.tools.JSONTool.java
/** * Parse a serialized JSON into a real JSON object. Only valid JSON strings can be parsed, and doesn't support * JSONP. If the argument is not valid JSON, then {@code null} is returned. * * @param json the string to parse, must be valid JSON * @return the parsed JSON, either a {@link net.sf.json.JSONObject} or a {@link net.sf.json.JSONArray}, or * {@code null} if the argument is not a valid JSON * @since 5.2M1/*from w w w . j a v a 2 s . c om*/ */ // FIXME: directly returning in a public API the object of a dead library, not very nice for something introduced in // 5.2... public JSON parse(String json) { try { return JSONSerializer.toJSON(json); } catch (JSONException ex) { this.logger.info("Tried to parse invalid JSON: [{}], exception was: {}", StringUtils.abbreviate(json, 32), ex.getMessage()); return null; } }
From source file:org.yamj.core.database.model.CastCrew.java
public boolean setJob(final JobType jobType, final String role) { setJobType(jobType);//w w w .j a v a 2s .co m if ((JobType.ACTOR.equals(jobType) || JobType.GUEST_STAR.equals(jobType)) && StringUtils.isNotBlank(role)) { final String newRole = StringUtils.abbreviate(role, 255); if (!StringUtils.equals(getRole(), newRole)) { setRole(newRole); return true; } } return false; }
From source file:ro.dabuno.office.integration.MailMerge.java
private void applyLines(Data dataIn, XWPFDocument doc) throws XmlException, IOException { CTBody body = doc.getDocument().getBody(); XmlOptions optionsOuter = new XmlOptions(); optionsOuter.setSaveOuter();//from w w w. j ava 2 s .c om // read the current full Body text String srcString = body.xmlText(); // apply the replacements boolean first = true; List<String> headers = dataIn.getHeaders(); for (List<String> data : dataIn.getData()) { log.info("Applying to template: " + data); String replaced = srcString; for (int fieldNr = 0; fieldNr < headers.size(); fieldNr++) { String header = headers.get(fieldNr); String value = data.get(fieldNr); // ignore columns without headers as we cannot match them if (header == null) { continue; } // use empty string for data-cells that have no value if (value == null) { value = ""; } replaced = replaced.replace("${" + header + "}", value); } // check for missed replacements or formatting which interferes if (replaced.contains("${")) { log.warn("Still found template-marker after doing replacement: " + StringUtils.abbreviate(StringUtils.substring(replaced, replaced.indexOf("${")), 200)); } appendBody(body, replaced, first); first = false; } }
From source file:ru.mystamps.web.service.SiteServiceImpl.java
private static String abbreviateIfLengthGreaterThan(String text, int maxLength, String fieldName) { if (text == null || text.length() <= maxLength) { return text; }/*from ww w. ja va 2s.c om*/ // TODO(security): fix possible log injection LOG.warn("Length of value for '{}' field ({}) exceeds max field size ({}): '{}'", fieldName, text.length(), maxLength, text); return StringUtils.abbreviate(text, maxLength); }
From source file:shionn.blog.content.RssController.java
private String buildShortContent(String content) { return StringUtils.abbreviate(content, 300); }
From source file:silvertrout.plugins.feedeater.FeedEater.java
private void print(Feed feed, FeedItem feedItem) { String title = StringUtils.abbreviate(feedItem.getTitle(), 80); String content = StringUtils.abbreviate(feedItem.getContent(), 250); String link = feedItem.getLink(); getNetwork().getConnection().sendPrivmsg(feed.getChannel().getName(), "[" + feed.getTitle() + "] \u0002" + title + "\u000f: " + content + " - " + link); }
From source file:storybook.toolkit.TextUtil.java
public static String ellipsize(String text, int max) { return StringUtils.abbreviate(text, max); // old/* w ww.j a v a2s.c om*/ // if (textWidth(text) <= max) // return text; // // // Start by chopping off at the word before max // // This is an over-approximation due to thin-characters... // int end = text.lastIndexOf(' ', max - 3); // // // Just one long word. Chop it off. // if (end == -1) // return text.substring(0, max-3) + "..."; // // // Step forward as long as textWidth allows. // int newEnd = end; // do { // end = newEnd; // newEnd = text.indexOf(' ', end + 1); // // // No more spaces. // if (newEnd == -1) // newEnd = text.length(); // // } while (textWidth(text.substring(0, newEnd) + "...") < max); // // return text.substring(0, end) + "..."; }