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.sakaiproject.profile2.tool.pages.panels.MessageThreadsView.java

public MessageThreadsView(final String id) {
    super(id);//ww w  .j  a  v  a  2  s .  com

    log.debug("MessageThreads()");

    //get current user
    final String currentUserUuid = sakaiProxy.getCurrentUserId();

    //heading
    /*
    Label heading = new Label("messageThreadListHeading", new ResourceModel("heading.messages"));
    add(heading);
    */

    //no messages label
    Label noMessagesLabel = new Label("noMessagesLabel");
    noMessagesLabel.setOutputMarkupPlaceholderTag(true);
    add(noMessagesLabel);

    //container which wraps list
    final WebMarkupContainer messageThreadListContainer = new WebMarkupContainer("messageThreadListContainer");
    messageThreadListContainer.setOutputMarkupId(true);

    //get our list of messages
    final MessageThreadsDataProvider provider = new MessageThreadsDataProvider(currentUserUuid);
    int numMessages = (int) provider.size();

    //message list
    DataView<MessageThread> messageThreadList = new DataView<MessageThread>("messageThreadList", provider) {
        private static final long serialVersionUID = 1L;

        protected void populateItem(final Item<MessageThread> item) {

            final MessageThread thread = (MessageThread) item.getDefaultModelObject();
            Message message = thread.getMostRecentMessage();
            String messageFromUuid = message.getFrom();

            //we need to know if this message has been read or not so we can style it accordingly
            //we only need this if we didn't send the message
            MessageParticipant participant = null;

            boolean messageOwner = false;
            if (StringUtils.equals(messageFromUuid, currentUserUuid)) {
                messageOwner = true;
            }
            if (!messageOwner) {
                participant = messagingLogic.getMessageParticipant(message.getId(), currentUserUuid);
            }

            //prefs and privacy
            ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(messageFromUuid);
            ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(messageFromUuid);

            //photo link
            AjaxLink<String> photoLink = new AjaxLink<String>("photoLink", new Model<String>(messageFromUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    setResponsePage(new ViewProfile(getModelObject()));
                }

            };

            //photo
            ProfileImage messagePhoto = new ProfileImage("messagePhoto", new Model<String>(messageFromUuid));
            messagePhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
            photoLink.add(messagePhoto);
            item.add(photoLink);

            //name link
            AjaxLink<String> messageFromLink = new AjaxLink<String>("messageFromLink",
                    new Model<String>(messageFromUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    setResponsePage(new ViewProfile(getModelObject()));
                }

            };
            messageFromLink.add(new Label("messageFromName",
                    new Model<String>(sakaiProxy.getUserDisplayName(messageFromUuid))));
            item.add(messageFromLink);

            //date
            item.add(new Label("messageDate", ProfileUtils.convertDateToString(message.getDatePosted(),
                    ProfileConstants.MESSAGE_DISPLAY_DATE_FORMAT)));

            //subject link
            AjaxLink<MessageThread> messageSubjectLink = new AjaxLink<MessageThread>("messageSubjectLink",
                    new Model<MessageThread>(thread)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    //load messageview panel
                    //setResponsePage(new MyMessageView(id, currentUserUuid, getModelObject().getId(), getModelObject().getSubject()));

                    //load MyMessages with some params that will then load a diff tab panel and show this message panel.
                    setResponsePage(new MyMessages(thread.getId()));

                }

            };
            messageSubjectLink.add(new Label("messageSubject", new Model<String>(thread.getSubject())));
            item.add(messageSubjectLink);

            //message body
            item.add(new Label("messageBody", new Model<String>(StringUtils.abbreviate(message.getMessage(),
                    ProfileConstants.MESSAGE_PREVIEW_MAX_LENGTH))));

            //unread notice for accessibility, off unless its new.
            Label messageUnreadNotice = new Label("messageUnreadNotice",
                    new ResourceModel("accessibility.messages.unread"));
            messageUnreadNotice.setVisible(false);
            item.add(messageUnreadNotice);

            //highlight if new, also render accessibility notice
            if (!messageOwner && !participant.isRead()) {
                item.add(new AttributeAppender("class", true, new Model<String>("unread-message"), " "));
                messageUnreadNotice.setVisible(true);
            }

            item.setOutputMarkupId(true);
        }

    };
    messageThreadList.setOutputMarkupId(true);
    messageThreadList.setItemsPerPage(ProfileConstants.MAX_MESSAGES_PER_PAGE);
    messageThreadListContainer.add(messageThreadList);
    add(messageThreadListContainer);

    //pager
    AjaxPagingNavigator pager = new AjaxPagingNavigator("navigator", messageThreadList);
    add(pager);

    //initially, if no message threads to show, hide container and pager, set and show label
    if (numMessages == 0) {
        messageThreadListContainer.setVisible(false);
        pager.setVisible(false);

        noMessagesLabel.setDefaultModel(new ResourceModel("text.messages.none"));
        noMessagesLabel.setVisible(true);
    }

    //also, if num less than num required for pager, hide it
    if (numMessages <= ProfileConstants.MAX_MESSAGES_PER_PAGE) {
        pager.setVisible(false);
    }
}

From source file:org.sakaiproject.profile2.tool.pages.panels.RequestedFriends.java

public RequestedFriends(final String id, final String userUuid) {
    super(id);//from   ww  w  .  j  a v a2  s.c o  m

    log.debug("RequestedFriends()");

    final String currentUserUuid = sakaiProxy.getCurrentUserId();

    //setup model to store the actions in the modal windows
    final FriendAction friendActionModel = new FriendAction();

    //get our list of friend requests as an IDataProvider
    RequestedFriendsDataProvider provider = new RequestedFriendsDataProvider(userUuid);

    //init number of requests
    numRequestedFriends = (int) provider.size();

    //model so we can update the number of requests
    IModel<Integer> numRequestedFriendsModel = new Model<Integer>() {
        private static final long serialVersionUID = 1L;

        public Integer getObject() {
            return numRequestedFriends;
        }
    };

    //heading
    final WebMarkupContainer requestedFriendsHeading = new WebMarkupContainer("requestedFriendsHeading");
    requestedFriendsHeading
            .add(new Label("requestedFriendsLabel", new ResourceModel("heading.friend.requests")));
    requestedFriendsHeading.add(new Label("requestedFriendsNumber", numRequestedFriendsModel));
    requestedFriendsHeading.setOutputMarkupId(true);
    add(requestedFriendsHeading);

    //container which wraps list
    final WebMarkupContainer requestedFriendsContainer = new WebMarkupContainer("requestedFriendsContainer");
    requestedFriendsContainer.setOutputMarkupId(true);

    //connection window
    final ModalWindow connectionWindow = new ModalWindow("connectionWindow");

    //search results
    DataView<Person> requestedFriendsDataView = new DataView<Person>("connections", provider) {
        private static final long serialVersionUID = 1L;

        protected void populateItem(final Item<Person> item) {

            Person person = (Person) item.getDefaultModelObject();
            final String personUuid = person.getUuid();

            //get name
            String displayName = person.getDisplayName();

            //get other objects
            ProfilePrivacy privacy = person.getPrivacy();
            ProfilePreferences prefs = person.getPreferences();

            //image wrapper, links to profile
            Link<String> friendItem = new Link<String>("connectionPhotoWrap", new Model<String>(personUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick() {
                    setResponsePage(new ViewProfile(getModelObject()));
                }
            };

            //image
            ProfileImage connectionPhoto = new ProfileImage("connectionPhoto", new Model<String>(personUuid));
            connectionPhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
            friendItem.add(connectionPhoto);

            item.add(friendItem);

            //name and link to profile
            Link<String> profileLink = new Link<String>("connectionLink", new Model<String>(personUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick() {
                    setResponsePage(new ViewProfile(getModelObject()));
                }
            };
            profileLink.add(new Label("connectionName", displayName));
            item.add(profileLink);

            //status component
            ProfileStatusRenderer status = new ProfileStatusRenderer("connectionStatus", person,
                    "connection-status-msg", "connection-status-date");
            status.setOutputMarkupId(true);
            item.add(status);

            //CONFIRM FRIEND LINK AND WINDOW

            WebMarkupContainer c1 = new WebMarkupContainer("confirmConnectionContainer");
            c1.setOutputMarkupId(true);

            final AjaxLink<String> confirmConnectionLink = new AjaxLink<String>("confirmConnectionLink",
                    new Model<String>(personUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {

                    //get this item, and set content for modalwindow
                    String personUuid = getModelObject();
                    connectionWindow.setContent(new ConfirmFriend(connectionWindow.getContentId(),
                            connectionWindow, friendActionModel, userUuid, personUuid));

                    //modalwindow handler 
                    connectionWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
                        private static final long serialVersionUID = 1L;

                        public void onClose(AjaxRequestTarget target) {
                            if (friendActionModel.isConfirmed()) {

                                //decrement number of requests
                                numRequestedFriends--;

                                //remove friend item from display
                                target.appendJavaScript("$('#" + item.getMarkupId() + "').slideUp();");

                                //update label
                                target.add(requestedFriendsHeading);

                                //get parent panel and repaint ConfirmedFriends panel via helper method in MyFriends 
                                findParent(MyFriends.class).updateConfirmedFriends(target, userUuid);

                                //if none left, hide everything
                                if (numRequestedFriends == 0) {
                                    target.appendJavaScript(
                                            "$('#" + requestedFriendsHeading.getMarkupId() + "').fadeOut();");
                                    target.appendJavaScript(
                                            "$('#" + requestedFriendsContainer.getMarkupId() + "').fadeOut();");
                                }
                            }
                        }
                    });

                    connectionWindow.show(target);
                    target.appendJavaScript("fixWindowVertical();");
                }
            };
            //ContextImage confirmConnectionIcon = new ContextImage("confirmConnectionIcon",new Model<String>(ProfileConstants.ACCEPT_IMG));
            //confirmConnectionLink.add(confirmConnectionIcon);
            confirmConnectionLink
                    .add(new AttributeModifier("title", true, new ResourceModel("link.title.confirmfriend")));
            confirmConnectionLink.add(new AttributeModifier("alt", true, new StringResourceModel(
                    "accessibility.connection.confirm", null, new Object[] { displayName })));
            confirmConnectionLink
                    .add(new Label("confirmConnectionLabel", new ResourceModel("link.friend.confirm"))
                            .setOutputMarkupId(true));
            c1.add(confirmConnectionLink);
            item.add(c1);

            //IGNORE FRIEND LINK AND WINDOW

            WebMarkupContainer c2 = new WebMarkupContainer("ignoreConnectionContainer");
            c2.setOutputMarkupId(true);

            final AjaxLink<String> ignoreConnectionLink = new AjaxLink<String>("ignoreConnectionLink",
                    new Model<String>(personUuid)) {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {

                    //get this item, and set content for modalwindow
                    String personUuid = getModelObject();
                    connectionWindow.setContent(new IgnoreFriend(connectionWindow.getContentId(),
                            connectionWindow, friendActionModel, userUuid, personUuid));

                    //modalwindow handler 
                    connectionWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
                        private static final long serialVersionUID = 1L;

                        public void onClose(AjaxRequestTarget target) {
                            if (friendActionModel.isIgnored()) {

                                //decrement number of requests
                                numRequestedFriends--;

                                //remove friend item from display
                                target.appendJavaScript("$('#" + item.getMarkupId() + "').slideUp();");

                                //update label
                                target.add(requestedFriendsHeading);

                                //if none left, hide everything
                                if (numRequestedFriends == 0) {
                                    target.appendJavaScript(
                                            "$('#" + requestedFriendsHeading.getMarkupId() + "').fadeOut();");
                                    target.appendJavaScript(
                                            "$('#" + requestedFriendsContainer.getMarkupId() + "').fadeOut();");
                                }
                            }
                        }
                    });

                    connectionWindow.show(target);
                    target.appendJavaScript("fixWindowVertical();");
                }
            };
            //ContextImage ignoreConnectionIcon = new ContextImage("ignoreConnectionIcon",new Model<String>(ProfileConstants.CANCEL_IMG));
            //ignoreConnectionLink.add(ignoreConnectionIcon);
            ignoreConnectionLink
                    .add(new AttributeModifier("title", true, new ResourceModel("link.title.ignorefriend")));
            ignoreConnectionLink.add(new AttributeModifier("alt", true, new StringResourceModel(
                    "accessibility.connection.ignore", null, new Object[] { displayName })));
            ignoreConnectionLink.add(new Label("ignoreConnectionLabel", new ResourceModel("link.friend.ignore"))
                    .setOutputMarkupId(true));
            c2.add(ignoreConnectionLink);
            item.add(c2);

            WebMarkupContainer c3 = new WebMarkupContainer("viewFriendsContainer");
            c3.setOutputMarkupId(true);

            final AjaxLink<String> viewFriendsLink = new AjaxLink<String>("viewFriendsLink") {
                private static final long serialVersionUID = 1L;

                public void onClick(AjaxRequestTarget target) {
                    // always ViewFriends because a user isn't connected to himself
                    setResponsePage(new ViewFriends(personUuid));
                }
            };
            final Label viewFriendsLabel = new Label("viewFriendsLabel",
                    new ResourceModel("link.view.friends"));
            viewFriendsLink.add(viewFriendsLabel);

            //hide if not allowed
            if (!privacyLogic.isActionAllowed(userUuid, currentUserUuid,
                    PrivacyType.PRIVACY_OPTION_MYFRIENDS)) {
                viewFriendsLink.setEnabled(false);
                c3.setVisible(false);
            }
            viewFriendsLink.setOutputMarkupId(true);
            c3.add(viewFriendsLink);
            item.add(c3);

            WebMarkupContainer c4 = new WebMarkupContainer("emailContainer");
            c4.setOutputMarkupId(true);

            ExternalLink emailLink = new ExternalLink("emailLink", "mailto:" + person.getProfile().getEmail(),
                    new ResourceModel("profile.email").getObject());

            c4.add(emailLink);

            // friend=false
            if (StringUtils.isBlank(person.getProfile().getEmail())
                    || false == privacyLogic.isActionAllowed(person.getUuid(), currentUserUuid,
                            PrivacyType.PRIVACY_OPTION_CONTACTINFO)) {

                c4.setVisible(false);
            }
            item.add(c4);

            WebMarkupContainer c5 = new WebMarkupContainer("websiteContainer");
            c5.setOutputMarkupId(true);

            // TODO home page, university profile URL or academic/research URL (see PRFL-35)
            ExternalLink websiteLink = new ExternalLink("websiteLink", person.getProfile().getHomepage(),
                    new ResourceModel("profile.homepage").getObject()).setPopupSettings(new PopupSettings());

            c5.add(websiteLink);

            // friend=false
            if (StringUtils.isBlank(person.getProfile().getHomepage())
                    || false == privacyLogic.isActionAllowed(person.getUuid(), currentUserUuid,
                            PrivacyType.PRIVACY_OPTION_CONTACTINFO)) {

                c5.setVisible(false);
            }
            item.add(c5);

            // not a friend yet, so friend=false
            if (true == privacyLogic.isActionAllowed(person.getUuid(), sakaiProxy.getCurrentUserId(),
                    PrivacyType.PRIVACY_OPTION_BASICINFO)) {

                item.add(new Label("connectionSummary", StringUtils
                        .abbreviate(ProfileUtils.stripHtml(person.getProfile().getPersonalSummary()), 200)));
            } else {
                item.add(new Label("connectionSummary", ""));
            }

            item.setOutputMarkupId(true);
        }

    };
    requestedFriendsDataView.setOutputMarkupId(true);
    requestedFriendsContainer.add(requestedFriendsDataView);

    //add results container
    add(requestedFriendsContainer);

    //add window
    add(connectionWindow);

    //initially, if no requests, hide everything
    if (numRequestedFriends == 0) {
        this.setVisible(false);
    }

}

From source file:org.sakaiproject.profile2.util.ProfileUtils.java

/**
 * Trims and abbreviates text to the given maximum number of displayed
 * characters (less 3 characters, in case "..." must be appended).
 * Supports HTML and preserves formatting.
 * //from   w  w  w.j a v a 2  s  .co m
 * @param s             the string
 * @param maxNumOfChars    num chars to keep. If HTML, it's the number of content chars, ignoring tags.
 * @param isHtml       is the string HTML?
 * @return
 */
public static String truncateAndAbbreviate(String s, int maxNumOfChars, boolean isHtml) {

    if (StringUtils.isBlank(s)) {
        return "";
    }

    //html
    if (isHtml) {
        StringBuilder trimmedHtml = new StringBuilder();

        boolean trimmed = FormattedText.trimFormattedText(s, maxNumOfChars - 3, trimmedHtml);

        if (trimmed) {
            int index = trimmedHtml.lastIndexOf("</");
            if (-1 != index) {
                trimmedHtml.insert(index, "...");
            } else {
                trimmedHtml.append("...");
            }
        }
        return trimmedHtml.toString();
    }

    //plain text
    return StringUtils.abbreviate(s, maxNumOfChars);

}

From source file:org.sakaiproject.signup.logic.messages.SignupEmailBase.java

protected String getAbbreviatedMeetingTitle() {
    return StringUtils.abbreviate(meeting.getTitle(), 30);
}

From source file:org.sakaiproject.tool.section.jsf.backingbean.EditManagersBean.java

public String getAbbreviatedSectionTitle() {
    return StringUtils.abbreviate(sectionTitle, 15);
}

From source file:org.sakaiproject.tool.section.jsf.backingbean.FilteredSectionListingBean.java

protected List<String> generateTaNames(List<ParticipationRecord> tas) {
    // Generate the string showing the TAs
    List<String> taNames = new ArrayList<String>();
    for (Iterator taIter = tas.iterator(); taIter.hasNext();) {
        ParticipationRecord ta = (ParticipationRecord) taIter.next();
        taNames.add(StringUtils.abbreviate(ta.getUser().getSortName(), getPrefs().getMaxNameLength()));
    }//from  w ww  .j  av  a2  s .co m

    Collections.sort(taNames);
    return taNames;
}

From source file:org.sakaiproject.user.impl.BaseUserDirectoryService.java

/**
 * Adjust the id - trim it to null. Note: eid case insensitive option does NOT apply to id.
 *
 * @param id/*  w w  w . j  av  a 2s  . c  o m*/
 *        The id to clean up.
 * @return A cleaned up id.
 */
protected String cleanId(String id) {
    // if we are not doing separate id and eid, use the eid rules
    if (!m_separateIdEid) {
        id = cleanEid(id);
    }
    id = StringUtils.trimToNull(id);
    // max length for an id is 99 chars
    id = StringUtils.abbreviate(id, 99);
    return id;
}

From source file:org.simbasecurity.core.audit.AuditLogEvent.java

private static String truncate(String input) {
    return StringUtils.abbreviate(input, 255);
}

From source file:org.simbasecurity.core.audit.AuditLogEvent.java

private static String truncate(String input, int length) {
    return StringUtils.abbreviate(input, length);
}

From source file:org.sipfoundry.sipxconfig.common.SipxCollectionUtils.java

/**
 * Displays as much information about the array as we can without overwhelming log file with
 * useless data//from  w  w w  .  j  a va  2  s.  c o m
 */
public static String arrayToShortString(Object[] items, int len) {
    String[] strItems = new String[items.length];
    for (int i = 0; i < items.length; i++) {
        Object item = items[i];
        String itemRepr;
        if (item instanceof Object[]) {
            itemRepr = Arrays.deepToString((Object[]) item);
        } else {
            itemRepr = item.toString();
        }
        strItems[i] = StringUtils.abbreviate(itemRepr, len);
    }
    return "[" + StringUtils.join(strItems, ", ") + "]";
}