Java Code Examples for org.apache.commons.lang.StringUtils#abbreviate()

The following examples show how to use org.apache.commons.lang.StringUtils#abbreviate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhpElementsUtil.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
public static String getClassDeprecatedMessage(@NotNull PhpClass phpClass) {
    if (phpClass.isDeprecated()) {
        PhpDocComment docComment = phpClass.getDocComment();
        if (docComment != null) {
            for (PhpDocTag deprecatedTag : docComment.getTagElementsByName("@deprecated")) {
                String tagValue = deprecatedTag.getTagValue();
                if (StringUtils.isNotBlank(tagValue)) {
                    return StringUtils.abbreviate("Deprecated: " + tagValue, 100);
                }
            }
        }
    }

    return null;
}
 
Example 2
Source File: ConnectionInformationMetaData.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String getDescription() {
	final StringBuilder builder = new StringBuilder(super.getDescription());
	ConnectionConfiguration config = Optional.ofNullable(getConfiguration()).orElse(UNKNOWN_CONNECTION);
	String tags = String.join(TAG_DELIMITER, Optional.ofNullable(config.getTags()).orElseGet(Collections::emptyList)).trim();
	String description = StringUtils.abbreviate(Objects.toString(config.getDescription(), "").trim(), DESCRIPTION_PREVIEW_LENGTH);

	if (!description.isEmpty()) {
		builder.append("<p style='margin-top:2px;margin-bottom:3px;'>").append(description).append("</p>");
	}

	if (!tags.isEmpty()) {
		builder.append("<p style='margin-top:2px;'>");
		builder.append(I18N.getGUILabel("connection.metadata.connection_type.tags.label")).append(" ");
		builder.append(tags).append("</p>");
	}

	return builder.toString();
}
 
Example 3
Source File: TajoAdmin.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
public static void processList(Writer writer, TajoClient client) throws ParseException, IOException,
    ServiceException, SQLException {
  List<BriefQueryInfo> queryList = client.getRunningQueryList();
  SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
  String fmt = "%1$-20s %2$-7s %3$-20s %4$-30s%n";
  String line = String.format(fmt, "QueryId", "State", 
                "StartTime", "Query");
  writer.write(line);
  line = String.format(fmt, line20, line7, line20, line30);
  writer.write(line);

  for (BriefQueryInfo queryInfo : queryList) {
      String queryId = String.format("q_%s_%04d",
                                     queryInfo.getQueryId().getId(),
                                     queryInfo.getQueryId().getSeq());
      String state = getQueryState(queryInfo.getState());
      String startTime = df.format(queryInfo.getStartTime());

      String sql = StringUtils.abbreviate(queryInfo.getQuery(), 30);
      line = String.format(fmt, queryId, state, startTime, sql);
      writer.write(line);
  }
}
 
Example 4
Source File: Twitter.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sends a direct message via Twitter
 *
 * @param recipientId
 *            the receiver of this direct message
 * @param messageTxt
 *            the direct message to send
 *
 * @return <code>true</code>, if sending the direct message has been successful
 *         and <code>false</code> in all other cases.
 */
@ActionDoc(text = "Sends a direct message via Twitter", returns = "<code>true</code>, if sending the direct message has been successful and <code>false</code> in all other cases.")
public static boolean sendDirectMessage(
        @ParamDoc(name = "recipientId", text = "the receiver of this direct message") String recipientId,
        @ParamDoc(name = "messageTxt", text = "the direct message to send") String messageTxt) {
    if (!checkPrerequisites()) {
        return false;
    }

    try {
        // abbreviate the Tweet to meet the allowed character limit ...
        messageTxt = StringUtils.abbreviate(messageTxt, CHARACTER_LIMIT);
        // send the direct message
        DirectMessage message = client.sendDirectMessage(recipientId, messageTxt);
        logger.debug("Successfully sent direct message '{}' to @", message.getText(),
                message.getRecipientScreenName());
        return true;
    } catch (TwitterException e) {
        logger.warn("Failed to send Tweet '{}' because of : ", messageTxt, e.getLocalizedMessage());
        return false;
    }
}
 
Example 5
Source File: TextRenderer.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private String formatColumn(ReportColumn c, String value) {
    if (IntegerUtil.assign(c.getSize(), 0) > 3) {
        if (c.isTruncate()) {
            return StringUtils.leftPad(truncate(c.getSize(), value), c.getSize());
        }
        return StringUtils.abbreviate(StringUtils.leftPad(value, c.getSize()), c.getSize());
    }
    return StringUtils.leftPad(truncate(c.getSize(), value), c.getSize());
}
 
Example 6
Source File: MyEvent.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param title
 * @param labelValues {{"text without label"}{"value", "label"}, ...}
 * @return
 */
public MyEvent setTooltip(final String title, final String[][] labelValues)
{
  this.tooltipTitle = title;
  final StringBuffer buf = new StringBuffer();
  boolean first = true;
  for (final String[] lv : labelValues) {
    if (lv == null || lv.length < 1 || lv.length > 2) {
      if (WebConfiguration.isDevelopmentMode() == true) {
        throw new IllegalArgumentException("labelValues must be string arrays of length 1 or 2!");
      }
      continue;
    }
    String value = lv[0];
    if (StringUtils.isBlank(value) == true) {
      continue;
    }
    value = StringUtils.abbreviate(value, 80);
    final String label = lv.length == 2 ? lv[1] : null;
    if (first == true) {
      first = false;
    } else {
      buf.append("\n");
    }
    if (label != null) {
      buf.append(label).append(": ").append(value);
    } else {
      buf.append(value);
    }
  }

  if (first == false) {
    buf.append("\n");
  }
  buf.append(PFUserContext.getLocalizedString("timesheet.duration")).append(": ").append(getDuration());
  this.tooltipContent = HtmlHelper.escapeHtml(buf.toString(), true);
  return this;
}
 
Example 7
Source File: OverviewChartLayout.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
protected void pointClicked( JSONObject json ) throws JSONException {
    super.pointClicked( json );

    String caption = "Commit: " + StringUtils.abbreviate( json.getString( "commitId" ), 10 );
    nextChartButton.setCaption( caption );
    nextChartButton.setVisible( true );
}
 
Example 8
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public String getElementText(PsiElement psiElement) {
    return StringUtils.abbreviate(
        SymbolPresentationUtil.getSymbolPresentableText(psiElement),
        50
    );
}
 
Example 9
Source File: PhpCommandGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {

    Collection<LookupElement> elements = new ArrayList<>();

    Map<String, CommandArg> targets = getCommandConfigurationMap(phpClass, addMethod);

    for(CommandArg key: targets.values()) {
        LookupElementBuilder lookup = LookupElementBuilder.create(key.getName()).withIcon(Symfony2Icons.SYMFONY);

        String description = key.getDescription();
        if(description != null) {

            if(description.length() > 25) {
                description = StringUtils.abbreviate(description, 25);
            }

            lookup = lookup.withTypeText(description, true);
        }

        if(key.getDefaultValue() != null) {
            lookup = lookup.withTailText("(" + key.getDefaultValue() + ")", true);
        }

        elements.add(lookup);
    }

    return elements;
}
 
Example 10
Source File: IterationsChartLayout.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private String firstMessages(JSONArray arr) {

        String s = "";
        int len = Math.min(5, arr.length());

        for (int i = 0; i < len; i++) {
            JSONObject json = JsonUtil.get(arr, i);

            s += "* " + StringUtils.abbreviate( json.optString( "message" ), 200 ) + "\n"
                    + StringUtils.abbreviate(json.optString("trace"), 500) + "\n\n";
        }

        return s;
    }
 
Example 11
Source File: SingleMessageLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void nagUserAboutDynamicProperty(String propertyName, Object target, Object value) {
    if (!isEnabled()) {
        return;
    }
    nagUserOfDeprecated("Creating properties on demand (a.k.a. dynamic properties)", "Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties");

    String propertyWithClass = target.getClass().getName() + "." + propertyName;
    if (DYNAMIC_PROPERTIES.add(propertyWithClass)) {
        String propertyWithTarget = String.format("\"%s\" on \"%s\"", propertyName, target);
        String theValue = (value==null)? "null" : StringUtils.abbreviate(value.toString(), 25);
        nagUserWith(String.format("Deprecated dynamic property: %s, value: \"%s\".", propertyWithTarget, theValue));
    } else {
        nagUserWith(String.format("Deprecated dynamic property \"%s\" created in multiple locations.", propertyName));
    }
}
 
Example 12
Source File: BuchungssatzImportRow.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Achtung: Diese Klasse ruft ggf. korrigierend und ändernd check() auf.
 * @see java.lang.Object#toString()
 * @see #check()
 */
public String toString()
{
  check(); // Leider muss dieser modifizierende check() ausgeführt werden, da auf die aufrufende Klasse ExcelImport kein Einfluss
  // genommen werden kann.
  String txt = StringUtils.abbreviate(text, 30);
  DayHolder day = new DayHolder(datum);
  return StringUtils.leftPad(NumberHelper.getAsString(satzNr), 4)
      + " "
      + StringUtils.leftPad(day.isoFormat(), 10)
      + StringUtils.leftPad(NumberHelper.getAsString(betrag, NumberHelper.getCurrencyFormat(Locale.GERMAN)), 12)
      + " "
      + kost1 != null ? StringUtils.leftPad(kost1.toString(), 12) : "-           " + " " + kost2 != null ? StringUtils.leftPad(kost2
      .toString(), 12) : "-           " + " " + StringUtils.rightPad(txt, 30);
}
 
Example 13
Source File: TimesheetDO.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return The abbreviated description (maximum length is 50 characters).
 */
@Transient
public String getShortDescription()
{
  if (this.description == null) {
    return "";
  }
  return StringUtils.abbreviate(getDescription(), 50);
}
 
Example 14
Source File: KostFormatter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gibt vollständige Kundennummer aus ("5.xxx") und hängt den Kundennamen (max. 30 stellig) an, z. B. "5.120 - DHL Verwaltungs GmbH"
 * @param kunde
 */
public static String formatKunde(final KundeDO kunde)
{
  if (kunde == null) {
    return "";
  }
  return format(kunde) + " - " + StringUtils.abbreviate(kunde.getName(), 30);
}
 
Example 15
Source File: PaddedTable.java    From hiped2 with Apache License 2.0 4 votes vote down vote up
public String abbreviate(String s) {
  return StringUtils.abbreviate(s, maxColLength);
}
 
Example 16
Source File: IssueCommentPayload.java    From DotCi with MIT License 4 votes vote down vote up
public String getDescription() {
    return StringUtils.abbreviate(this.comment.getBody(), 40);
}
 
Example 17
Source File: HRPlanningEntryDO.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Transient
public String getShortDescription()
{
  return StringUtils.abbreviate(getDescription(), 50);
}
 
Example 18
Source File: InventoryService.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
public String computeTitle(Inventory entity) {
  return entity.getStockLocation().getName()
      + (!Strings.isNullOrEmpty(entity.getDescription())
          ? "-" + StringUtils.abbreviate(entity.getDescription(), 10)
          : "");
}
 
Example 19
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public String getElementText(PsiElement psiElement) {
    String symbolPresentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement);
    return StringUtils.abbreviate(symbolPresentableText, 50);
}
 
Example 20
Source File: Generic.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getDisplayString1() {
	return StringUtils.abbreviate(getString1(), 65);
}