Example usage for org.apache.commons.lang StringUtils isNumeric

List of usage examples for org.apache.commons.lang StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isNumeric.

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:com.greenline.guahao.biz.manager.orderremind.impl.OrderRemindManagerImpl.java

@Override
public OrderRemindDO findOrderRemindCount(LocalResponseDO<Object> lrd, UserDO user) {
    String logObj = "????";
    String error = null;/*  www .  ja v a  2  s . c  o m*/
    OrderRemindDO remind = new OrderRemindDO();
    CheckResponse resp = null;
    UserInfoRequestDTO request = new UserInfoRequestDTO();
    if (null != user) {
        request.setiDNo(user.getCertNo());
        request.setUserName(user.getUserName());
        request.setPartnerId(user.getPartnerId());
        request.setServerType("1"); // 
    }
    try {
        if (lrd.isSuccess()) {
            logger.info(String.format("%s?[userAuthenticationService.checkUserService]?:%s",
                    logObj, jackJson.writeString(request)));
            resp = userAuthenticationService.checkUserService(request);
            if (null != resp) {
                logger.info(
                        String.format("%s?[userAuthenticationService.checkUserService]:%s",
                                logObj, jackJson.writeString(resp)));
                if (resp.getIsSucess()) {
                    List<ServiceDTO> list = resp.getServiceList();
                    if (null != list && list.size() > 0) {
                        int total = 0; // 
                        int residue = 0; // 
                        for (ServiceDTO s : list) {
                            if (null != s) {
                                if (StringUtils.isNotBlank(s.getTotalCount())
                                        && StringUtils.isNumeric(s.getTotalCount())) {
                                    total += new Integer(s.getTotalCount());
                                }
                                if (StringUtils.isNotBlank(s.getValidCount())
                                        && StringUtils.isNumeric(s.getValidCount())) {
                                    residue += new Integer(s.getValidCount());
                                }
                            }
                        }
                        remind.setTotalCount(total);
                        if (null != resp.getInserviceCount()) {
                            remind.setUsingCount(resp.getInserviceCount());
                            residue -= resp.getInserviceCount(); // ?
                        }
                        if (residue < 0) {
                            logger.warn(String.format(
                                    "[%s]????0",
                                    jackJson.writeString(user)));
                            residue = 0;
                        }
                        remind.setResidueCount(residue);
                        remind.setUsedCount(total - residue);
                    }
                } else {
                    lrd.setResult(LocalResponseCode.REMOTE_ERROR, resp.getErrorsInfo(), String.format(
                            "%s?[userAuthenticationService.checkUserService]?%s",
                            logObj, resp.getErrorsInfo()));
                }
            } else {
                lrd.setResult(LocalResponseCode.REMOTE_EXCEPTION, "?", String
                        .format("%s?[userAuthenticationService.checkUserService]null", logObj));
            }
        }
        if (!lrd.isSuccess()) {
            logger.error(lrd.getProfessionalInfo());
        }
    } catch (Exception e) {
        error = String.format("%S%s", logObj, e.getMessage());
        logger.error(error, e);
        lrd.setResult(LocalResponseCode.REMOTE_CALL_EXCEPTION, String.format("%S", logObj), error);
    }
    return remind;
}

From source file:com.glaf.core.db.DataServiceBean.java

/**
 * ????/*from   w  w w  .j a v  a2 s . c  o  m*/
 * 
 * @param sysData
 *            ?
 * @param loginContext
 *            
 * @param ipAddress
 *            IP?
 */
public void checkPermission(SysData sysData, LoginContext loginContext, String ipAddress) {
    boolean hasPermission = false;
    /**
     * ??????
     */
    if (!StringUtils.equals(sysData.getAccessType(), "PUB")) {
        /**
         * IP???
         */
        if (StringUtils.isNotEmpty(sysData.getAddressPerms())) {
            List<String> addressList = StringTools.split(sysData.getAddressPerms());
            for (String addr : addressList) {
                if (StringUtils.equals(ipAddress, addr)) {
                    hasPermission = true;
                }
                if (StringUtils.equals(ipAddress, "127.0.0.1")) {
                    hasPermission = true;
                }
                if (StringUtils.equals(ipAddress, "localhost")) {
                    hasPermission = true;
                }
                if (addr.endsWith("*")) {
                    String tmp = addr.substring(0, addr.indexOf("*"));
                    if (StringUtils.contains(ipAddress, tmp)) {
                        hasPermission = true;
                    }
                }
            }
            if (!hasPermission) {
                throw new RuntimeException("Permission denied.");
            }
        }

        /**
         * ???
         */
        if (StringUtils.isNotEmpty(sysData.getPerms())
                && !StringUtils.equalsIgnoreCase(sysData.getPerms(), "anyone")) {
            if (loginContext.hasSystemPermission() || loginContext.hasAdvancedPermission()) {
                hasPermission = true;
            }
            List<String> permissions = StringTools.split(sysData.getPerms());
            for (String perm : permissions) {
                if (loginContext.getPermissions().contains(perm)) {
                    hasPermission = true;
                }
                if (loginContext.getRoles().contains(perm)) {
                    hasPermission = true;
                }
                if (StringUtils.isNotEmpty(perm) && StringUtils.isNumeric(perm)) {
                    if (loginContext.getRoleIds().contains(Long.parseLong(perm))) {
                        hasPermission = true;
                    }
                }
            }
            if (!hasPermission) {
                throw new RuntimeException("Permission denied.");
            }
        }
    }
}

From source file:morphy.user.Formula.java

public boolean matches(NewMatchParams params) {
    String[][] patternfixes = {//  w w w.  j a v a2  s . c  o m
            /*{"\\s+",""},
            {"(\\s+and\\s+)"," && "}, 
            {"(\\s+&\\s+)"," && "},
            {"(\\s+\\|\\s+)"," || "},
            {"(\\s+or\\s+)"," || "}*/
            { "\\s+", "" }, { "&", " && " }, { "and", " && " }, { "\\s*?\\|\\s*?", " || " }, { "or", " || " } };
    String tmpformula = formula.toLowerCase();

    for (int i = 0; i < patternfixes.length; i++) {
        tmpformula = tmpformula.replaceAll(patternfixes[i][0], patternfixes[i][1]);
    }

    System.out.println(tmpformula);

    String[] operators = { ">=", "<=", ">", "<", "!=", "<>", "=" };

    int parenCount = 0;
    String[] arr = tmpformula.split(" ");
    System.out.println(java.util.Arrays.toString(arr));
    for (int i = 0; i < arr.length; i++) {
        String s = arr[i];
        if (s.startsWith("("))
            parenCount++;
        for (int j = 0; j < operators.length; j++) {
            if (s.contains(operators[j])) {
                s = s.replace(operators[j], " " + operators[j] + " ");
                break;
            }
        }

        String[] tmp = s.split(" ");
        //System.out.println(java.util.Arrays.toString(tmp));

        if (StringUtils.isNumeric(tmp[0]) && tmp.length == 1) {
            //int k = Integer.parseInt(tmp[0]);
            //boolean b = k>0?true:false; 
        } else if (tmp.length == 3) {
            // this has to a variable comparison expression
            String variable = tmp[0].replace("(", "");
            String cmpoper = tmp[1];
            String value = tmp[2].replace(")", "");
            Key k = Key.valueOf(variable);
            System.out.println(
                    variable + " " + cmpoper + " " + value + ": " + cmp(params.getParam(k), cmpoper, value));
            s = "" + cmp(params.getParam(k), cmpoper, value);
        } else if (tmp.length == 1) {
            // this has be a boolean expression
        } else {
            System.out.println("invalid expression: " + s);
        }

        //s = s.replace("(","").replace(")","");
        arr[i] = s;
        if (s.endsWith(")"))
            parenCount--;
    }
    System.out.println(java.util.Arrays.toString(arr));

    //MorphyStringTokenizer tok = new MorphyStringTokenizer(this.formula,"", isEatingBlocksOfDelimiters)

    return false;
}

From source file:com.flexive.rest.FxRestApiUtils.java

/**
 * Apply common request parameters such as the requested language. Call this before <em>any</em> API call
 * as it processes security configuration and sets request context information that will be used later.
 *
 * <p>//from   w  ww.  j av a 2  s .c  o  m
 *     This method is called automatically on JAX-RS classes or methods annotated with {@link com.flexive.rest.interceptors.FxRestApi @FxRestApi}.
 * </p>
 */
public static void applyRequestParameters(HttpHeaders headers, UriInfo uriInfo) throws FxApplicationException {
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(true);

    if (!isRequestContextAvailable()) {
        // set context for the first request only, subsequent JAX-RS handler invocations in this request
        // should reuse the existing context
        FxContext.get().setAttribute(CTX_REQUEST, new RequestContext(headers, uriInfo));
    }

    // get access token
    String token = queryParameters.getFirst(FxRestApiConst.HEADER_TOKEN);
    if (token == null && headers.getRequestHeader(FxRestApiConst.HEADER_TOKEN) != null) {
        token = Iterables.getFirst(headers.getRequestHeader(FxRestApiConst.HEADER_TOKEN), null);
    }
    if (StringUtils.isNotBlank(token)) {
        EJBLookup.getAccountEngine().loginByRestToken(token);
    }
    if (FxContext.getUserTicket().isGuest() && !FxBasicFilter.isGuestAccessAllowed()) {
        throw new GuestAccessDisabledException();
    }

    final String lang = queryParameters.getFirst("lang");
    if (StringUtils.isNotBlank(lang)) {
        // override request user's language
        final FxLanguage overrideLang;
        if (StringUtils.isNumeric(lang)) {
            overrideLang = CacheAdmin.getEnvironment().getLanguage(Long.parseLong(lang));
        } else {
            overrideLang = CacheAdmin.getEnvironment().getLanguage(lang);
        }
        FxContext.getUserTicket().setLanguage(overrideLang);
    }
}

From source file:fr.paris.lutece.plugins.suggest.web.action.MassPinnedSuggestSubmitAction.java

/**
 * {@inheritDoc}// w ww  . ja  va2  s .  c om
 */
@Override
public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response,
        AdminUser adminUser, SuggestAdminSearchFields searchFields) throws AccessDeniedException {
    IPluginActionResult result = new DefaultPluginActionResult();

    int nIdSuggestSubmit;
    String strRedirect = SuggestJspBean.getJspManageSuggestSubmit(request);

    if ((searchFields.getSelectedSuggestSubmit() != null)
            && !searchFields.getSelectedSuggestSubmit().isEmpty()) {
        //test All ressource selected before update
        for (String strIdSuggestSubmit : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmit) && StringUtils.isNumeric(strIdSuggestSubmit)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmit);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());

                if ((suggestSubmit == null) || !RBACService.isAuthorized(Suggest.RESOURCE_TYPE,
                        SuggestUtils.EMPTY_STRING + suggestSubmit.getSuggest().getIdSuggest(),
                        SuggestResourceIdService.PERMISSION_MANAGE_SUGGEST_SUBMIT, adminUser)) {
                    throw new AccessDeniedException();
                }
            }
        }

        boolean isPinned = (request.getParameter(PARAMETER_MASS_PIN_ACTION) != null);

        //update all suggest submit selected
        for (String strIdSuggestSubmittoUpdate : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmittoUpdate)
                    && StringUtils.isNumeric(strIdSuggestSubmittoUpdate)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmittoUpdate);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());
                suggestSubmit.setPinned(isPinned);
                SuggestSubmitService.getService().update(suggestSubmit, getPlugin());
            }
        }

        //update manualy order of list suggest submit
        SuggestSubmitService.getService().updateSuggestSubmitOrder(null, null, searchFields.getIdSuggest(),
                true, getPlugin());
        SuggestSubmitService.getService().updateSuggestSubmitOrder(null, null, searchFields.getIdSuggest(),
                false, getPlugin());
    } else {
        strRedirect = AdminMessageService.getMessageUrl(request, MESSAGE_YOU_MUST_SELECT_SUGGEST_SUBMIT,
                AdminMessage.TYPE_INFO);
    }

    result.setRedirect(strRedirect);

    return result;
}

From source file:fr.paris.lutece.plugins.extend.modules.comment.web.CommentJspBean.java

/**
 * Do publish unpublish comment./*  w w w.  java  2s .c  o m*/
 * 
 * @param request the request
 * @return the string
 */
public String doPublishUnpublishComment(HttpServletRequest request) {
    String strIdComment = request.getParameter(CommentConstants.PARAMETER_ID_COMMENT);

    if (StringUtils.isNotBlank(strIdComment) && StringUtils.isNumeric(strIdComment)) {
        int nIdComment = Integer.parseInt(strIdComment);
        Comment comment = _commentService.findByPrimaryKey(nIdComment);

        if (comment != null) {
            try {
                _commentService.updateCommentStatus(comment.getIdComment(), !comment.isPublished());
            } catch (Exception ex) {
                // Something wrong happened... a database check might be needed
                AppLogService.error(ex.getMessage() + " when updating a comment", ex);

                return AdminMessageService.getMessageUrl(request,
                        CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR);
            }

            String strPostBackUrl = (String) request.getSession().getAttribute(
                    CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL);
            request.getSession().setAttribute(
                    CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL, null);
            if (StringUtils.isEmpty(strPostBackUrl)) {
                strPostBackUrl = JSP_VIEW_EXTENDER_INFO;
            }
            UrlItem url = new UrlItem(strPostBackUrl);
            url.addParameter(CommentConstants.PARAMETER_EXTENDER_TYPE,
                    CommentResourceExtender.EXTENDER_TYPE_COMMENT);
            url.addParameter(CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE,
                    comment.getIdExtendableResource());
            url.addParameter(CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE,
                    comment.getExtendableResourceType());
            if (comment.getIdParentComment() > 0) {
                url.addParameter(CommentConstants.PARAMETER_ID_COMMENT, comment.getIdParentComment());
            }
            url.addParameter(CommentConstants.PARAMETER_FROM_URL,
                    StringUtils.replace(request.getParameter(CommentConstants.PARAMETER_FROM_URL),
                            CommentConstants.CONSTANT_AND, CommentConstants.CONSTANT_AND_HTML));

            return url.getUrl();
        }
    }

    return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
}

From source file:fr.paris.lutece.plugins.suggest.web.action.MassChangeVoteSuggestSubmitAction.java

/**
 * {@inheritDoc}/*  w ww . ja  va  2  s  . c o  m*/
 */
@Override
public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response,
        AdminUser adminUser, SuggestAdminSearchFields searchFields) throws AccessDeniedException {
    IPluginActionResult result = new DefaultPluginActionResult();

    int nIdSuggestSubmit;
    String strRedirect = SuggestJspBean.getJspManageSuggestSubmit(request);

    if ((searchFields.getSelectedSuggestSubmit() != null)
            && !searchFields.getSelectedSuggestSubmit().isEmpty()) {
        //test All ressource selected before update
        for (String strIdSuggestSubmit : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmit) && StringUtils.isNumeric(strIdSuggestSubmit)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmit);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());

                if ((suggestSubmit == null) || !RBACService.isAuthorized(Suggest.RESOURCE_TYPE,
                        SuggestUtils.EMPTY_STRING + suggestSubmit.getSuggest().getIdSuggest(),
                        SuggestResourceIdService.PERMISSION_MANAGE_SUGGEST_SUBMIT, adminUser)) {
                    throw new AccessDeniedException();
                }
            }
        }

        boolean isDisabledVote = (request.getParameter(PARAMETER_MASS_DISABLE_ACTION) != null);

        //update all suggest submit selected
        for (String strIdSuggestSubmittoUpdate : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmittoUpdate)
                    && StringUtils.isNumeric(strIdSuggestSubmittoUpdate)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmittoUpdate);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());
                suggestSubmit.setDisableVote(isDisabledVote);
                SuggestSubmitService.getService().update(suggestSubmit, getPlugin());
            }
        }
    } else {
        strRedirect = AdminMessageService.getMessageUrl(request, MESSAGE_YOU_MUST_SELECT_SUGGEST_SUBMIT,
                AdminMessage.TYPE_INFO);
    }

    result.setRedirect(strRedirect);

    return result;
}

From source file:fr.paris.lutece.plugins.suggest.web.action.MassChangeCommentSuggestSubmitAction.java

/**
 * {@inheritDoc}/*from   w w  w .  ja v a  2s. co  m*/
 */
@Override
public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response,
        AdminUser adminUser, SuggestAdminSearchFields searchFields) throws AccessDeniedException {
    IPluginActionResult result = new DefaultPluginActionResult();

    int nIdSuggestSubmit;
    String strRedirect = SuggestJspBean.getJspManageSuggestSubmit(request);

    if ((searchFields.getSelectedSuggestSubmit() != null)
            && !searchFields.getSelectedSuggestSubmit().isEmpty()) {
        //test All ressource selected before update
        for (String strIdSuggestSubmit : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmit) && StringUtils.isNumeric(strIdSuggestSubmit)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmit);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());

                if ((suggestSubmit == null) || !RBACService.isAuthorized(Suggest.RESOURCE_TYPE,
                        SuggestUtils.EMPTY_STRING + suggestSubmit.getSuggest().getIdSuggest(),
                        SuggestResourceIdService.PERMISSION_MANAGE_SUGGEST_SUBMIT, adminUser)) {
                    throw new AccessDeniedException();
                }
            }
        }

        boolean isDisabledVote = (request.getParameter(PARAMETER_MASS_DISABLE_ACTION) != null);

        //update all suggest submit selected
        for (String strIdSuggestSubmittoUpdate : searchFields.getSelectedSuggestSubmit()) {
            if (StringUtils.isNotBlank(strIdSuggestSubmittoUpdate)
                    && StringUtils.isNumeric(strIdSuggestSubmittoUpdate)) {
                nIdSuggestSubmit = SuggestUtils.getIntegerParameter(strIdSuggestSubmittoUpdate);

                SuggestSubmit suggestSubmit = SuggestSubmitService.getService()
                        .findByPrimaryKey(nIdSuggestSubmit, false, getPlugin());
                suggestSubmit.setDisableComment(isDisabledVote);
                SuggestSubmitService.getService().update(suggestSubmit, getPlugin());
            }
        }
    } else {
        strRedirect = AdminMessageService.getMessageUrl(request, MESSAGE_YOU_MUST_SELECT_SUGGEST_SUBMIT,
                AdminMessage.TYPE_INFO);
    }

    result.setRedirect(strRedirect);

    return result;
}

From source file:de.cosmocode.commons.Strings.java

/**
 * Checks whether a given {@link String} is a valid
 * number, containing only digits.//from w  ww  . j  a  v  a2  s. co m
 * This implementation is performing a blank-check
 * before using {@link StringUtils#isNumeric(String)}.
 * 
 * <pre>
 * Strings.isNumeric(null)   = false
 * Strings.isNumeric("")     = false
 * Strings.isNumeric("  ")   = false
 * Strings.isNumeric("123")  = true
 * Strings.isNumeric("12 3") = false
 * Strings.isNumeric("ab2c") = false
 * Strings.isNumeric("12-3") = false
 * Strings.isNumeric("12.3") = false
 * </pre>
 * 
 * @param s the String to check, may be null
 * @return true if s is not blank and contains only digits
 */
public static boolean isNumeric(String s) {
    return StringUtils.isNotBlank(s) && StringUtils.isNumeric(s);
}

From source file:com.clican.pluto.common.support.spring.BeanPropertyRowMapper.java

/**
 * Convert a name in camelCase to an underscored name in lower case. Any
 * upper case letters are converted to lower case with a preceding
 * underscore./*  w w w  . j av  a 2 s  .com*/
 * 
 * @param name
 *            the string containing original name
 * @return the converted name
 */
private String underscoreName(String name) {
    StringBuffer result = new StringBuffer();
    if (name != null && name.length() > 0) {
        result.append(name.substring(0, 1).toLowerCase());
        boolean reset = false;
        for (int i = 1; i < name.length(); i++) {
            String s = name.substring(i, i + 1);
            if (s.equals(s.toUpperCase()) && !StringUtils.isNumeric(s)) {
                if (reset) {
                    reset = false;
                    result.append("_");
                    result.append(s.toLowerCase());
                } else {
                    result.append(s.toLowerCase());
                }
            } else {
                reset = true;
                result.append(s.toLowerCase());
            }
        }
    }
    return result.toString();
}