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:com.twinsoft.convertigo.beans.steps.LogStep.java

@Override
public String toString() {
    return "(" + logger + ") : log." + level + "(" + StringUtils.abbreviate(expression, 25) + ")";
}

From source file:com.ethlo.geodata.importer.GeonamesBoundaryImporter.java

@Override
public long processFile(Consumer<Map<String, String>> sink) throws IOException {
    long count = 0;
    try (final BufferedReader reader = IoUtils.getBufferedReader(boundaryFile)) {
        String line = reader.readLine(); // skip first line

        while ((line = reader.readLine()) != null) {
            if (StringUtils.isNotBlank(line)) {
                final String[] fields = line.split("\t");
                if (fields.length == 2) {
                    try {
                        final Map<String, String> entry = parsePoints(fields);
                        sink.accept(entry);
                    } catch (ParseException exc) {
                        logger.warn("Cannot parse geometry for location {}: {}", fields[0], exc.getMessage());
                    }/*from   w w  w . j a v  a 2 s .  c o  m*/
                } else if (logger.isWarnEnabled()) {
                    logger.warn("Unexpected field count for {}", StringUtils.abbreviate(line, 100));
                }
            }

            count++;
        }
    }
    return count;
}

From source file:com.haulmont.cuba.web.gui.components.table.AbbreviatedColumnGenerator.java

@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
    Property property = source.getItem(itemId).getItemProperty(columnId);
    Object value = property.getValue();

    if (value == null) {
        return null;
    }//w  ww.  ja  v  a  2s  .  com

    String stringValue = value.toString();
    if (columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
            stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value);
        }
    }
    String cellValue = stringValue;
    boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
    if (isMultiLineCell) {
        cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
    }

    int maxTextLength = column.getMaxTextLength();
    if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
        return StringUtils.abbreviate(cellValue, maxTextLength);
    } else {
        return cellValue;
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.background.DownloadBehaviorJob.java

/**
 * Performs the download and calls the callback method.
 *///from  ww  w  . jav a2 s  . c o m
@Override
public void run() {
    final Scriptable scope = callback_.getParentScope();
    final WebRequest request = new WebRequest(url_);
    try {
        final WebResponse webResponse = client_.loadWebResponse(request);
        final String content = webResponse.getContentAsString();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
        }
        final Object[] args = new Object[] { content };
        final ContextAction action = new ContextAction() {
            @Override
            public Object run(final Context cx) {
                callback_.call(cx, scope, scope, args);
                return null;
            }
        };
        final ContextFactory cf = client_.getJavaScriptEngine().getContextFactory();
        cf.call(action);
    } catch (final IOException e) {
        LOG.error("Behavior #default#download: Cannot download " + url_, e);
    }
}

From source file:ca.phon.app.project.RecentProjectListCellRenderer.java

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

    //      comp.setVerticalTextPosition(JLabel.BOTTOM);
    //      comp.setHorizontalTextPosition(JLabel.CENTER);

    // if the file string stats with RMI, show the remote project icon,
    // otherwise, show the default project icon
    if (value.toString().startsWith("rmi://"))
        comp.setIcon(remoteProjectIcon);
    else/*from ww  w. java 2 s  .  c o m*/
        comp.setIcon(localProjectIcon);

    int numChars = 20;
    int numBreaks = value.toString().length() / numChars;

    //      String compString = new String();
    //      for(int i = 0; i < numBreaks; i++) {
    //         compString += value.toString().substring(i*numChars, i*numChars+numChars) + "<br>";
    //      }
    //      compString += value.toString().substring(numBreaks*numChars, 
    //            value.toString().length());

    comp.setText("<html><center>" + StringUtils.abbreviate(value.toString(), 60) + "</center></html>");

    return comp;
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java

@Test
public void otherUtils() {
    // ignoreCase:contains/startWith/EndWith/indexOf/lastIndexOf
    assertThat(StringUtils.containsIgnoreCase("Aaabbb", "aaa")).isTrue();
    assertThat(StringUtils.indexOfIgnoreCase("Aaabbb", "aaa")).isEqualTo(0);

    // 0/*from  www.  j  a  v  a  2s.  com*/
    assertThat(StringUtils.leftPad("1", 3, '0')).isEqualTo("001");
    assertThat(StringUtils.leftPad("12", 3, '0')).isEqualTo("012");

    // ???
    assertThat(StringUtils.abbreviate("abcdefg", 7)).isEqualTo("abcdefg");
    assertThat(StringUtils.abbreviate("abcdefg", 6)).isEqualTo("abc...");

    // ?/?
    assertThat(StringUtils.capitalize("abc")).isEqualTo("Abc");
    assertThat(StringUtils.uncapitalize("Abc")).isEqualTo("abc");
}

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

public static String createHrefUrls(String text, boolean showFullURL) {
    String replacedText = text;/*w  w  w . j av a  2  s  .c  o m*/
    List<String> urls = extractUrls(text);
    for (String url : urls) {
        String resoureName = url;
        if (showFullURL == false) {
            resoureName = StringUtils.abbreviate(getResourceNameFromUrl(url), MAX_RESOURCE_NAME);
        }
        String link = "<a href='" + url + "' title='" + url + "' target='_blank'> " + resoureName + "</a>";
        replacedText = replacedText.replace(url, link);
    }
    return replacedText;
}

From source file:de.jcup.egradle.core.util.History.java

public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("History (");
    sb.append(list.size());/*from  w w  w.ja v  a 2  s  .  c o  m*/
    sb.append('/');
    sb.append(max);
    sb.append("):\n");
    int i = 0;
    for (T data : list) {
        sb.append(i);
        sb.append('=');
        sb.append(StringUtils.abbreviate(Objects.toString(data), 40));
        sb.append("\n");
    }
    return sb.toString();
}

From source file:hoot.services.controllers.osm.CapabilitiesResource.java

/**
 * <NAME>Capabilities Service</NAME>
 * <DESCRIPTION>/*from www.  j  a v  a2s  .c om*/
 * The Hootenanny Capabilities Service implements the OSM
 * Capabilities Service v0.6 with some differences. The Hootenanny API does not support the following
 * capabilities properties: tracepoints
 * </DESCRIPTION>
 * <PARAMETERS>
 * </PARAMETERS>
 * <OUTPUT>
 *    Capability OSM XML
 * </OUTPUT>
 * <EXAMPLE>
 *    <URL>http://localhost:8080/hoot-services/osm/api/capabilities</URL>
 *    <REQUEST_TYPE>GET</REQUEST_TYPE>
 *    <INPUT>
 *   </INPUT>
 * <OUTPUT>
 * Capability OSM XML
 * see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmCapabilitiesService
 * </OUTPUT>
 * </EXAMPLE>
*
* Service method endpoint for retrieving OSM capabilities
*
* @return Response containing requested capabilities data
* @see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmCapabilitiesService
*/
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_XML)
public Response get() {
    try {
        log.info("Retrieving capabilities...");

        Document responseDoc = (new CapabilitiesResponseWriter()).writeResponse();
        log.debug("Returning response: " + StringUtils.abbreviate(XmlDocumentBuilder.toString(responseDoc), 100)
                + " ...");
        return Response.ok(new DOMSource(responseDoc), MediaType.TEXT_XML)
                .header("Content-type", MediaType.TEXT_XML).build();
    } catch (Exception e) {
        final String message = "Error retrieving capabilities: " + e.getMessage();
        log.error(message);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build();
    }
}

From source file:de.micromata.genome.chronos.spi.jdbc.TriggerJobDisplayDO.java

public String getJobDefinitionStringShort() {
    String s = super.getJobDefinitionString();

    if (s == null || s.length() == 0) {
        return "";
    }//from  w w w .  ja  v a  2 s  . co m
    String st = "<classToStart>";
    int idx = s.indexOf("<classToStart>");
    if (idx != -1) {
        s = s.substring(idx + st.length());
        idx = s.indexOf("<");
        if (idx != -1) {
            s = s.substring(0, idx);
        }
        return s;
    }
    // GWAFactoryBean
    st = "<className>";
    idx = s.indexOf("<className>");
    if (idx != -1) {
        s = s.substring(idx + st.length());
        idx = s.indexOf("<");
        if (idx != -1) {
            s = s.substring(0, idx);
        }
        return s;
    }

    // if (s.startsWith("<") == true) {
    // s = StringUtils.substring(s, 1, 50);
    // } else {
    s = StringUtils.abbreviate(s, 50);
    // }
    idx = s.indexOf('\n');
    if (idx != -1) {
        s = s.substring(0, idx);
    }
    return s;
}