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:com.iw.plugins.spindle.editors.util.XMLNodeLabelProvider.java

public String getText(Object obj) {
    if (obj instanceof XMLNode) {
        XMLNode artifact = (XMLNode) obj;
        String type = artifact.getType();

        if (type == ITypeConstants.TAG || type == ITypeConstants.EMPTYTAG || type == ITypeConstants.DECL) {
            String name = artifact.getName();
            return name == null ? "" : name;
        }/* w  ww .ja v  a  2s.  c  om*/

        if (type == ITypeConstants.ATTR) {
            String name = artifact.getName();
            String attrvalue = artifact.getAttributeValue();
            return (name == null ? "" : name) + " = "
                    + StringUtils.abbreviate(attrvalue == null ? "" : attrvalue, 50);
        }

        if (type == ITypeConstants.COMMENT)
            return "COMMENT" + StringUtils.abbreviate(artifact.getContent().trim(), 50);

        if (type == ITypeConstants.TEXT)
            return StringUtils.abbreviate(artifact.getContent().trim(), 50);

        if (type == ITypeConstants.PI)
            return StringUtils.abbreviate(artifact.getContent().trim(), 50);
    }

    return obj.toString();
}

From source file:mobi.chouette.model.Company.java

/**
 * set name <br/>//from   www . j  a  va 2 s .c om
 * truncated to 255 characters if too long
 * 
 * @param value
 *            New value
 */
public void setName(String value) {
    name = StringUtils.abbreviate(value, 255);
}

From source file:at.tfr.securefs.MessageHandlerBean.java

@OnMessage
public void handleMessage(String json, Session wsSession) throws JsonParseException, JsonMappingException,
        IOException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException,
        NoSuchPaddingException, InvalidAlgorithmParameterException, InterruptedException, ExecutionException {

    try {/* www  .j  a v  a  2s. co  m*/
        handleMessage(json, new WebSocketSender(wsSession));
    } catch (Exception e) {
        log.warn("cannot handle message=" + StringUtils.abbreviate(json, 100) + " : " + e, e);
    }
}

From source file:com.siemens.sw360.search.db.SearchDocument.java

/**
 * Get document name/*from w  ww.  j av a  2 s.  c o m*/
 */
String getName() {
    if (!SW360Constants.MAP_FULLTEXT_SEARCH_NAME.containsKey(type)) {
        return "";
    } else {
        String name = getProperty(SW360Constants.MAP_FULLTEXT_SEARCH_NAME.get(type));
        return StringUtils.abbreviate(name, NAME_MAX_LENGTH);
    }
}

From source file:de.tudarmstadt.lt.ltbot.text.JSoupTextExtractor.java

@Override
public String getPlaintext(final String htmltext) {
    try {/*w w  w . j  a v  a2 s .com*/
        // preserve newlines
        // html = html.replaceAll("(?i)<br[^>]*>", "br2nl"); // <br>s are often just inserted for style
        String hhtmltext = _end_prgrph_ptrn.matcher(htmltext).replaceAll("</p>br2nl");
        hhtmltext = _nwln_ptrn.matcher(hhtmltext).replaceAll("br2nl");

        Document soup = Jsoup.parse(hhtmltext);
        String plaintext = soup.text();

        plaintext = _tmp_nwln_ptrn.matcher(plaintext).replaceAll("\n");
        plaintext = _emptln_ptrn.matcher(plaintext.trim()).replaceAll("");

        return plaintext;
    } catch (Throwable t) {
        for (int i = 1; t != null && i < 10; i++) {
            LOG.log(Level.SEVERE,
                    String.format("Failed to get plaintext from while '%s' (%d %s:%s).",
                            StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()),
                    t);
            t = t.getCause();
        }
        return "Failed to get plaintext content \n" + htmltext;
    }
}

From source file:hydrograph.ui.graph.handler.GraphPropertiesHandler.java

private String getCurrentGraphName() {
    String graphName = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            .getEditorInput().getName();
    graphName = StringUtils.remove(graphName, Constants.JOB_EXTENSION);
    graphName = StringUtils.abbreviate(graphName, 20);
    return graphName;
}

From source file:com.gu.management.database.logging.SqlQueryData.java

private String extractComment() {
    String trimmedRawQuery = rawSqlQuery.trim();
    if (trimmedRawQuery.startsWith("/*")) {
        final String comment = extractCommentFromCommentedQuery(trimmedRawQuery);
        if (!"dynamic native SQL query".equals(comment) && !"criteria query".equals(comment)) {
            return comment;
        }//from  w w w  .  j  a v  a  2 s  .  co  m
    }

    //noinspection ThrowableInstanceNeverThrown
    LOGGER.trace("No comment on query: " + rawSqlQuery, new DummyExceptionGetAStackTraceDumpedToLog());

    return StringUtils.abbreviate(rawSqlQuery, QUERY_PREVIEW_LENGTH);
}

From source file:dk.i2m.jsf.converters.AbbreviationDisplayConverter.java

public String getAsString(FacesContext ctx, UIComponent comp, Object value) {
    if (value instanceof String) {
        String originalValue = (String) value;
        Map<String, Object> attrs = comp.getAttributes();
        if (attrs.containsKey(MAX_LENGTH)) {
            Object objMaxLength = attrs.get(MAX_LENGTH);
            if (objMaxLength instanceof String) {
                String maxLength = (String) objMaxLength;

                try {
                    return StringUtils.abbreviate(originalValue, Integer.valueOf(maxLength));
                } catch (NumberFormatException ex) {
                    logger.warning("Attribute '" + MAX_LENGTH + "' must contain a String with a numeric value");
                    return originalValue;
                }/*from w ww  . jav a2  s  . c o  m*/
            } else {
                logger.warning("Attribute '" + MAX_LENGTH + "' must contain a String with a numeric value");
                return originalValue;
            }
        } else {
            logger.warning("Attribute '" + MAX_LENGTH + "' is missing");
            return originalValue;
        }
    } else {
        logger.warning(
                "Value provided to " + getClass().getName() + " was not a String but a " + value.getClass());
        return "";
    }
}

From source file:gov.guilin.plugin.yeepay.YeepayPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);// www . j  av  a2s .co m
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("p0_Cmd", "Buy");
    parameterMap.put("p1_MerId", pluginConfig.getAttribute("partner"));
    parameterMap.put("p2_Order", sn);
    parameterMap.put("p3_Amt", payment.getAmount().setScale(2).toString());
    parameterMap.put("p4_Cur", "CNY");
    parameterMap.put("p5_Pid",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 20));
    parameterMap.put("p7_Pdesc",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 20));
    parameterMap.put("p8_Url", getNotifyUrl(sn, NotifyMethod.general));
    parameterMap.put("p9_SAF", "0");
    parameterMap.put("pa_MP", "guilin");
    parameterMap.put("pr_NeedResponse", "1");
    parameterMap.put("hmac", generateSign(parameterMap));
    return parameterMap;
}

From source file:net.osxx.plugin.yeepay.YeepayPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);//  www .ja  v  a2 s  .c  o m
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("p0_Cmd", "Buy");
    parameterMap.put("p1_MerId", pluginConfig.getAttribute("partner"));
    parameterMap.put("p2_Order", sn);
    parameterMap.put("p3_Amt", payment.getAmount().setScale(2).toString());
    parameterMap.put("p4_Cur", "CNY");
    parameterMap.put("p5_Pid",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 20));
    parameterMap.put("p7_Pdesc",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 20));
    parameterMap.put("p8_Url", getNotifyUrl(sn, NotifyMethod.general));
    parameterMap.put("p9_SAF", "0");
    parameterMap.put("pa_MP", "osxx");
    parameterMap.put("pr_NeedResponse", "1");
    parameterMap.put("hmac", generateSign(parameterMap));
    return parameterMap;
}