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

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

Introduction

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

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:cc.kune.core.server.manager.impl.SiteManagerDefault.java

/**
 * Load properties./*from   www. ja va 2 s .  c om*/
 *
 * @param kuneProperties
 *          the kune properties
 */
private void loadProperties(final KuneProperties kuneProperties) {
    data = loadInitData();
    motdTranslated = new HashMap<I18nLanguage, MotdDTO>();

    siteThemes = getSiteThemes(this.kuneProperties.getList(KuneProperties.WS_THEMES));
    reservedWords = new ReservedWordsRegistryDTO(ReservedWordsRegistry.fromList(kuneProperties));

    if (kuneProperties.getBoolean(KuneProperties.MOTD_ENABLED)) {
        motd = new MotdDTO();
        motd.setTitle(kuneProperties.get(KuneProperties.MOTD_TITLE));
        motd.setMessage(StringUtils.abbreviate(kuneProperties.get(KuneProperties.MOTD_MESSAGE), 500));
        motd.setMessageBottom(
                StringUtils.abbreviate(kuneProperties.get(KuneProperties.MOTD_MESSAGE_BOTTOM), 500));
        motd.setOkBtnText(kuneProperties.get(KuneProperties.MOTD_OK_BTN_TEXT));
        motd.setOkBtnUrl(kuneProperties.get(KuneProperties.MOTD_OK_BTN_URL));
        motd.setCloseBtnText(kuneProperties.get(KuneProperties.MOTD_CLOSE_BTN_TEXT));
        motd.setCookieName(kuneProperties.get(KuneProperties.MOTD_COOKIE_NAME));
        motd.setShouldRemember(kuneProperties.getInteger(KuneProperties.MOTD_SHOULD_REMEMBER));
    } else {
        motd = null;
    }
}

From source file:com.google.ie.business.service.impl.IdeaServiceImpl.java

@SuppressWarnings("unchecked")
public void addIdeaToListInCache(Idea originalIdea, String keyOfTheList, int noOfIdeas, int expiryDelay) {
    LinkedList<Idea> listOfIdeas = (LinkedList<Idea>) CacheHelper.getObject(CacheConstants.IDEA_NAMESPACE,
            keyOfTheList);//from   w ww  .j  ava 2 s  .  c  om
    if (listOfIdeas != null) {
        if (listOfIdeas.size() >= noOfIdeas) {
            /* Remove the last element which is also the oldest */
            listOfIdeas.pollLast();
        }
    } else {
        listOfIdeas = new LinkedList<Idea>();
    }
    /* Create a new idea object to contain the required data only */
    Idea ideaWithTheRequiredDataOnly = new Idea();
    ideaWithTheRequiredDataOnly
            .setTitle(StringUtils.abbreviate(originalIdea.getTitle(), ServiceConstants.FIFTY));
    /* Limit the description to hundred characters */
    ideaWithTheRequiredDataOnly
            .setDescription(StringUtils.abbreviate(originalIdea.getDescription(), ServiceConstants.HUNDRED));
    ideaWithTheRequiredDataOnly.setKey(originalIdea.getKey());
    /* Add the idea to the head of the list */
    listOfIdeas.addFirst(ideaWithTheRequiredDataOnly);
    /* Put the updated list back to the cache */
    CacheHelper.putObject(CacheConstants.IDEA_NAMESPACE, keyOfTheList, listOfIdeas, expiryDelay);
}

From source file:com.sfs.ucm.controller.SpecificationAction.java

/**
 * Validate specification/*w w  w  . j  a v  a2s.c o  m*/
 * <ul>
 * <li>If new specification check for duplicate</li>
 * </ul>
 * 
 * @return flag true if validation is successful
 */
private boolean validate() {
    boolean isvalid = true;
    if (this.specification.getId() == null) {
        if (this.specifications.contains(this.specification)) {
            this.facesContextMessage.errorMessage("{0} already exists",
                    StringUtils.abbreviate(this.specification.getName(), 25));
            logger.error("{} already exists", this.specification.getName());
            isvalid = false;
            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.addCallbackParam("validationFailed", !isvalid);
        }
    }

    return isvalid;
}

From source file:de.tudarmstadt.lt.lm.app.PerplexityClient.java

@SuppressWarnings("unchecked")
void run(Reader r) {
    long l = 0;/*from  w w w  .j a  v a 2 s .  c  o m*/
    for (LineIterator liter = new LineIterator(r); liter.hasNext();) {
        if (++l % 5000 == 0)
            LOG.info("{}: processing line {}.", _rmi_string, l);

        String line = liter.next();
        if (line.trim().isEmpty())
            continue;

        List<String>[] ngrams;
        try {
            if (_one_ngram_per_line)
                ngrams = new List[] { Arrays.asList(line.split(" ")) };
            else
                ngrams = _lm_prvdr.getNgrams(line);
            if (ngrams == null || ngrams.length == 0)
                continue;
        } catch (Exception e) {
            LOG.error("{}: Could not get ngrams from line {}: '{}'.", _rmi_string, l,
                    StringUtils.abbreviate(line, 100), e);
            continue;
        }

        for (List<String> ngram : ngrams) {
            if (ngram.isEmpty())
                continue;
            _num_ngrams++;
            try {
                boolean oov = false;
                if (_lm_prvdr.ngramContainsOOV(ngram)) {
                    _oov_ngrams++;
                    if (_lm_prvdr.ngramEndsWithOOV(ngram)) {
                        _oov_terms++;
                        oov = true;
                    }
                }

                if (_lm_prvdr_oovref.ngramContainsOOV(ngram)) {
                    _oovreflm_oov_ngrams++;
                    if (_lm_prvdr_oovref.ngramEndsWithOOV(ngram)) {
                        _oovreflm_oov_terms++;
                        if (_no_oov_reflm || (_no_oov && oov))
                            continue;
                    }
                }

                double log10prob = _perplexity_all.addLog10Prob(ngram);
                _perplexity_file.addLog10Prob(ngram);
                if (log10prob < _min_prob) {
                    _min_prob = log10prob;
                    _min_ngram = ngram;
                }
                if (log10prob > _max_prob) {
                    _max_prob = log10prob;
                    _max_ngram = ngram;
                }
            } catch (Exception e) {
                LOG.error("{}: Could not add ngram '{}' to perplexity.", _rmi_string, ngram);
                continue;
            }
        }
    }
}

From source file:net.bpelunit.framework.ui.command.BPELUnitCommandLineRunner.java

private String createReadableOutputInternal(ITestArtefact artefact, boolean recursive, String inline) {
    StringBuffer output = new StringBuffer();
    output.append(inline + "<Artefact \"" + artefact.getName() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
    String internalInline = inline + "  "; //$NON-NLS-1$
    output.append(internalInline + "Status: " //$NON-NLS-1$
            + artefact.getStatus().toString() + "\n"); //$NON-NLS-1$
    if (recursive) {
        for (ITestArtefact child : artefact.getChildren()) {
            if (artefact instanceof XMLData) {
                XMLData sd = (XMLData) artefact;
                output.append(internalInline + sd.getName() + " : " //$NON-NLS-1$
                        + StringUtils.abbreviate(BPELUnitUtil.removeSpaceLineBreaks(sd.getXmlData()),
                                MAX_LINE_LENGTH)
                        + "\n"); //$NON-NLS-1$
            } else {
                output.append(createReadableOutputInternal(child, recursive, internalInline));
            }/*from w  w  w.j  a v  a2s. com*/
        }
    }
    output.append(inline + "</Artefact \"" + artefact.getName() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
    return output.toString();
}

From source file:com.fiveamsolutions.nci.commons.audit.DefaultProcessor.java

/**
 * Produces a string formatted as follows "(String.valueOf(k),String.valueOf(v)) ,
 * (String.valueOf(k),String.valueOf(v)), ...".
 * @param map/*from   ww w.j  a  v  a2  s. c o  m*/
 * @return a value string of the provided map
 */
@SuppressWarnings("PMD.ConsecutiveLiteralAppends")
private String getValueString(Map<?, ?> map) {
    if (map == null) {
        return null;
    }
    String sep = "";
    StringBuffer sb = new StringBuffer();
    for (Object k : map.keySet()) {
        if (sb.length() > AuditLogDetail.VALUE_LENGTH) {
            break;
        }
        Object v = map.get(k);
        if (isPersistent(k)) {
            k = getId(k);
        }
        if (v == null) {
            v = "";
        } else if (isPersistent(v)) {
            v = getId(v);
        }
        sb.append(sep);
        sb.append('(');
        escape(sb, ObjectUtils.toString(k, null));
        sb.append(',');
        escape(sb, ObjectUtils.toString(v, null));
        sb.append(')');
        sep = ",";
    }
    return StringUtils.abbreviate(sb.toString(), AuditLogDetail.VALUE_LENGTH);
}

From source file:de.fme.topx.component.TopXSearchComponent.java

/**
 * reads the document name and title and generates an abbreviated version of
 * both./*  w ww  .j av  a2  s .  co  m*/
 * 
 * @param nodeRef
 * @param newNode
 */
private void setNameAndTitle(NodeRef nodeRef, Node newNode) {
    newNode.setName((String) getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME));
    newNode.setAbbreviatedName(
            StringUtils.abbreviate((String) getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME), 28));

    newNode.setTitle((String) getNodeService().getProperty(nodeRef, ContentModel.PROP_TITLE));

    newNode.setAbbreviatedTitle(StringUtils
            .abbreviate((String) getNodeService().getProperty(nodeRef, ContentModel.PROP_TITLE), 28));
}

From source file:com.sfs.captor.controller.UseCaseFlowAction.java

/**
 * Validate Alternative Flow/*from   w  ww  .  j av a  2s . com*/
 * <ul>
 * <li>Check for duplicate alternative flow</li>
 * </ul>
 * 
 * @return flag true if validation is successful
 */
private boolean validateAlternativeFlow() {
    boolean isvalid = true;

    if (this.alternativeFlow.getId() == null) {
        if (checkForDuplicateAlternateFlow(this.useCase, this.alternativeFlow.getName())) {
            this.facesContextMessage.errorMessage("{0} already exists",
                    StringUtils.abbreviate(this.alternativeFlow.getName(), 25));
            logger.error("{} already exists", this.alternativeFlow.getName());
            isvalid = false;
            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.addCallbackParam("validationFailed", !isvalid);
        }
    }

    // verify alternative flow end step is a valid basic step number
    if (this.alternativeFlow.getEndStep() != null && this.alternativeFlow.getEndStep() != 0) {
        if (this.alternativeFlow.getEndStep().shortValue() < this.alternativeFlow.getStartStep().shortValue()) {
            this.facesContextMessage.errorMessage("EndStep must be greater than or equal to BeginStep");
            logger.error("EndStep must be greater than or equal to BeginStep");
            isvalid = false;
            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.addCallbackParam("validationFailed", !isvalid);
        }
    }

    return isvalid;
}

From source file:com.sfs.captor.controller.AlternativeFlowAction.java

/**
 * Validate business rule//from   ww w . j  ava 2s.c om
 * <ul>
 * <li>Check for duplicate business rule</li>
 * </ul>
 * 
 * @return flag true if validation is successful
 */
private boolean validateBusinessRule() {
    boolean isvalid = true;

    if (this.flowStepRule.getId() == null) {
        if (checkForDuplicateBusinessRule(this.flowStepRule.getName())) {
            this.facesContextMessage.errorMessage("{0} already exists",
                    StringUtils.abbreviate(this.flowStepRule.getName(), 25));
            logger.error("{} already exists", this.flowStepRule.getName());
            isvalid = false;
            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.addCallbackParam("validationFailed", !isvalid);
        }
    }
    return isvalid;
}

From source file:io.hops.ha.common.TransactionStateImpl.java

public void addAppAttempt(RMAppAttempt appAttempt) {
    String appIdStr = appAttempt.getAppAttemptId().getApplicationId().toString();

    Credentials credentials = appAttempt.getCredentials();
    ByteBuffer appAttemptTokens = null;

    if (credentials != null) {
        DataOutputBuffer dob = new DataOutputBuffer();
        try {/*from  ww  w.  j a v  a 2 s . c  o  m*/
            credentials.writeTokenStorageToStream(dob);
        } catch (IOException ex) {
            LOG.error("faillerd to persist tocken: " + ex, ex);
        }
        appAttemptTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
    }

    ApplicationAttemptStateDataPBImpl attemptStateData = (ApplicationAttemptStateDataPBImpl) ApplicationAttemptStateDataPBImpl
            .newApplicationAttemptStateData(appAttempt.getAppAttemptId(), appAttempt.getMasterContainer(),
                    appAttemptTokens, appAttempt.getStartTime(), appAttempt.getState(),
                    appAttempt.getOriginalTrackingUrl(),
                    StringUtils.abbreviate(appAttempt.getDiagnostics(), 1000),
                    appAttempt.getFinalApplicationStatus(), new HashSet<NodeId>(),
                    new ArrayList<ContainerStatus>(), appAttempt.getProgress(), appAttempt.getHost(),
                    appAttempt.getRpcPort());

    byte[] attemptStateByteArray = attemptStateData.getProto().toByteArray();
    if (attemptStateByteArray.length > 13000) {
        LOG.error("application Attempt State too big: " + appAttempt.getAppAttemptId() + " "
                + appAttemptTokens.array().length + " " + appAttempt.getDiagnostics().getBytes().length + " "
                + " ");
    }
    this.appAttempts.put(appAttempt.getAppAttemptId().toString(),
            new ApplicationAttemptState(appIdStr, appAttempt.getAppAttemptId().toString(),
                    attemptStateByteArray, appAttempt.getHost(), appAttempt.getRpcPort(), appAttemptTokens,
                    appAttempt.getTrackingUrl()));
    appIds.add(appAttempt.getAppAttemptId().getApplicationId());
}