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.batoo.jpa.core.impl.criteria.QueryImpl.java

private void prepareLabels(final ResultSetMetaData md) throws SQLException {
    this.labels = new String[md.getColumnCount()];

    for (int i = 0; i < this.labels.length; i++) {
        String label = md.getColumnName(i + 1) + " (" + md.getColumnTypeName(i + 1) + ")";
        label = StringUtils.abbreviate(label, QueryImpl.MAX_COL_LENGTH);

        this.labels[i] = label;
    }/*from   ww w .j  av a  2  s  .  co m*/
}

From source file:org.betaconceptframework.astroboa.console.jsf.ContentObjectViewAsTree.java

public void presentContentObject_UIAction(String selectedContentObjectIdentifier) {
    ContentObject selectedContentObject = contentService.getContentObject(selectedContentObjectIdentifier,
            ResourceRepresentationType.CONTENT_OBJECT_INSTANCE, FetchLevel.ENTITY, CacheRegion.NONE, null,
            false);//from  w w  w  .  j  a  va  2  s. c om

    selectedContentObjectForView = contentObjectUIWrapperFactory.getInstance(selectedContentObject);

    contentObjectTitle = ((StringProperty) selectedContentObjectForView.getContentObject()
            .getCmsProperty("profile.title")).getSimpleTypeValue();

    // content object title is used as header for the contentObjectViewerPanel. So abbreviate to 100 chars to fit into one window line
    contentObjectTitle = StringUtils.abbreviate(contentObjectTitle, 100);

    // get root content object property which contains all properties
    ComplexCmsRootProperty rootProperty = selectedContentObjectForView.getContentObject()
            .getComplexCmsRootProperty();

    ContentObjectTypeDefinition contentObjectTypeDefinition = (ContentObjectTypeDefinition) definitionService
            .getCmsDefinition(selectedContentObjectForView.getContentObject().getContentObjectType(),
                    ResourceRepresentationType.DEFINITION_INSTANCE, false);

    String locale = JSFUtilities.getLocaleAsString();

    contentObjectAsTreeData = new LazyLoadingContentObjectPropertyTreeNodeRichFaces(rootProperty.getName(),
            contentObjectTypeDefinition.getDisplayName().getLocalizedLabelForLocale(locale), null,
            "ComplexTypeSingleOccurrencePropertyNode", false, rootProperty, contentObjectTypeDefinition);
}

From source file:org.betaconceptframework.astroboa.console.jsf.edit.ContentObjectEdit.java

public String abbreviateString(String stringToAbbreviate, int maxWidth) {
    if (stringToAbbreviate != null) {
        return StringUtils.abbreviate(stringToAbbreviate, maxWidth);
    } else {// ww w.ja v  a  2  s . c  om
        return "";
    }
}

From source file:org.bug4j.server.util.StringUtil.java

public static String fixTitle(String title) {
    String ret;//  w  w  w.j  a va 2 s . c o m
    if (title != null) {
        final int length = title.length();
        final StringBuilder sb = new StringBuilder(length);

        int i = 0;
        // Skip leading spaces & other bad chars
        while (i < length) {
            final char c = title.charAt(i);
            if (32 < c && c < 127) {
                break;
            }
            i++;
        }

        while (i < length) {
            // Keep good chars
            while (i < length) {
                final char c = title.charAt(i++);
                if (32 >= c || c >= 127) {
                    break;
                }
                sb.append(c);
            }
            // Skip bad chars, record a space for the last one
            while (i < length) {
                final char c = title.charAt(i);
                if (32 <= c && c < 127) {
                    sb.append(' ');
                    break;
                }
                i++;
            }
        }

        ret = sb.toString();
        ret = StringUtils.abbreviate(ret, Bug.TITLE_SIZE);
    } else {
        ret = null;
    }

    return ret;
}

From source file:org.candlepin.common.filter.TeeHttpServletRequest.java

@Override
public String getBody() {
    if (ServletLogger.showAsText(getContentType())) {
        return new String(body);
    }//  w ww  .  j a v  a 2 s  . c o m
    return StringUtils.abbreviate(Util.toBase64(body), 100);
}

From source file:org.candlepin.common.filter.TeeHttpServletResponse.java

@Override
public String getBody() {
    byte[] buff = getOutputBuffer();

    if (buff != null) {
        if (ServletLogger.showAsText(getContentType())) {
            return new String(buff);
        }/* w  ww . j  a  v  a2s .  c om*/
        return StringUtils.abbreviate(Util.toBase64(buff), 100);
    }

    return "";
}

From source file:org.carrot2.workbench.core.ui.AttributeGroups.java

/**
 * Create editors based on the given {@link GroupingMethod}.
 *///  w w  w.j a  v a  2 s .  co m
private void createEditors(Composite parent) {
    /*
     * Create a filtered view of attribute descriptors.
     */
    BindableDescriptor descriptor = this.descriptor.only(Predicates.not(new InternalAttributePredicate(false)))
            .only(new HasEditorPredicate());
    if (filterPredicate != null) {
        descriptor = descriptor.only(filterPredicate);
    }

    /*
     * CARROT-818: Check if there is anything for display. 
     */
    if (descriptor.attributeDescriptors.isEmpty()) {
        createMessage(mainControl, this, "No attributes.");
    }

    /*
     * Group attributes.
     */
    descriptor = descriptor.group(grouping);

    /*
     * Create sections for attribute groups.
     */
    for (Object groupKey : descriptor.attributeGroups.keySet()) {
        final String groupLabel;
        if (groupKey instanceof Class<?>) {
            groupLabel = ((Class<?>) groupKey).getSimpleName();
        } else {
            // Anything else, we simply convert to a string.
            groupLabel = StringUtils.abbreviate(groupKey.toString(), 160);
        }

        createEditorGroup(mainControl, groupKey.toString(), groupLabel, descriptor,
                descriptor.attributeGroups.get(groupKey), this);
    }

    /*
     * If we have a NONE grouping, then skip creating section headers.
     */
    if (grouping == GroupingMethod.NONE) {
        if (descriptor.attributeGroups.size() > 0) {
            Utils.logError("There should be no groups if grouping is NONE.", false);
        }

        if (!descriptor.attributeDescriptors.isEmpty()) {
            createUntitledEditorGroup(mainControl, descriptor, descriptor.attributeDescriptors, this);
        }
    } else {
        /*
         * Otherwise, add remaining attributes under a synthetic group.
         */
        if (!descriptor.attributeDescriptors.isEmpty()) {
            createEditorGroup(mainControl, UNGROUPED_ATTRIBUTES_GROUP, UNGROUPED_ATTRIBUTES_GROUP, descriptor,
                    descriptor.attributeDescriptors, this);
        }
    }
}

From source file:org.carrot2.workbench.core.ui.SearchEditor.java

/**
 * Abbreviates the input's title (and adds an ellipsis at end if needed).
 *//*from  w w  w .j av a2  s. c  o m*/
private String getAbbreviatedInputTitle(SearchResult searchResult) {
    final int MAX_WIDTH = 40;
    return StringUtils.abbreviate(getFullInputTitle(searchResult), MAX_WIDTH);
}

From source file:org.carrot2.workbench.vis.FlashViewPage.java

/**
 * Reloads XML data in the browser. Use {@link ReloadXMLJob} for invoking this.
 *//* w w w.  ja v a  2 s.  co  m*/
private IStatus reloadDataXml() {
    // If there is no search result, quit. Search result listener will reschedule.
    if (getProcessingResult() == null) {
        logger.debug("Reloading XML aborted: no processing result.");
        // No search result yet.
        return Status.OK_STATUS;
    }

    // If browser disposed, quit.
    if (browser.isDisposed()) {
        logger.debug("Reloading XML aborted: browser disposed.");
        return Status.OK_STATUS;
    }

    // If the page has not finished loading, reschedule.
    if (!browserInitialized) {
        logger.debug("Reloading XML rescheduled: browser not ready.");
        new ReloadXMLJob("delaying").reschedule(BROWSER_REFRESH_DELAY);
        return Status.OK_STATUS;
    }

    ProcessingResult pr = getProcessingResult();
    if (pr == lastProcessingResult) {
        logger.debug("Reloading XML aborted: identical processing result.");
        return Status.OK_STATUS;
    }

    try {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        new Persister().write(smallerMemFootprintMirror(pr), os);
        os.close();

        String xml = new String(os.toByteArray(), "UTF-8");
        logger.info("Updating view XML: " + StringEscapeUtils.escapeJava(StringUtils.abbreviate(xml, 120)));

        if (!browser.execute("javascript:updateDataXml('" + StringEscapeUtils.escapeJavaScript(xml) + "')")) {
            logger.warn("Failed to update the XML (reason unknown): " + StringUtils.abbreviate(xml, 200));
        } else {
            lastProcessingResult = pr;
        }
    } catch (Exception e) {
        logger.warn("Embedded browser error: ", e);
    }

    return Status.OK_STATUS;
}

From source file:org.cleverbus.api.entity.Request.java

public void setUri(String uri) {
    Assert.hasText(uri, "uri must not be empty");

    this.uri = StringUtils.abbreviate(uri, URI_MAX_LENGTH);
}