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.duracloud.syncui.service.SyncProcessManagerImpl.java

private void startSyncProcess() throws SyncProcessException {
    DirectoryConfigs directories = this.syncConfigurationManager.retrieveDirectoryConfigs();

    if (directories.isEmpty()) {
        throw new SyncProcessException("unable to start because " + "no watch directories are configured.");
    }/*  www  .  j  a v a 2 s  .c o m*/
    List<File> dirs = directories.toFileList();

    DuracloudConfiguration dc = this.syncConfigurationManager.retrieveDuracloudConfiguration();

    try {
        ContentStoreManager csm = contentStoreManagerFactory.create();
        String username = dc.getUsername();
        String spaceId = dc.getSpaceId();
        csm.login(new Credential(username, dc.getPassword()));
        ContentStore contentStore = csm.getPrimaryContentStore();
        boolean syncDeletes = this.syncConfigurationManager.isSyncDeletes();
        String prefix = this.syncConfigurationManager.getPrefix();
        SyncEndpoint syncEndpoint = new DuraStoreChunkSyncEndpoint(contentStore, username, spaceId, syncDeletes,
                this.syncConfigurationManager.getMaxFileSizeInBytes(), // 1GB chunk size
                this.syncConfigurationManager.isSyncUpdates(), this.syncConfigurationManager.isRenameUpdates(),
                this.syncConfigurationManager.isJumpStart(), this.syncConfigurationManager.getUpdateSuffix(),
                prefix);

        syncEndpoint.addEndPointListener(new EndPointLogger());

        this.backupDir.mkdirs();

        syncBackupManager = new SyncBackupManager(this.backupDir, BACKUP_FREQUENCY, dirs);

        long backup = -1;
        if (syncBackupManager.hasBackups()) {
            backup = syncBackupManager.attemptRestart();
        }

        syncManager = new SyncManager(dirs, syncEndpoint, this.syncConfigurationManager.getThreadCount(), // threads
                CHANGE_LIST_MONITOR_FREQUENCY); // change list poll frequency
        syncManager.beginSync();

        RunMode mode = this.syncConfigurationManager.getMode();

        if (backup < 0) {
            dirWalker = DirWalker.start(dirs, new FileExclusionManager());
        } else if (mode.equals(RunMode.CONTINUOUS)) {
            dirWalker = RestartDirWalker.start(dirs, backup, new FileExclusionManager());
        }

        startBackupsOnDirWalkerCompletion();

        dirMonitor = new DirectoryUpdateMonitor(dirs, CHANGE_LIST_MONITOR_FREQUENCY, syncDeletes);

        configureMode(mode);
        if (syncDeletes) {
            deleteChecker = DeleteChecker.start(syncEndpoint, spaceId, dirs, prefix);
        }

    } catch (ContentStoreException e) {
        String message = StringUtils.abbreviate(e.getMessage(), 100);
        handleStartupException(message, e);
    } catch (Exception e) {
        String message = StringUtils.abbreviate(e.getMessage(), 100);
        handleStartupException(message, e);
    }
}

From source file:org.eclim.plugin.core.command.complete.CodeCompleteResult.java

/**
 * Creates the menu text based on the supplied text info.
 *
 * @param info The info text.//from w w  w  .jav a 2  s.c o  m
 * @return The menu text
 */
public static String menuFromInfo(String info) {
    if (info == null) {
        return null;
    }

    String menu = info;
    Matcher matcher = FIRST_LINE.matcher(menu);
    if (menu.length() > 1 && matcher.find(1)) {
        menu = menu.substring(0, matcher.start() + 1);
        if (menu.endsWith("<")) {
            menu = menu.substring(0, menu.length() - 1);
        }
    }
    menu = menu.replaceAll("\n", StringUtils.EMPTY);
    menu = menu.replaceAll("<.*?>", StringUtils.EMPTY);
    return StringUtils.abbreviate(menu, MAX_SHORT_DESCRIPTION_LENGTH);
}

From source file:org.eclipse.jubula.client.core.model.TestResultPO.java

/**
 * @param statusDescription the statusDescription to set
 *///from  ww  w  .  j a va  2  s .  c  o  m
public void setStatusDescription(String statusDescription) {
    if (statusDescription != null && statusDescription.length() > 1000) {
        log.error(NLS.bind(Messages.LongerThanExpected, new Object[] { 1000 }) + statusDescription);
    }
    m_statusDescription = StringUtils.abbreviate(statusDescription, 1000);

}

From source file:org.eclipse.mylyn.internal.reviews.r4e.connector.ui.editor.ArtifactsSection.java

private void createSubSection(final R4EItem item, Section section) {
    int style = ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT
            | ExpandableComposite.LEFT_TEXT_CLIENT_ALIGNMENT;
    final Section subSection = toolkit.createSection(composite, style);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(subSection);
    String description = item.getDescription();
    description = StringUtils.replace(description, "\n", "");
    description = StringUtils.abbreviate(description, 100);
    if (description == null) {
        description = "Item";
    }/*from   w  w  w.java 2s .  com*/
    subSection.setText(description);
    subSection.setTitleBarForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    subSection.setToolTipText(item.getDescription());

    addTextClient(toolkit, subSection, "", false); //$NON-NLS-1$

    if (subSection.isExpanded()) {
        createSubSectionContents(item, subSection);
    }
    subSection.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            if (subSection.getClient() == null) {
                createSubSectionContents(item, subSection);
            }
        }
    });
}

From source file:org.eclipse.mylyn.internal.reviews.ui.dialogs.CommentInputDialog.java

@Override
protected void createFormContent(final IManagedForm mform) {
    final ScrolledForm scrolledform = mform.getForm();
    scrolledform.setExpandVertical(true);
    scrolledform.setExpandHorizontal(true);
    final Composite composite = scrolledform.getBody();

    scrolledform.setContent(composite);/* w ww  .  j  a  v a2 s  .c  o  m*/

    final GridLayout layout = new GridLayout(1, false);

    composite.setLayout(layout);
    GridData textGridData = null;

    commentButtons = new ArrayList<Button>();
    for (final IComment comment : commentList) {
        final Button commentSelectionButton = new Button(composite, SWT.RADIO);
        commentSelectionButton.setBackground(composite.getBackground());

        final String authorAndDate;
        if (comment.getAuthor() != null) {
            authorAndDate = comment.getAuthor().getDisplayName() + " " //$NON-NLS-1$
                    + comment.getCreationDate().toString();
        } else {
            authorAndDate = Messages.CommentInputDialog_No_author + " " //$NON-NLS-1$
                    + comment.getCreationDate().toString();
        }

        String commentPrefix = StringUtils.abbreviate(comment.getDescription(), 50);
        if (comment.isDraft()) {
            commentSelectionButton
                    .setText(NLS.bind(Messages.CommentInputDialog_Draft, authorAndDate, commentPrefix));
        } else {
            commentSelectionButton.setText(authorAndDate + " " + commentPrefix); //$NON-NLS-1$
        }

        commentSelectionButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                selectComment(comment);
            }
        });
        GridDataFactory.fillDefaults().span(2, 1).applyTo(commentSelectionButton);
        commentButtons.add(commentSelectionButton);
    }

    fCommentInputTextField = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP);

    textGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    textGridData.horizontalSpan = 2;
    textGridData.minimumHeight = fCommentInputTextField.getLineHeight() * 4;
    fCommentInputTextField.setToolTipText(Messages.ReviewsCommentToolTip);
    fCommentInputTextField.setLayoutData(textGridData);
    fCommentInputTextField.setEnabled(false);

    //Set default focus
    fCommentInputTextField.setFocus();

    this.setHelpAvailable(false);
}

From source file:org.eclipse.skalli.view.component.MultiLinkField.java

@SuppressWarnings({ "serial", "deprecation" })
private void render() {
    layout.removeAllComponents();//from   ww w.ja va 2 s.  co  m
    if (!readOnly) {
        layout.setColumns(2);
    }

    int groupsIdx = 0;
    int groupsSize = linkGroups.getItems().size();
    for (final LinkGroup linkGroup : linkGroups.getItems()) {
        Label linkGroupLabel = new Label(linkGroup.getCaption());
        linkGroupLabel.addStyleName(STYLE_LABEL_GROUP);

        layout.addComponent(linkGroupLabel);
        layout.setComponentAlignment(linkGroupLabel, Alignment.TOP_RIGHT);

        if (!readOnly) {
            Button btnUpGroup = null;
            Button btnDownGroup = null;
            Button btnRemoveGroup = null;
            // up
            if (groupsIdx > 0) {
                btnUpGroup = new Button("up");
                btnUpGroup.setStyleName(Button.STYLE_LINK);
                btnUpGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnUpGroup.setDescription(String.format("Move up group '%s'", linkGroup.getCaption()));
                btnUpGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveUp(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // down
            if (groupsIdx < groupsSize - 1) {
                btnDownGroup = new Button("down");
                btnDownGroup.setStyleName(Button.STYLE_LINK);
                btnDownGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnDownGroup.setDescription(String.format("Move down group '%s'", linkGroup.getCaption()));
                btnDownGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveDown(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // remove
            btnRemoveGroup = new Button("remove");
            btnRemoveGroup.setStyleName(Button.STYLE_LINK);
            btnRemoveGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
            btnRemoveGroup.setDescription(String.format("Remove group '%s'", linkGroup.getCaption()));
            btnRemoveGroup.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    modified = linkGroups.remove(linkGroup);
                    renderIfModified();
                }
            });

            HorizontalLayout toolbar = getToolbar(btnUpGroup, btnDownGroup, btnRemoveGroup);
            layout.addComponent(toolbar);
            layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
        }

        layout.newLine();

        Collection<Link> links = linkGroup.getItems();
        int linksIdx = 0;
        int linksSize = links.size();
        for (final Link link : links) {

            if (readOnly) {
                // view
                Label linkLabel = new Label(link.getLabel());
                linkLabel.addStyleName(STYLE_LABEL_LINK);
                linkLabel.setDescription(StringUtils.abbreviate(link.getUrl(), 50));
                layout.addComponent(linkLabel);
                layout.setComponentAlignment(linkLabel, Alignment.TOP_LEFT);
            } else {
                // edit
                Button btnEditLink = new Button(link.getLabel());
                btnEditLink.setStyleName(Button.STYLE_LINK);
                btnEditLink.addStyleName(STYLE_LABEL_LINK);
                btnEditLink.setDescription(String.format("Edit link '%s' %s", link.getLabel(),
                        StringUtils.isBlank(link.getUrl()) ? "" : "[" + link.getUrl() + "]"));
                btnEditLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        LinkWindow editLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                                linkGroup, link, MultiLinkField.this);
                        editLinkWindow.show();
                    }
                });
                layout.addComponent(btnEditLink);
                layout.setComponentAlignment(btnEditLink, Alignment.TOP_LEFT);
            }

            if (!readOnly) {
                Button btnUpLink = null;
                Button btnDownLink = null;
                Button btnRemoveLink = null;
                // up
                if (linksIdx > 0) {
                    btnUpLink = new Button("up");
                    btnUpLink.setStyleName(Button.STYLE_LINK);
                    btnUpLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnUpLink.setDescription(String.format("Move up link '%s'", link.getLabel()));
                    btnUpLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveUp(link);
                            renderIfModified();
                        }
                    });
                }
                // down
                if (linksIdx < linksSize - 1) {
                    btnDownLink = new Button("down");
                    btnDownLink.setStyleName(Button.STYLE_LINK);
                    btnDownLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnDownLink.setDescription(String.format("Move down link '%s'", link.getLabel()));
                    btnDownLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveDown(link);
                            renderIfModified();
                        }
                    });
                }
                // remove
                btnRemoveLink = new Button("remove");
                btnRemoveLink.setStyleName(Button.STYLE_LINK);
                btnRemoveLink.addStyleName(STYLE_BUTTON_LINKACTION);
                btnRemoveLink.setDescription(String.format("Remove link '%s'", link.getLabel()));
                btnRemoveLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroup.remove(link);
                        if (linkGroup.getItems().isEmpty()) {
                            linkGroups.remove(linkGroup);
                        }
                        renderIfModified();
                    }
                });

                HorizontalLayout toolbar = getToolbar(btnUpLink, btnDownLink, btnRemoveLink);
                layout.addComponent(toolbar);
                layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
            }

            layout.newLine();

            linksIdx++;
        }

        groupsIdx++;
    }

    if (!readOnly) {
        Button btnAddLink = new Button(buttonCaption, new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                LinkWindow addLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                        MultiLinkField.this);
                addLinkWindow.show();
            }
        });
        btnAddLink.setStyleName(Button.STYLE_LINK);
        btnAddLink.addStyleName(STYLE_BUTTON_ADD);
        btnAddLink.setDescription("Add Link");
        layout.addComponent(btnAddLink);
    }
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.FeedInfoBox.java

@SuppressWarnings("nls")
private void addEntry(Project project, String userId, HtmlBuilder html, Entry entry) {
    html.append("<p class=\"").append(STYLE_TIMELINE_ENTRY).append("\">");

    String title = StringUtils.abbreviate(entry.getTitle(), MAX_DISPLAY_LENGTH_TITLE);

    String link = null;//ww  w  .  j ava  2s  . c o  m
    if (entry.getLink() != null) {
        link = entry.getLink().getHref();
    }

    link = mapLink(project, userId, link);

    html.appendLink(HtmlUtils.clean(title), link);

    html.append("<br />");

    String source = entry.getSource();
    if (StringUtils.isNotBlank(HtmlUtils.clean(source))) {
        html.append(source);
    }

    String date = getDate(entry);
    if (StringUtils.isNotBlank(date)) {
        html.append(" - ").append(HtmlUtils.clean(date));
    }

    String author = getAuthor(entry);
    if (StringUtils.isNotBlank(author)) {
        html.append(" - ").append(HtmlUtils.clean(author));
    }
    html.append("</p>");
}

From source file:org.eclipse.sw360.portal.tags.OutTag.java

@Override
public int doStartTag() throws JspException {
    if (value instanceof String) {
        boolean abbreviated = false;
        String candidate = (String) this.value;
        String originalValue = candidate;
        if (maxChar > 4) {
            candidate = StringUtils.abbreviate(candidate, maxChar);
            if (!originalValue.equals(candidate)) {
                abbreviated = true;/*from   w w  w .ja  v a2 s.  com*/
            }
        }

        if (stripNewlines) {
            candidate = candidate.replaceAll("[\r\n]+", " ");
        }
        if ("'".equals(jsQuoting)) {
            candidate = escapeInSingleQuote(candidate);
        } else if ("\"".equals(jsQuoting)) {
            candidate = escapeInDoubleQuote(candidate);
        }
        this.value = candidate;

        if (abbreviated) {
            try {
                this.pageContext.getOut().write("<span title=\"" + escapeInDoubleQuote(originalValue) + "\">");
                int i = super.doStartTag();
                this.pageContext.getOut().write("</span>");
                return i;
            } catch (IOException e) {
                throw new JspException(e.toString(), e);
            }
        }
    }
    return super.doStartTag();
}

From source file:org.ejbca.ui.cli.service.ServiceListCommand.java

@Override
public CommandResult execute(ParameterContainer parameters) {

    final ServiceSessionRemote serviceSession = EjbRemoteHelper.INSTANCE
            .getRemoteSession(ServiceSessionRemote.class);
    Collection<Integer> availableServicesIds = serviceSession
            .getAuthorizedVisibleServiceIds(getAuthenticationToken());
    if (availableServicesIds.size() == 0) {
        getLogger().info("No services are available.");
        return CommandResult.SUCCESS;
    }/*from w ww.j a  v  a 2  s .co  m*/

    getLogger().info("Actv| Service name    | Worker           | Interval         | Action           ");
    getLogger().info("----+-----------------+------------------+------------------+------------------");
    for (Integer serviceId : availableServicesIds) {
        StringBuilder row = new StringBuilder();
        ServiceConfiguration serviceConfig = serviceSession.getServiceConfiguration(getAuthenticationToken(),
                serviceId);

        // Active
        row.append(serviceConfig.isActive() ? "  X |" : "    |");

        // Name
        row.append(' ');
        String serviceName = serviceSession.getServiceName(serviceId.intValue());
        row.append(StringUtils.rightPad(StringUtils.abbreviate(serviceName, 15), 16));
        row.append('|');

        // Class paths
        addClassPath(row, serviceConfig.getWorkerClassPath());
        row.append('|');
        addClassPath(row, serviceConfig.getIntervalClassPath());
        row.append('|');
        addClassPath(row, serviceConfig.getActionClassPath());

        getLogger().info(row.toString());
    }
    return CommandResult.SUCCESS;
}

From source file:org.ejbca.ui.cli.service.ServiceListCommand.java

private void addClassPath(StringBuilder row, String classPath) {
    row.append(' ');
    final String className = classPath.replaceFirst("^.*\\.", "");
    row.append(StringUtils.rightPad(StringUtils.abbreviate(className, 16), 17));
}