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:org.kuali.rice.kcb.bo.Message.java

/**
 * @see java.lang.Object#toString()//  w  ww .  j a  v  a2  s . c o  m
 */
@Override
public String toString() {
    return new ToStringBuilder(this).append("id", id).append("creationDateTime", creationDateTime)
            .append("deliveryType", deliveryType).append("recipient", recipient).append("title", title)
            .append("channel", channel).append("producer", producer)
            .append("content", StringUtils.abbreviate(content, 100)).append("contentType", contentType)
            .append("lockVerNbr", lockVerNbr).toString();
}

From source file:org.kuali.rice.kew.actionrequest.dao.impl.ActionRequestDAOJpaImpl.java

public void saveActionRequest(ActionRequestValue actionRequest) {
    if (actionRequest.getAnnotation() != null && actionRequest.getAnnotation().length() > 2000) {
        actionRequest.setAnnotation(StringUtils.abbreviate(actionRequest.getAnnotation(), 2000));
    }//from   www.  j a  v a2  s.com
    if (actionRequest.getActionRequestId() == null) {
        loadDefaultValues(actionRequest);
        entityManager.persist(actionRequest);
    } else {
        OrmUtils.merge(entityManager, actionRequest);
    }
}

From source file:org.kuali.rice.kew.actionrequest.dao.impl.ActionRequestDAOOjbImpl.java

public void saveActionRequest(ActionRequestValue actionRequest) {
    if (actionRequest.getActionRequestId() == null) {
        loadDefaultValues(actionRequest);
    }//  w w w.j a  va  2  s. c o  m
    if (actionRequest.getAnnotation() != null && actionRequest.getAnnotation().length() > 2000) {
        actionRequest.setAnnotation(StringUtils.abbreviate(actionRequest.getAnnotation(), 2000));
    }
    this.getPersistenceBrokerTemplate().store(actionRequest);
}

From source file:org.kuali.rice.kew.actionrequest.service.impl.ActionRequestServiceImpl.java

protected ActionRequestValue saveActionRequest(ActionRequestValue actionRequest, boolean simulation) {
    if (actionRequest.isGroupRequest()) {
        Group group = actionRequest.getGroup();
        if (group == null) {
            throw new RiceRuntimeException("Attempted to save an action request with a non-existent group.");
        }//from w w  w .j  a  v  a 2s.c  om
        if (!group.isActive()
                && actionRequest.getRouteHeader().getDocumentType().getFailOnInactiveGroup().getPolicyValue()) {
            throw new RiceRuntimeException("Attempted to save an action request with an inactive group.");
        }
    }
    if (actionRequest.getActionRequestId() == null) {
        loadDefaultValues(actionRequest);
    }
    if (actionRequest.getAnnotation() != null && actionRequest.getAnnotation().length() > 2000) {
        actionRequest.setAnnotation(StringUtils.abbreviate(actionRequest.getAnnotation(), 2000));
    }
    if (simulation) {
        return actionRequest;
    } else {
        return getDataObjectService().save(actionRequest);
    }
}

From source file:org.kuali.rice.kew.lookup.valuefinder.SavedSearchValuesFinder.java

/**
 * @see org.kuali.rice.krad.keyvalues.KeyValuesFinder#getKeyValues()
 *//* w  w  w  .ja  va  2  s. c  o m*/
@Override
public List<KeyValue> getKeyValues() {
    List<KeyValue> savedSearchValues = new ArrayList<KeyValue>();
    savedSearchValues.add(new ConcreteKeyValue("", "Searches"));
    savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-----"));
    savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-Named Searches"));
    List<KeyValue> namedSearches = KEWServiceLocator.getDocumentSearchService()
            .getNamedSearches(GlobalVariables.getUserSession().getPrincipalId());
    for (KeyValue keyValue : namedSearches) {
        String label = StringUtils.abbreviate(keyValue.getValue(), 75);
        KeyValue keyLabel = new ConcreteKeyValue(keyValue.getKey(), label);
        savedSearchValues.add(keyLabel);
    }
    savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-----"));
    savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-Recent Searches"));
    List<KeyValue> mostRecentSearches = KEWServiceLocator.getDocumentSearchService()
            .getMostRecentSearches(GlobalVariables.getUserSession().getPrincipalId());
    for (KeyValue keyValue : mostRecentSearches) {
        String label = StringUtils.abbreviate(keyValue.getValue(), 75);
        KeyValue keyLabel = new ConcreteKeyValue(keyValue.getKey(), label);
        savedSearchValues.add(keyLabel);
    }
    return savedSearchValues;
}

From source file:org.languagetool.dev.wikipedia.DatabaseDumpHandler.java

@Override
protected void handleResult(String title, List<RuleMatch> ruleMatches, String text, Language language)
        throws SQLException {
    final String sql = "INSERT INTO corpus_match "
            + "(version, language_code, ruleid, rule_subid, rule_description, message, error_context, corpus_date, "
            + "check_date, sourceuri, is_visible) " + "VALUES (0, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)";
    try (PreparedStatement prepSt = conn.prepareStatement(sql)) {
        final java.sql.Date dumpSqlDate = new java.sql.Date(dumpDate.getTime());
        final java.sql.Date nowDate = new java.sql.Date(new Date().getTime());
        for (RuleMatch match : ruleMatches) {
            prepSt.setString(1, language.getShortName());
            final Rule rule = match.getRule();
            prepSt.setString(2, rule.getId());
            if (rule instanceof PatternRule) {
                final PatternRule patternRule = (PatternRule) rule;
                prepSt.setString(3, patternRule.getSubId());
            } else {
                prepSt.setNull(3, Types.VARCHAR);
            }/* w  w  w  . j  a  v a 2  s  . co  m*/
            prepSt.setString(4, rule.getDescription());
            prepSt.setString(5, StringUtils.abbreviate(match.getMessage(), 255));
            final String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
            if (context.length() > 255) {
                // let's skip these strange cases, as shortening the text might leave us behind with invalid markup etc
                continue;
            }
            prepSt.setString(6, context);
            prepSt.setDate(7, dumpSqlDate);
            prepSt.setDate(8, nowDate);
            prepSt.setString(9, URL_PREFIX.replaceAll(LANG_MARKER, langCode) + title);
            prepSt.executeUpdate();
            errorCount++;
            if (maxErrors > 0 && errorCount >= maxErrors) {
                throw new ErrorLimitReachedException(maxErrors);
            }
        }
    }
}

From source file:org.languagetool.gui.ResultArea.java

private String getRuleMatchHtml(List<RuleMatch> ruleMatches, String text, String startCheckText) {
    final ContextTools contextTools = new ContextTools();
    final StringBuilder sb = new StringBuilder(200);
    sb.append(startCheckText);/*from  ww  w  .  j ava  2  s  .c  o  m*/
    sb.append("<br>\n");
    int i = 0;
    for (final RuleMatch match : ruleMatches) {
        final String output = Tools.makeTexti18n(messages, "result1", i + 1, match.getLine() + 1,
                match.getColumn());
        sb.append(output);
        final String msg = match.getMessage().replaceAll("<suggestion>", "<b>")
                .replaceAll("</suggestion>", "</b>").replaceAll("<old>", "<b>").replaceAll("</old>", "</b>");
        sb.append("<b>").append(messages.getString("errorMessage")).append("</b> ");
        sb.append(msg);
        final RuleLink ruleLink = RuleLink.buildDeactivationLink(match.getRule());
        sb.append(" <a href=\"").append(ruleLink).append("\">").append(messages.getString("deactivateRule"))
                .append("</a><br>\n");
        if (match.getSuggestedReplacements().size() > 0) {
            final String replacement = StringTools.listToString(match.getSuggestedReplacements(), "; ");
            sb.append("<b>").append(messages.getString("correctionMessage")).append("</b> ").append(replacement)
                    .append("<br>\n");
        }
        if (ITSIssueType.Misspelling.equals(match.getRule().getLocQualityIssueType())) {
            contextTools.setErrorMarkerStart(SPELL_ERROR_MARKER_START);
        } else {
            contextTools.setErrorMarkerStart(LT_ERROR_MARKER_START);
        }
        final String context = contextTools.getContext(match.getFromPos(), match.getToPos(), text);
        sb.append("<b>").append(messages.getString("errorContext")).append("</b> ").append(context);
        sb.append("<br>\n");
        if (match.getRule().getUrl() != null && Desktop.isDesktopSupported()) {
            sb.append("<b>").append(messages.getString("moreInfo")).append("</b> <a href=\"");
            final String url = match.getRule().getUrl().toString();
            sb.append(url);
            final String shortUrl = StringUtils.abbreviate(url, 60);
            sb.append("\">").append(shortUrl).append("</a><br>\n");
        }
        i++;
    }
    sb.append(Main.HTML_GREY_FONT_START);
    sb.append(getDisabledRulesHtml());
    final String checkDone = Tools.makeTexti18n(messages, "checkDone", ruleMatches.size(), runTime);
    sb.append("<br>\n").append(checkDone);
    sb.append("<br>\n").append(messages.getString("makeLanguageToolBetter"));
    sb.append(Main.HTML_FONT_END).append("<br>\n");
    return sb.toString();
}

From source file:org.LexGrid.LexBIG.example.BuildTreeForCode.java

/**
 * Prints the given tree item, recursing through all branches.
 * /*ww w  . java  2  s.c  o m*/
 * @param ti
 */
protected void printTree(TreeItem ti, String focusCode, int depth) {
    StringBuffer indent = new StringBuffer();
    for (int i = 0; i < depth * 2; i++)
        indent.append("| ");

    StringBuffer codeAndText = new StringBuffer(indent).append(focusCode.equals(ti.code) ? ">>>>" : "")
            .append(ti.code).append(':').append(StringUtils.abbreviate(ti.text, 60))
            .append(ti.expandable ? " [+]" : "");
    Util.displayMessage(codeAndText.toString());

    indent.append("| ");
    for (String association : ti.assocToChildMap.keySet()) {
        Util.displayMessage(indent.toString() + association);
        List<TreeItem> children = ti.assocToChildMap.get(association);
        Collections.sort(children);
        for (TreeItem childItem : children)
            printTree(childItem, focusCode, depth + 1);
    }
}

From source file:org.LexGrid.LexBIG.example.BuildTreeForMetaCodeBySource.java

/**
 * Prints formatted text providing context for
 * the given item including CUI, SAB, AUI, and Text.
 * @throws LBException/*from   ww  w.  j  a  v  a  2s  .  c  o m*/
 */
protected void printHeader(ResolvedConceptReference rcr, String sab) throws LBException {

    Util.displayMessage("CUI ....... : " + rcr.getConceptCode());
    Util.displayMessage("Description : " + StringUtils.abbreviate(rcr.getEntityDescription().getContent(), 60));
    Util.displayMessage("SAB ....... : " + sab);
    Util.displayMessage("");
    Util.displayMessage("AUIs with this CUI associated for this SAB :");
    for (String line : getAtomText(rcr, sab).split("\\|"))
        Util.displayMessage("  {" + line + '}');
}

From source file:org.LexGrid.LexBIG.example.BuildTreeForMetaCodeBySource.java

/**
 * Prints the given tree item, recursing through all branches.
 * /* w w  w . j  av  a  2s  . c  o  m*/
 * @param ti
 */
protected void printTree(TreeItem ti, String focusCode, int depth) {
    StringBuffer indent = new StringBuffer();
    for (int i = 0; i < depth * 2; i++)
        indent.append("| ");

    StringBuffer codeAndText = new StringBuffer(indent).append(focusCode.equals(ti.code) ? ">" : " ")
            .append(ti.code).append(':').append(StringUtils.abbreviate(ti.text, 60))
            .append(ti.expandable ? " [+]" : "");
    if (ti.auis != null)
        for (String line : ti.auis.split("\\|"))
            codeAndText.append('\n').append(indent).append("    {").append(StringUtils.abbreviate(line, 60))
                    .append('}');
    Util.displayMessage(codeAndText.toString());

    indent.append("| ");
    for (String association : ti.assocToChildMap.keySet()) {
        Util.displayMessage(indent.toString() + association);
        List<TreeItem> children = ti.assocToChildMap.get(association);
        Collections.sort(children);
        for (TreeItem childItem : children)
            printTree(childItem, focusCode, depth + 1);
    }
}