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:net.gtaun.wl.race.dialog.TrackDialog.java

public static WlListDialog create(Player player, EventManager eventManager, AbstractDialog parent,
        RaceServiceImpl service, Track track) {
    PlayerStringSet stringSet = service.getLocalizedStringSet().getStringSet(player);
    RacingManagerImpl racingManager = service.getRacingManager();

    return WlListDialog.create(player, eventManager).parentDialog(parent)
            .caption(() -> stringSet.format("Dialog.TrackDialog.Caption", track.getName()))

            .item(() -> stringSet.format("Dialog.TrackDialog.Name", track.getName()),
                    (i) -> i.getCurrentDialog().show())
            .item(() -> stringSet.format("Dialog.TrackDialog.Author", track.getAuthorUniqueId()),
                    (i) -> i.getCurrentDialog().show())

            .item(() -> {/*from ww  w.  j a  va  2  s . c  o m*/
                String desc = track.getDesc();
                if (StringUtils.isBlank(desc))
                    desc = stringSet.get("Common.Empty");
                return stringSet.format("Dialog.TrackDialog.Desc", StringUtils.abbreviate(desc, 60));
            }, (i) -> {
                i.getCurrentDialog().show();
            })

            .item(() -> stringSet.format("Dialog.TrackDialog.Status", track.getStatus()),
                    (i) -> i.getCurrentDialog().show())
            .item(() -> stringSet.format("Dialog.TrackDialog.Checkpoints", track.getCheckpoints().size()),
                    (i) -> i.getCurrentDialog().show())
            .item(() -> stringSet.format("Dialog.TrackDialog.Length", track.getLength() / 1000.0f),
                    (i) -> i.getCurrentDialog().show())
            .item(() -> stringSet.format("Dialog.TrackDialog.Distance",
                    player.getLocation().distance(track.getStartLocation())),
                    (i) -> i.getCurrentDialog().show())

            .item(() -> stringSet.get("Dialog.TrackDialog.Edit"), () -> {
                if (track.getStatus() == TrackStatus.RANKING)
                    return false;
                if (player.isAdmin())
                    return true;
                return player.getName().equalsIgnoreCase(track.getAuthorUniqueId());
            }, (i) -> {
                if (track.getStatus() == TrackStatus.COMPLETED) {
                    String caption = stringSet.get("Dialog.TrackEditConfirmDialog.Caption");
                    String text = stringSet.format("Dialog.TrackEditConfirmDialog.Text", track.getName());

                    MsgboxDialog.create(player, eventManager).parentDialog(i.getCurrentDialog())
                            .caption(caption).message(text).onClickOk((d) -> {
                                player.playSound(1083);
                                service.editTrack(player, track);
                            }).build().show();
                } else if (track.getStatus() == TrackStatus.RANKING) {
                    i.getCurrentDialog().show();
                } else {
                    service.editTrack(player, track);
                }
            })

            .item(() -> stringSet.get("Dialog.TrackDialog.Test"), () -> {
                if (track.getCheckpoints().isEmpty())
                    return false;
                return track.getStatus() == TrackStatus.EDITING;
            }, (i) -> {
                Runnable startNewRacing = () -> {
                    Racing racing = racingManager.createRacing(track, player,
                            RacingUtils.getDefaultName(player, track));
                    racing.teleToStartingPoint(player);
                    racing.beginCountdown();
                };

                List<TrackCheckpoint> checkpoints = track.getCheckpoints();
                if (checkpoints.isEmpty())
                    return;

                if (racingManager.isPlayerInRacing(player)) {
                    Racing racing = racingManager.getPlayerRacing(player);
                    NewRacingConfirmDialog
                            .create(player, eventManager, i.getCurrentDialog(), service, racing, () -> {
                                startNewRacing.run();
                            }).show();
                } else
                    startNewRacing.run();
            })

            .item(() -> stringSet.get("Dialog.TrackDialog.NewRacing"), () -> {
                if (track.getCheckpoints().isEmpty())
                    return false;
                return track.getStatus() != TrackStatus.EDITING;
            }, (i) -> {
                NewRacingDialog.create(player, eventManager, i.getCurrentDialog(), service, track).show();
            })

            .item(() -> stringSet.get("Dialog.TrackDialog.QuickNewRacing"), () -> {
                if (track.getCheckpoints().isEmpty())
                    return false;
                return track.getStatus() != TrackStatus.EDITING;
            }, (i) -> {
                Runnable startNewRacing = () -> {
                    Racing racing = racingManager.createRacing(track, player,
                            RacingUtils.getDefaultName(player, track));
                    racing.teleToStartingPoint(player);
                };

                if (racingManager.isPlayerInRacing(player)) {
                    Racing racing = racingManager.getPlayerRacing(player);
                    String caption = stringSet.get("Dialog.TrackNewRacingConfirmDialog.Caption");
                    String text = stringSet.format("Dialog.TrackNewRacingConfirmDialog.Text", racing.getName());

                    WlMsgboxDialog.create(player, eventManager).parentDialog(parent).caption(caption)
                            .message(text).onClickOk((d) -> {
                                player.playSound(1083);
                                racing.leave(player);
                                startNewRacing.run();
                            }).build().show();
                } else
                    startNewRacing.run();
            })

            .onClickOk((d, i) -> player.playSound(1083)).build();
}

From source file:com.thinkgem.jeesite.modules.sys.interceptor.GlobalInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    String uri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.ADMIN_PATH;
    // ??POST//w ww .  jav  a2 s  .  c o m
    if ("POST".equals(request.getMethod()) && uri.length() > uriPrefix.length()) {
        User user = UserUtils.getUser();
        if (user != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("url: (" + request.getMethod() + ") " + uri);
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                sb.append((index++ == 0 ? "?" : "&") + param + "=");
                sb.append(StringUtils.abbreviate(request.getParameter((String) param), 100));
            }
            sb.append("; userId: " + user.getId());
            sb.append("; userName: " + user.getName());
            sb.append("; loginName: " + user.getLoginName());
            sb.append("; ipAddr: " + request.getLocalAddr());
            sb.append("; datetime: " + DateUtils.getDateTime());
            sb.append("; handler: " + handler.toString());
            logger.info(sb.toString());
        }
    }
}

From source file:com.twinsoft.convertigo.beans.statements.LogStatement.java

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

From source file:com.github.mike10004.stormpathacctmgr.NewPasswordFormServlet.java

/**
 * Handles the HTTP {@code GET} method. Gets the password reset token 
 * parameter value from the request query string and forwards to 
 * a JSP page for rendering.// ww w  .  j  a va  2  s . c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ResourceException {
    boolean tokenVerified = false;
    String token = request.getParameter(PasswordReset.PARAM_RESET_TOKEN);
    if (token != null && !token.isEmpty()) {
        checkNotNullAndNotEmpty(token, "token");
        Stormpaths stormpaths = createStormpaths();
        Application application = stormpaths.buildApplication();
        Account account;
        try {
            account = application.verifyPasswordResetToken(token);
            tokenVerified = true;
            log.log(Level.INFO, "verified token {0} and got account {1}",
                    new Object[] { StringUtils.abbreviate(token, 32), account.getEmail() });
            request.setAttribute(ATTR_TARGET_EMAIL, account.getEmail());
        } catch (ResourceException e) {
            log.log(Level.INFO, "verifyPasswordResetToken failed: {0}", (Object) e);
        }
    } else {
        log.info("'sptoken' query parameter is empty or not present");
    }
    request.setAttribute(ATTR_TOKEN_VERIFIED, tokenVerified);
    RequestDispatcher dispatcher = request.getRequestDispatcher(RESET_ENTER_NEW_PASSWORD_JSP_PATH);
    dispatcher.forward(request, response);
}

From source file:com.sonicle.webtop.calendar.TplHelper.java

private static String buildEventTitle(Locale locale, String dateFormat, String timeFormat,
        EventFootprint event) {/*from w  w  w.j  ava  2  s  .c  o m*/
    DateTimeZone etz = DateTimeZone.forID(event.getTimezone());
    DateTimeFormatter fmt = DateTimeUtils.createFormatter(dateFormat + " " + timeFormat, etz);
    StringBuilder sb = new StringBuilder();

    sb.append(StringUtils.abbreviate(event.getTitle(), 30));
    sb.append(" @");

    if (!StringUtils.isEmpty(event.getRecurrenceRule())) {
        RRuleStringify.Strings strings = WT.getRRuleStringifyStrings(locale);
        RRuleStringify rrs = new RRuleStringify(strings, etz);
        sb.append(" (");
        sb.append(rrs.toHumanReadableFrequencyQuietly(event.getRecurrenceRule()));
        sb.append(")");
    }

    //TODO: solo l'orario se date coincidono!!!
    sb.append(" ");
    sb.append(fmt.print(event.getStartDate()));
    sb.append(" - ");
    sb.append(fmt.print(event.getEndDate()));

    return sb.toString();
}

From source file:com.l2jfree.sql.L2DBEntity.java

public String toString(int maxWidth) {
    return StringUtils.abbreviate(toString(), maxWidth);
}

From source file:com.twinsoft.convertigo.beans.statements.WaitTriggerStatement.java

@Override
public String toString() {
    String msg = "Wait " + trigger.toString();
    return StringUtils.abbreviate(msg, 30);
}

From source file:fi.foyt.fni.view.forge.AbstractForgePublicViewBackingBean.java

protected PublicMaterialBean toMaterialBean(fi.foyt.fni.persistence.model.materials.Material material) {
    if (material == null) {
        return null;
    }//  w  w w  .  j  av a  2 s. c  o m

    String icon = materialController.getMaterialIcon(material.getType());
    String license = material.getLicense();
    CreativeCommonsLicense commonsLicence = CreativeCommonsUtils.parseLicenseUrl(license);
    String creatorName = material.getCreator().getFullName();
    String modifierName = material.getModifier().getFullName();
    List<MaterialTag> materialTags = materialController.listMaterialTags(material);
    List<String> tags = new ArrayList<>(materialTags.size());

    for (MaterialTag materialTag : materialTags) {
        tags.add(materialTag.getTag().getText());
    }

    String viewPath = String.format("/materials/%s", material.getPath());
    String editPath = materialController.getForgeMaterialViewerUrl(material);
    String downloadLink = String.format("/materials/%s?download=true", material.getPath());
    String path = material.getPath();
    String parentPath = material.getParentFolder() != null
            ? materialController.getForgeMaterialViewerUrl(material.getParentFolder())
            : "/forge/";

    String description = material.getDescription();
    if (StringUtils.isBlank(description) && (material instanceof Document)) {
        description = StringUtils.abbreviate(((Document) material).getContentPlain(), 250);
    }

    Boolean viewable;
    switch (material.getType()) {
    case DOCUMENT:
    case IMAGE:
    case PDF:
    case VECTOR_IMAGE:
        viewable = true;
        break;
    default:
        viewable = false;
        break;
    }

    Boolean printable = materialController.isPrintableAsPdfType(material.getType());

    return new PublicMaterialBean(material.getId(), material.getTitle(), description, icon, license,
            commonsLicence != null ? commonsLicence.getIconUrl(true) : null, material.getCreator().getId(),
            creatorName, material.getCreated(), material.getModifier().getId(), modifierName,
            material.getModified(), tags, viewPath, editPath, downloadLink, parentPath, path, viewable,
            printable);
}

From source file:gov.nih.nci.caintegrator.common.Cai2Util.java

/**
 * @param statusDescription the string to trim
 * @return trimmed string if too long, or full string if it isn't too long.
 *//*from   w  w  w .java  2s .com*/
public static String trimDescription(String statusDescription) {
    return StringUtils.abbreviate(statusDescription, MAX_DESCRIPTION_LENGTH);
}

From source file:com.evolveum.midpoint.model.impl.dataModel.dot.DotMappingRelation.java

@Nullable
private String getLabel(String defaultLabel, boolean showConstant) {
    ExpressionType expression = getMapping().getExpression();
    if (expression == null || expression.getExpressionEvaluator().isEmpty()) {
        return defaultLabel;
    }// w w w  .  j  a  va2 s.c om
    if (expression.getExpressionEvaluator().size() > 1) {
        return "> 1 evaluator"; // TODO multivalues
    }
    JAXBElement<?> evalElement = expression.getExpressionEvaluator().get(0);
    Object eval = evalElement.getValue();
    if (QNameUtil.match(evalElement.getName(), SchemaConstants.C_VALUE)) {
        if (showConstant) {
            String str = getStringConstant(eval);
            return "\'" + StringUtils.abbreviate(str, MAX_CONSTANT_WIDTH) + "\'";
        } else {
            return "constant";
        }
    } else if (eval instanceof AsIsExpressionEvaluatorType) {
        return defaultLabel;
    } else if (eval instanceof ScriptExpressionEvaluatorType) {
        ScriptExpressionEvaluatorType script = (ScriptExpressionEvaluatorType) eval;
        if (script.getLanguage() == null) {
            return "groovy";
        } else {
            return StringUtils.substringAfter(script.getLanguage(), "#");
        }
    } else {
        return evalElement.getName().getLocalPart();
    }
}