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

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

Introduction

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

Prototype

public static String abbreviate(final String str, final int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:io.bitsquare.gui.components.paymentmethods.CashDepositForm.java

@Override
protected void autoFillNameTextField() {
    if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
        String bankId = null;// www  .  ja  v  a  2  s .  c  o  m
        String countryCode = cashDepositAccountContractData.getCountryCode();
        if (countryCode == null)
            countryCode = "";
        if (BankUtil.isBankIdRequired(countryCode)) {
            bankId = bankIdInputTextField.getText();
            if (bankId.length() > 9)
                bankId = StringUtils.abbreviate(bankId, 9);
        } else if (BankUtil.isBranchIdRequired(countryCode)) {
            bankId = branchIdInputTextField.getText();
            if (bankId.length() > 9)
                bankId = StringUtils.abbreviate(bankId, 9);
        } else if (BankUtil.isBankNameRequired(countryCode)) {
            bankId = bankNameInputTextField.getText();
            if (bankId.length() > 9)
                bankId = StringUtils.abbreviate(bankId, 9);
        }

        String accountNr = accountNrInputTextField.getText();
        if (accountNr.length() > 9)
            accountNr = StringUtils.abbreviate(accountNr, 9);

        String method = BSResources.get(paymentAccount.getPaymentMethod().getId());
        if (bankId != null && !bankId.isEmpty())
            accountNameTextField.setText(method.concat(": ").concat(bankId).concat(", ").concat(accountNr));
        else
            accountNameTextField.setText(method.concat(": ").concat(accountNr));
    }
}

From source file:com.moviejukebox.plugin.TheMovieDbPlugin.java

/**
 * Search for information on the person/*from   w w  w .  j  a  v  a  2s  . c  om*/
 *
 * @param person
 * @return
 */
@Override
public boolean scan(Person person) {
    String id = getPersonId(person);

    if (StringTools.isValidString(id)) {
        int tmdbId = Integer.parseInt(id);
        try {
            PersonInfo tmdbPerson = tmdb.getPersonInfo(tmdbId);

            LOG.info(tmdbPerson.toString());
            if (skipFaceless && StringUtils.isBlank(tmdbPerson.getProfilePath())) {
                LOG.debug("Skipped '{}' no profile picture found (skip.faceless=true)", tmdbPerson.getName());
                return Boolean.FALSE;
            }

            person.setName(tmdbPerson.getName());

            person.setBiography(StringUtils.abbreviate(tmdbPerson.getBiography(), preferredBiographyLength));
            person.setId(IMDB_PLUGIN_ID, tmdbPerson.getImdbId());
            person.setUrl("http://www.themoviedb.org/person/" + tmdbId);

            List<String> akas = tmdbPerson.getAlsoKnownAs();
            if (akas != null && !akas.isEmpty()) {
                // Set the birthname to be the first aka
                person.setBirthName(akas.get(0));

                // Add the akas
                for (String aka : tmdbPerson.getAlsoKnownAs()) {
                    person.addAka(aka);
                }
            }

            if (StringTools.isValidString(tmdbPerson.getBirthday())) {
                // Look for the death day and append that as well
                if (StringTools.isValidString(tmdbPerson.getDeathday())) {
                    person.setYear(tmdbPerson.getBirthday() + "/" + tmdbPerson.getDeathday());
                } else {
                    person.setYear(tmdbPerson.getBirthday());
                }
            }

            person.setBirthPlace(tmdbPerson.getPlaceOfBirth());

            URL url = tmdb.createImageUrl(tmdbPerson.getProfilePath(), ORIGINAL);
            person.setPhotoURL(url.toString());
            person.setPhotoFilename();

            // Filmography
            PersonCreditList<CreditMovieBasic> results = tmdb.getPersonMovieCredits(tmdbId, languageCode);
            person.setKnownMovies(results.getCast().size() + results.getCrew().size());

            int actorCount = 0;
            int directorCount = 0;
            int writerCount = 0;

            // Process the credits into a filmography list
            List<Filmography> filmList = new ArrayList<>();

            // Process the cast
            if (jobsInclude.contains("Actor")) {
                for (CreditMovieBasic credit : results.getCast()) {
                    if (++actorCount > actorMax) {
                        // Over the limit, so stop
                        break;
                    }
                    LOG.debug("Credit job: {} = '{}' - {} ({})", credit.getCreditType(), credit.getJob(),
                            credit.getTitle(), credit.getReleaseDate());
                    filmList.add(convertMovieCredit(credit));
                }
            }

            // Process the crew
            for (CreditMovieBasic credit : results.getCrew()) {
                if (jobsInclude.contains("Director") && (++directorCount > directorMax)) {
                    // Skip this record as no more are needed
                    LOG.debug("Skipping DIRECTOR '{}' (max reached)", person.getName());
                    continue;
                } else if (jobsInclude.contains("Writer") && (++writerCount > writerMax)) {
                    // Skip this record as no more are needed
                    LOG.debug("Skipping WRITER '{}' (max reached)", person.getName());
                    continue;
                }

                LOG.debug("Credit job: {} = '{}' - {} ({})", credit.getCreditType(), credit.getJob(),
                        credit.getTitle(), credit.getReleaseDate());
                filmList.add(convertMovieCredit(credit));
            }

            LOG.debug("Actors found   : {}, max: {}", actorCount, actorMax);
            LOG.debug("Directors found: {}, max: {}", directorCount, directorMax);
            LOG.debug("Writers found  : {}, max: {}", writerCount, writerMax);

            // See if we need to trim the list
            if (filmList.size() > preferredFilmographyMax) {
                LOG.debug("Reached limit of {} films for {}. Total found: {}", preferredFilmographyMax,
                        person.getName(), filmList.size());
                // Sort the collection to ensure the most relevant films are at the start
                Collections.sort(filmList, filmographyCmp);
                person.setFilmography(filmList.subList(0, preferredFilmographyMax));
            } else {
                person.setFilmography(filmList);
            }

            // Update the version
            int version = person.getVersion();
            person.setVersion(++version);

            return Boolean.TRUE;
        } catch (MovieDbException ex) {
            LOG.warn("Failed to get information on {} ({}), error: {}", person.getName(), tmdbId,
                    ex.getMessage(), ex);
            return Boolean.FALSE;
        }
    }
    return Boolean.FALSE;
}

From source file:io.bitsquare.gui.main.overlays.Overlay.java

protected void setTruncatedMessage() {
    if (message != null && message.length() > 1800)
        truncatedMessage = StringUtils.abbreviate(message, 1800);
    else/*from ww w . j  av  a 2  s.  c  om*/
        truncatedMessage = message;
}

From source file:fm.audiobox.core.AudioBoxClient.java

/**
 * Create credential with refresh token.
 *
 * @return the credential//  ww  w.  ja  va 2 s .com
 *
 * @throws java.io.IOException if any problem occurs with the configured data store.
 */
private HttpRequestInitializer createCredentialWithRefreshToken() throws IOException {
    StoredCredential c = getStoredCredential();
    logger.trace("Signing request method with access_token: " + StringUtils.abbreviate(c.getAccessToken(), 8));

    return createCredentialWithRefreshToken(c);
}

From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java

/**
 * Shortens and escapes (for markdown) some special characters. Otherwise the shortened text
 * could contain some unfinished sequences.
 * @param rule/*w w  w  . j  a va 2  s. c om*/
 * @return
 */
private static String getShortRuleDescription(Rule rule) {
    return StringEscapeUtils
            .escapeHtml4(
                    StringUtils.abbreviate(
                            StringUtils.stripToEmpty(rule.getDescription().replaceAll("\n|\r", "")
                                    .replaceAll("\\|", "\\\\|").replaceAll("`", "'").replaceAll("\\*", "")),
                            100));
}

From source file:org.activiti.engine.impl.persistence.entity.AbstractJobEntity.java

public void setExceptionMessage(String exceptionMessage) {
    this.exceptionMessage = StringUtils.abbreviate(exceptionMessage, MAX_EXCEPTION_MESSAGE_LENGTH);
}

From source file:org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("HistoricDetailVariableInstanceUpdateEntity[");
    sb.append("id=").append(id);
    sb.append(", name=").append(name);
    sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null");
    if (longValue != null) {
        sb.append(", longValue=").append(longValue);
    }//from  w w w.  java 2  s. c  om
    if (doubleValue != null) {
        sb.append(", doubleValue=").append(doubleValue);
    }
    if (textValue != null) {
        sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40));
    }
    if (textValue2 != null) {
        sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40));
    }
    if (byteArrayRef.getId() != null) {
        sb.append(", byteArrayValueId=").append(byteArrayRef.getId());
    }
    sb.append("]");
    return sb.toString();
}

From source file:org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntityImpl.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("HistoricDetailVariableInstanceUpdateEntity[");
    sb.append("id=").append(id);
    sb.append(", name=").append(name);
    sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null");
    if (longValue != null) {
        sb.append(", longValue=").append(longValue);
    }//from   w ww  .  j a  v a 2  s .com
    if (doubleValue != null) {
        sb.append(", doubleValue=").append(doubleValue);
    }
    if (textValue != null) {
        sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40));
    }
    if (textValue2 != null) {
        sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40));
    }
    if (byteArrayRef != null && byteArrayRef.getId() != null) {
        sb.append(", byteArrayValueId=").append(byteArrayRef.getId());
    }
    sb.append("]");
    return sb.toString();
}

From source file:org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("HistoricVariableInstanceEntity[");
    sb.append("id=").append(id);
    sb.append(", name=").append(name);
    sb.append(", revision=").append(revision);
    sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null");
    if (longValue != null) {
        sb.append(", longValue=").append(longValue);
    }/*w w  w .  j a  v  a  2  s .  c  om*/
    if (doubleValue != null) {
        sb.append(", doubleValue=").append(doubleValue);
    }
    if (textValue != null) {
        sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40));
    }
    if (textValue2 != null) {
        sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40));
    }
    if (byteArrayRef.getId() != null) {
        sb.append(", byteArrayValueId=").append(byteArrayRef.getId());
    }
    sb.append("]");
    return sb.toString();
}

From source file:org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntityImpl.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("HistoricVariableInstanceEntity[");
    sb.append("id=").append(id);
    sb.append(", name=").append(name);
    sb.append(", revision=").append(revision);
    sb.append(", type=").append(variableType != null ? variableType.getTypeName() : "null");
    if (longValue != null) {
        sb.append(", longValue=").append(longValue);
    }/*from w  ww .ja v  a  2 s .com*/
    if (doubleValue != null) {
        sb.append(", doubleValue=").append(doubleValue);
    }
    if (textValue != null) {
        sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40));
    }
    if (textValue2 != null) {
        sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40));
    }
    if (byteArrayRef != null && byteArrayRef.getId() != null) {
        sb.append(", byteArrayValueId=").append(byteArrayRef.getId());
    }
    sb.append("]");
    return sb.toString();
}