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.edgenius.wiki.service.impl.ActivityLogServiceImpl.java

public void logUserStatusUpdate(User user) {
    try {//from ww  w  .  j  av a 2  s  .co m
        ActivityLog activity = new ActivityLog();
        activity.setType(ActivityType.Type.USER_EVENT.getCode());
        activity.setSubType(ActivityType.SubType.UPDATE.getCode());
        activity.setSrcResourceType(SecurityValues.RESOURCE_TYPES.USER.ordinal());
        activity.setSrcResourceName(user.getUsername());
        activity.setExtroInfo(StringUtils.abbreviate(user.getSetting().getStatus(), 120));

        activity.setCreator(user);
        activity.setCreatedDate(new Date());
        this.save(activity);
    } catch (Exception e) {
        log.warn("Activity log failed for user update status", e);
    }
}

From source file:nc.noumea.mairie.organigramme.viewmodel.EditEntiteDtoViewModel.java

/**
 * Cre une feuille unitaire/*  w w w. j  a  va  2  s  .  co m*/
 * 
 * @param ul
 *            : le {@link Ul} parent
 * @param node
 *            : le node de la FDP
 * @return le composant {@link Li} reprsentant l'entit
 */
public Li creeLiEntite(Ul ul, final FichePosteTreeNodeDto node) {

    Li li = new Li();
    String numFichePoste = OrganigrammeUtil.splitByNumberAndSeparator(node.getNumero(), 8, "\n");

    Div divNumFichePoste = new Div();
    divNumFichePoste.appendChild(new Label(numFichePoste));

    // #17877 les FDP gele
    if (null != node.getIdStatutFDP() && node.getIdStatutFDP().equals(EnumStatutFichePoste.GELEE.getStatut())) {

        Label labelGelee = new Label(" GELEE");
        labelGelee.setStyle("font-weight: bold; color:red;");
        divNumFichePoste.appendChild(labelGelee);
    }

    li.appendChild(divNumFichePoste);
    Div divTitreFichePoste = new Div();

    // #18575 Si le titre de la FDP est trop long, alors pour ne pas que a
    // sorte de la case, on raccourcis le nom de l'agent
    String suffixeSigleSiEnfant = CollectionUtils.isEmpty(node.getFichePostesEnfant()) ? ""
            : " (" + node.sigle + ")";

    String libelleTitreEtSigle = node.getTitre() + suffixeSigleSiEnfant;
    String libelleAgent = node.getAgent();

    String libelleAgentAbbreviate = libelleTitreEtSigle.length() > 50 ? StringUtils.abbreviate(libelleAgent, 27)
            : libelleAgent;
    String libelleTitreEtSigleAbbreviate = StringUtils.abbreviate(libelleTitreEtSigle, 80);

    divTitreFichePoste.appendChild(new Label(libelleTitreEtSigleAbbreviate));

    li.appendChild(divTitreFichePoste);
    if (isAfficheAgentFdp()) {
        Div divAgent = new Div();
        divAgent.appendChild(new Label(libelleAgentAbbreviate));
        li.appendChild(divAgent);
    }
    li.setParent(ul);

    // #28374 : la demande serait d'avoir le chef d'entit de la mme
    // couleur que l'entit
    // retourne l entite seulement si la fiche de poste est la superieure
    // hierarchique de ce service
    CouleurTypeEntite couleurTypeEntite = null;
    if (!node.getServiceAffichageExportYed().equals("")) {
        EntiteDto entitePourFichePosteChef = EntityUtils.getBackgroundColorOfFichePoste(node, entity,
                mapFichesPosteSuperieureByService);
        if (null != entitePourFichePosteChef) {
            couleurTypeEntite = couleurTypeEntiteService
                    .findByIdTypeEntite(entitePourFichePosteChef.getTypeEntite().getId());
            if (couleurTypeEntite != null) {
                entitePourFichePosteChef.getTypeEntite().setCouleurEntite(couleurTypeEntite.getCouleurEntite());
                entitePourFichePosteChef.getTypeEntite().setCouleurTexte(couleurTypeEntite.getCouleurTexte());
            }
        }
    }

    // #28374 : la demande serait d'avoir le chef d'entit de la mme
    // couleur que l'entit
    // CouleurTypeEntite couleurTypeEntite = null;
    // if(!node.getServiceAffichageExportYed().equals("")
    // && null != node.getIdServiceADS()) {
    // try {
    // couleurTypeEntite =
    // couleurTypeEntiteService.findByIdTypeEntite(EntityUtils.getEntiteByIdServiceAds(
    // node.getIdServiceADS(), entity).getTypeEntite().getId());
    // } catch(Exception e) {
    // couleurTypeEntite = null;
    // }
    // }

    // #17875 Affichage en rouge des FDP non rglementaires
    if (null != node.getReglementaire() && "Non".equals(node.getReglementaire().trim())) {
        li.setStyle("background-color:red; color:white;");
    } else if (null != couleurTypeEntite) {
        // #28374 : la demande serait d'avoir le chef d'entit de la mme
        // couleur que l'entit
        li.setStyle("background-color:" + couleurTypeEntite.getCouleurEntite() + "; color: "
                + couleurTypeEntite.getCouleurTexte() + ";");
    } else {
        li.setStyle("background-color:#FFFFCF; color:#000000;");
    }

    li.setSclass("statut-" + StringUtils.lowerCase(node.getStatutCss()) + " fichePoste");

    li.setId(node.getIdLi());
    li.setDynamicProperty("title", creeTooltipEntite(node, libelleTitreEtSigle, libelleAgent));

    // On maintient une map permettant d'aller plus vite lors d'un click
    // event pour retrouver FichePosteTreeNodeDto correspondant  l'id du Li
    mapIdLiFichePosteTreeNodeDto.put(li.getId(), node);

    return li;
}

From source file:com.edgenius.wiki.gwt.server.PageControllerImpl.java

public PageItemListModel getUserPagesInSpace(String spaceUname, String username, int returnNum) {

    PageItemListModel model = new PageItemListModel();
    User viewer = WikiUtil.getUser(userReadingService);
    List<Page> pages;//  w  ww  .  ja v  a  2s . co  m
    if (StringUtils.isBlank(spaceUname)) {
        pages = pageService.getUserAllContributedPages(username, returnNum, viewer);
    } else {
        pages = pageService.getUserUpdatedPagesInSpace(spaceUname, username, returnNum, viewer);
    }
    model.itemList = copyPageItem(pages);
    User user = userReadingService.getUserByName(username);
    if (user != null) {
        model.userStatus = StringUtils.abbreviate(user.getSetting().getStatus(), 50);
        model.userPortrait = UserUtil.getPortraitUrl(user.getPortrait());
        if (user.isAnonymous() || user.equals(WikiUtil.getUser()) || WikiUtil.getUser().isAnonymous()) {
            model.isFollowing = -1;
        } else {
            model.isFollowing = userReadingService.isFollowing(WikiUtil.getUser(), user) ? 1 : 0;
        }
    }

    return model;
}

From source file:com.alibaba.wasp.zookeeper.ZKUtil.java

private static void logRetrievedMsg(final ZooKeeperWatcher zkw, final String znode, final byte[] data,
        final boolean watcherSet) {
    if (!LOG.isDebugEnabled())
        return;//www.j av  a2 s.c om
    LOG.debug(zkw.prefix("Retrieved " + ((data == null) ? 0 : data.length) + " byte(s) of data from znode "
            + znode + (watcherSet ? " and set watcher; " : "; data=")
            + (data == null ? "null"
                    : data.length == 0 ? "empty"
                            : (znode.startsWith(zkw.assignmentZNode) ? ZKAssign.toString(data) : // We should not be doing this
                            // reaching into another class
                                    znode.startsWith(zkw.backupMasterAddressesZNode)
                                            ? getServerNameOrEmptyString(data)
                                            : StringUtils.abbreviate(Bytes.toStringBinary(data), 32)))));
}

From source file:net.sf.zekr.ui.QuranFormMenuFactory.java

private String getAudioDataText(AudioData audioData) {
    String name = audioData.getLocalizedName();
    return StringUtils.abbreviate(name, GlobalConfig.MAX_MENU_STRING_LENGTH) + "\t" + audioData.quality + " ("
            + lang.getMeaning("ONLINE".equalsIgnoreCase(audioData.type) ? "ONLINE" : "OFFLINE") + ")"
            + (rtl ? I18N.LRM + "" : "");
}

From source file:net.sf.zekr.ui.QuranForm.java

public MenuItem addNewScopeMenuItem(Menu parentMenu, SearchScope scope) {
    final MenuItem item = new MenuItem(parentMenu, SWT.RADIO);
    String s = scope.toString();/*w  w w . j a v a2  s .c  om*/
    item.setText(StringUtils.abbreviate(s, GlobalConfig.MAX_MENU_STRING_LENGTH));
    item.setData(scope);
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (((MenuItem) e.getSource()).getSelection()) {
                setSearchScope((SearchScope) item.getData());
            }
        }
    });
    return item;
}

From source file:net.sourceforge.subsonic.ajax.NowPlayingService.java

private List<NowPlayingInfo> convert(List<TransferStatus> statuses) throws Exception {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    String url = request.getRequestURL().toString();
    List<NowPlayingInfo> result = new ArrayList<NowPlayingInfo>();
    for (TransferStatus status : statuses) {

        Player player = status.getPlayer();
        File file = status.getFile();

        if (player != null && player.getUsername() != null && file != null) {

            String username = player.getUsername();
            UserSettings userSettings = settingsService.getUserSettings(username);
            if (!userSettings.isNowPlayingAllowed()) {
                continue;
            }//from   w  w w.  j a v  a  2s  . com

            MediaFile mediaFile = mediaFileService.getMediaFile(file);
            File coverArt = mediaFileService.getCoverArt(mediaFile);

            String artist = mediaFile.getArtist();
            String title = mediaFile.getTitle();
            String streamUrl = url.replaceFirst("/dwr/.*", "/stream?player=" + player.getId() + "&pathUtf8Hex="
                    + StringUtil.utf8HexEncode(file.getPath()));
            String albumUrl = url.replaceFirst("/dwr/.*",
                    "/main.view?pathUtf8Hex=" + StringUtil.utf8HexEncode(mediaFile.getParentPath()));
            String lyricsUrl = url.replaceFirst("/dwr/.*", "/lyrics.view?artistUtf8Hex="
                    + StringUtil.utf8HexEncode(artist) + "&songUtf8Hex=" + StringUtil.utf8HexEncode(title));
            String coverArtUrl = coverArt == null ? null
                    : url.replaceFirst("/dwr/.*", "/coverArt.view?size=48&pathUtf8Hex="
                            + StringUtil.utf8HexEncode(coverArt.getPath()));
            String coverArtZoomUrl = coverArt == null ? null
                    : url.replaceFirst("/dwr/.*",
                            "/coverArt.view?pathUtf8Hex=" + StringUtil.utf8HexEncode(coverArt.getPath()));

            String avatarUrl = null;
            if (userSettings.getAvatarScheme() == AvatarScheme.SYSTEM) {
                avatarUrl = url.replaceFirst("/dwr/.*", "/avatar.view?id=" + userSettings.getSystemAvatarId());
            } else if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM
                    && settingsService.getCustomAvatar(username) != null) {
                avatarUrl = url.replaceFirst("/dwr/.*", "/avatar.view?username=" + username);
            }

            // Rewrite URLs in case we're behind a proxy.
            if (settingsService.isRewriteUrlEnabled()) {
                String referer = request.getHeader("referer");
                streamUrl = StringUtil.rewriteUrl(streamUrl, referer);
                albumUrl = StringUtil.rewriteUrl(albumUrl, referer);
                lyricsUrl = StringUtil.rewriteUrl(lyricsUrl, referer);
                coverArtUrl = StringUtil.rewriteUrl(coverArtUrl, referer);
                coverArtZoomUrl = StringUtil.rewriteUrl(coverArtZoomUrl, referer);
                avatarUrl = StringUtil.rewriteUrl(avatarUrl, referer);
            }

            String tooltip = StringUtil.toHtml(artist) + " &ndash; " + StringUtil.toHtml(title);

            if (StringUtils.isNotBlank(player.getName())) {
                username += "@" + player.getName();
            }
            artist = StringUtil.toHtml(StringUtils.abbreviate(artist, 25));
            title = StringUtil.toHtml(StringUtils.abbreviate(title, 25));
            username = StringUtil.toHtml(StringUtils.abbreviate(username, 25));

            long minutesAgo = status.getMillisSinceLastUpdate() / 1000L / 60L;
            if (minutesAgo < 60) {
                result.add(new NowPlayingInfo(username, artist, title, tooltip, streamUrl, albumUrl, lyricsUrl,
                        coverArtUrl, coverArtZoomUrl, avatarUrl, (int) minutesAgo));
            }
        }
    }

    return result;

}

From source file:ninja.text.TextImpl.java

@Override
public Text abbreviate(int maxWidth) {
    return Text.of(StringUtils.abbreviate(data.toString(), maxWidth));
}

From source file:onl.netfishers.netshot.compliance.CheckResult.java

/**
 * Sets the comment.// w  ww  .ja  v  a  2s  .  com
 *
 * @param comment the new comment
 */
public void setComment(String comment) {
    this.comment = StringUtils.abbreviate(comment, 255);
}

From source file:org.apache.accumulo.monitor.rest.logs.LogResource.java

/**
 * Generates log event list as a JSON object
 *
 * @return log event array/*w  w w  .j a v  a  2  s. c o  m*/
 */
@GET
public List<LogEvent> getRecentLogs() {
    List<DedupedLogEvent> dedupedLogEvents = LogService.getInstance().getEvents();
    ArrayList<LogEvent> logEvents = new ArrayList<>(dedupedLogEvents.size());

    for (DedupedLogEvent dev : dedupedLogEvents) {
        LoggingEvent ev = dev.getEvent();
        Object application = ev.getMDC("application");
        if (application == null)
            application = "";
        String msg = ev.getMessage().toString();
        // truncate if full hadoop errors get logged as a message
        msg = StringUtils.abbreviate(sanitize(msg), 300);

        String[] stacktrace = ev.getThrowableStrRep();
        if (stacktrace != null)
            for (int i = 0; i < stacktrace.length; i++)
                stacktrace[i] = sanitize(stacktrace[i]);

        // Add a new log event to the list
        logEvents.add(new LogEvent(ev.getTimeStamp(), application, dev.getCount(), ev.getLevel().toString(),
                msg.trim(), stacktrace));
    }
    return logEvents;
}