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

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

Introduction

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

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:mb.MbAdministrator.java

public void saveGameScore() {
    Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    if (!StringUtils.isNumeric(homeGoals) || !StringUtils.isNumeric(awayGoals)) {
        JsfUtil.addErrorMessage(ResourceBundle.getBundle("localization.messages", locale)
                .getString("AdministratorGameEdit_failureMessage"));
        return;/*www  .  ja  va 2 s. c  o m*/
    }
    selectedGame.setScore(homeGoals.trim() + ":" + awayGoals.trim());
    try {
        getEjbGame().edit(selectedGame);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("localization.messages", locale)
                .getString("AdministratorGameEdit_successMessage"));
    } catch (Exception e) {
        JsfUtil.addErrorMessage(ResourceBundle.getBundle("localization.messages", locale)
                .getString("AdministratorGameEdit_failureMessage"));
    }
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUser.java

public CompletableFuture<Long> getSteamIdFromVanityUrl(String urlPath, VanityUrlType type) {
    CompletableFuture<JsonObject> json = sendRequest(new ResolveVanityURL(VERSION_1, urlPath, type));
    return json.thenApply(root -> {
        JsonObject response = root.getAsJsonObject("response");
        int success = response.getAsJsonPrimitive("success").getAsInt();
        if (success == 1) {
            String steamId = response.getAsJsonPrimitive("steamid").getAsString();
            if (!StringUtils.isEmpty(steamId) && StringUtils.isNumeric(steamId)) {
                return Long.valueOf(steamId);
            }//from ww  w.j  av a2s .  c om
        }
        return null;
    });
}

From source file:com.glaf.base.modules.sys.springmvc.LoginController.java

/**
 * /*  www .  ja v  a2  s .  c  om*/
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping(params = "method=login")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    HttpSession session = request.getSession(false);
    if (session == null) {
        return new ModelAndView("/modules/login", modelMap);
    }

    if (StringUtils.isNotEmpty(request.getParameter("systemName"))) {
        Environment.setCurrentSystemName(request.getParameter("systemName"));
    } else {
        Environment.setCurrentSystemName(Environment.DEFAULT_SYSTEM_NAME);
    }

    ViewMessages messages = new ViewMessages();
    // ??
    String account = ParamUtil.getParameter(request, "x");
    String password = ParamUtil.getParameter(request, "y");

    String rand = (String) session.getAttribute("x_y");
    if (rand != null) {
        password = StringTools.replace(password, rand, "");
    }

    String rand2 = (String) session.getAttribute("x_z");
    if (rand2 != null) {
        password = StringTools.replace(password, rand2, "");
    }
    String pwd = password;
    try {
        pwd = DigestUtil.digestString(password, "MD5");
    } catch (Exception ex) {
    }

    logger.debug(account + " start login........................");

    // 
    SysUser bean = authorizeService.authorize(account, pwd);
    if (bean == null) {
        // ?
        messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure"));
        MessageUtils.addMessages(request, messages);
        return new ModelAndView("/modules/login", modelMap);
    }
    String ipAddr = RequestUtils.getIPAddress(request);
    SystemProperty p = SystemConfig.getProperty("login_limit");
    if (!(StringUtils.equals(ipAddr, "localhost") || StringUtils.equals(ipAddr, "127.0.0.1")
            || StringUtils.equals(account, "root") || StringUtils.equals(account, "admin"))) {

        SystemProperty pt = SystemConfig.getProperty("login_time_check");
        int timeoutSeconds = 300;

        if (pt != null && pt.getValue() != null && StringUtils.isNumeric(pt.getValue())) {
            timeoutSeconds = Integer.parseInt(pt.getValue());
        }
        if (timeoutSeconds < 300) {
            timeoutSeconds = 300;
        }
        if (timeoutSeconds > 3600) {
            timeoutSeconds = 3600;
        }

        /**
         * ???
         */
        if (p != null && StringUtils.equals(p.getValue(), "true")) {
            logger.debug("#################3#########################");
            String loginIP = null;
            UserOnline userOnline = userOnlineService.getUserOnline(account);
            logger.debug("userOnline:" + userOnline);
            boolean timeout = false;
            if (userOnline != null) {
                loginIP = userOnline.getLoginIP();
                if (userOnline.getCheckDateMs() != null
                        && System.currentTimeMillis() - userOnline.getCheckDateMs() > timeoutSeconds * 1000) {
                    timeout = true;// ?
                }
                if (userOnline.getLoginDate() != null && System.currentTimeMillis()
                        - userOnline.getLoginDate().getTime() > timeoutSeconds * 1000) {
                    timeout = true;// ?
                }
            }
            logger.info("login IP:" + loginIP);
            if (!timeout) {// ????
                if (loginIP != null && !(StringUtils.equals(ipAddr, loginIP))) {// 
                    messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure2"));
                    MessageUtils.addMessages(request, messages);
                    logger.debug("?");
                    return new ModelAndView("/modules/login", modelMap);
                }
            }
        }
    }

    Properties props = CallbackProperties.getProperties();
    if (props != null && props.keys().hasMoreElements()) {
        Enumeration<?> e = props.keys();
        while (e.hasMoreElements()) {
            String className = (String) e.nextElement();
            if (className.indexOf("parameter") >= 0) {
                continue;
            }
            try {
                Object obj = ClassUtils.instantiateObject(className);
                if (obj instanceof LoginCallback) {
                    LoginCallback callback = (LoginCallback) obj;
                    callback.afterLogin(bean.getAccount(), request, response);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                logger.error(ex);
            }
        }
    }

    if (bean.getLoginCount() != null) {
        bean.setLoginCount(bean.getLoginCount() + 1);
    } else {
        bean.setLoginCount(1);
    }
    // ?
    bean.setLastLoginDate(new Date());
    sysUserService.updateUser(bean);

    // String menus = sysApplicationService.getMenu(3, bean);
    // bean.setMenus(menus);
    // request.setAttribute(SysConstants.MENU, menus);

    ContextUtil.put(bean.getAccount(), bean);// ??

    RequestUtils.setLoginUser(request, response, "default", bean.getAccount());
    if (p != null && StringUtils.equals(p.getValue(), "true")) {
        try {
            UserOnline online = new UserOnline();
            online.setActorId(bean.getActorId());
            online.setName(bean.getName());
            online.setCheckDate(new Date());
            online.setLoginDate(new Date());
            online.setLoginIP(ipAddr);
            online.setSessionId(session.getId());
            userOnlineService.login(online);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }

    if (bean.getAccountType() == 1) {// 
        return new ModelAndView("/modules/sp_main", modelMap);
    } else if (bean.getAccountType() == 2) {// 
        return new ModelAndView("/modules/wx_main", modelMap);
    } else {
        return new ModelAndView("/modules/main", modelMap);
    }

}

From source file:file.BookmarkReader.java

private void processUserData(String userID, UserData userData, List<String> tags, List<String> categories,
        String wikiID) {//from  www . ja va 2  s.c o m
    if (userID != "" && tags.size() > 0/* && !userData.getTimestamp().isEmpty()*/) {
        if (!userData.getTimestamp().isEmpty() && !StringUtils.isNumeric(userData.getTimestamp())) {
            System.out.println("Invaled timestamp");
            return;
        }

        boolean doCount = (this.countLimit == 0 || this.userLines.size() < this.countLimit);
        //int userIndex = this.users.indexOf(userID);
        Integer userIndex = this.userMap.get(userID);
        if (userIndex == null) {
            this.users.add(userID);
            if (doCount) {
                this.userCounts.add(1);
            } else {
                this.userCounts.add(0);
            }
            userIndex = this.users.size() - 1;
            this.userMap.put(userID, userIndex);
        } else if (doCount) {
            this.userCounts.set(userIndex, this.userCounts.get(userIndex) + 1);
        }
        userData.setUserID(userIndex);
        //int resIndex = this.resources.indexOf(wikiID);
        Integer resIndex = this.resourceMap.get(wikiID);
        if (resIndex == null) {
            this.resources.add(wikiID);
            if (doCount) {
                this.resourceCounts.add(1);
            } else {
                this.resourceCounts.add(0);
            }
            resIndex = this.resources.size() - 1;
            this.resourceMap.put(wikiID, resIndex);
        } else if (doCount) {
            this.resourceCounts.set(resIndex, this.resourceCounts.get(resIndex) + 1);
        }
        userData.setWikiID(resIndex);

        for (String cat : categories) {
            int index = 0;
            if (!this.categories.contains(cat)) {
                this.categories.add(cat);
                index = this.categories.size() - 1;
            } else {
                index = this.categories.indexOf(cat);
            }
            userData.getCategories().add(index);
        }
        for (String tag : tags) {
            //int tagIndex = this.tags.indexOf(tag);
            Integer tagIndex = this.tagMap.get(tag);
            if (tagIndex == null) { // new tag
                this.tags.add(tag);
                if (doCount) {
                    this.tagCounts.add(1);
                } else {
                    this.tagCounts.add(0);
                }
                tagIndex = this.tags.size() - 1;
                this.tagMap.put(tag, tagIndex);
            } else if (doCount) {
                this.tagCounts.set(tagIndex, this.tagCounts.get(tagIndex) + 1);
            }
            userData.getTags().add(tagIndex);
        }
        this.userLines.add(userData);
        if (this.userLines.size() % 100000 == 0) {
            System.out.println("Read in 10000000 lines");
        }
    }
}

From source file:com.glaf.core.xml.XmlReader.java

protected void read(Element elem, ColumnDefinition field) {
    List<?> attrs = elem.attributes();
    if (attrs != null && !attrs.isEmpty()) {
        Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
        Iterator<?> iter = attrs.iterator();
        while (iter.hasNext()) {
            Attribute attr = (Attribute) iter.next();
            dataMap.put(attr.getName(), attr.getStringValue());
        }//from   ww  w .j  av  a 2s.  c  o  m
        Tools.populate(field, dataMap);
    }

    field.setName(elem.attributeValue("name"));
    field.setMask(elem.attributeValue("mask"));
    field.setTitle(elem.attributeValue("title"));
    field.setEnglishTitle(elem.attributeValue("englishTitle"));
    field.setType(elem.attributeValue("type"));
    field.setDataCode(elem.attributeValue("dataCode"));
    field.setRenderType(elem.attributeValue("renderType"));
    field.setColumnName(elem.attributeValue("column"));
    field.setDataType(FieldType.getFieldType(field.getType()));
    String length = elem.attributeValue("length");
    if (StringUtils.isNumeric(length)) {
        field.setLength(Integer.valueOf(length));
    }
    String maxLength = elem.attributeValue("maxLength");
    if (StringUtils.isNumeric(maxLength)) {
        field.setMaxLength(Integer.valueOf(maxLength));
    }
    String minLength = elem.attributeValue("minLength");
    if (StringUtils.isNumeric(minLength)) {
        field.setMinLength(Integer.valueOf(minLength));
    }
    String displayType = elem.attributeValue("displayType");
    if (StringUtils.isNumeric(displayType)) {
        field.setDisplayType(Integer.valueOf(displayType));
    }
    String sortNo = elem.attributeValue("sortNo");
    if (StringUtils.isNumeric(sortNo)) {
        field.setSortNo(Integer.valueOf(sortNo));
    }
    if (StringUtils.equals(elem.attributeValue("updatable"), "false")) {
        field.setUpdatable(false);
    }
    if (StringUtils.equals(elem.attributeValue("nullable"), "false")) {
        field.setNullable(false);
    }
    if (StringUtils.equals(elem.attributeValue("editable"), "true")) {
        field.setEditable(true);
    }
    if (StringUtils.equals(elem.attributeValue("searchable"), "true")) {
        field.setSearchable(true);
    }
}

From source file:io.stallion.users.UsersApiResource.java

@POST
@Path("/valet-login")
@Produces("application/json")
@MinRole(Role.MEMBER)/*from ww  w. j  a v  a2s .c  o m*/
public Object valetLogin(@BodyParam("targetUser") Object userKey) {
    if (StringUtils.isNumeric(userKey.toString())) {
        UserController.instance().valetLoginIfAllowed(Long.parseLong(userKey.toString()));
    } else {
        UserController.instance().valetLoginIfAllowed(userKey.toString());
    }
    return true;
}

From source file:com.emergya.persistenceGeo.web.RestTreeFolderController.java

/**
 * Returns the children of a specific container node. The container type is
 * specified using the type parameter. The condition the returned nodes has
 * to meet is specified using the filter parameter.
 * /*w  ww  .  j  a v a 2 s .  c  o  m*/
 * @param node
 *            The node id
 * @param type
 *            The type of the node (zone, folderType(Long), folder)
 * @param filter
 *            The condition the returned nodes has to meet
 * 
 * @return JSON node children of selected node
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/persistenceGeo/tree/treeService", produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<Treeable> treeService(@RequestParam(value = "node", required = false) String nodeId,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam(value = "filter", required = false) String filter) {

    List<Treeable> nodes = new LinkedList<Treeable>();

    try {

        Long typeId = FoldersAdminService.DEFAULT_FOLDER_TYPE;
        if (StringUtils.isNotBlank(type)
                && (StringUtils.isNumeric(type) || type.equals(ID_ANY_FOLDER_TYPE.toString()))) {
            typeId = Long.decode(type);
        }

        if (!StringUtils.isEmpty(nodeId) && (StringUtils.isNumeric(nodeId)
                || RestFoldersAdminController.UNASSIGNED_LAYERS_VIRTUAL_FOLDER_ID.toString().equals(nodeId))) {
            // The rest of types are consider like folders
            nodes = (List<Treeable>) restFoldersAdminController.loadFoldersById(nodeId, filter).get(ROOT);
        } else {
            // get root folder types
            nodes.addAll(getFoldersByType(typeId, filter));
        }

    } catch (Exception e) {
        LOG.error(e);
    }

    return nodes;
}

From source file:com.glaf.base.modules.sys.springmvc.MxLoginController.java

/**
 * //from   w  w  w.  j  a va  2s.  c  o  m
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping("/doLogin")
public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    HttpSession session = request.getSession(false);
    if (session == null) {
        return new ModelAndView("/modules/login", modelMap);
    }

    if (StringUtils.isNotEmpty(request.getParameter("systemName"))) {
        Environment.setCurrentSystemName(request.getParameter("systemName"));
    } else {
        Environment.setCurrentSystemName(Environment.DEFAULT_SYSTEM_NAME);
    }

    ViewMessages messages = new ViewMessages();
    // ??
    String account = ParamUtil.getParameter(request, "x");
    String password = ParamUtil.getParameter(request, "y");

    String rand = (String) session.getAttribute("x_y");
    if (rand != null) {
        password = StringTools.replace(password, rand, "");
    }
    String rand2 = (String) session.getAttribute("x_z");
    if (rand2 != null) {
        password = StringTools.replace(password, rand2, "");
    }
    String pwd = password;
    try {
        pwd = DigestUtil.digestString(password, "MD5");
    } catch (Exception ex) {
    }

    logger.debug(account + " start login........................");

    // 
    SysUser bean = authorizeService.authorize(account, pwd);
    if (bean == null) {
        // ?
        messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure"));
        MessageUtils.addMessages(request, messages);
        return new ModelAndView("/modules/login", modelMap);
    }

    String ipAddr = RequestUtils.getIPAddress(request);
    SystemProperty p = SystemConfig.getProperty("login_limit");

    if (!(StringUtils.equals(ipAddr, "localhost") || StringUtils.equals(ipAddr, "127.0.0.1")
            || StringUtils.equals(account, "root") || StringUtils.equals(account, "admin"))) {

        SystemProperty pt = SystemConfig.getProperty("login_time_check");
        int timeoutSeconds = 300;

        if (pt != null && pt.getValue() != null && StringUtils.isNumeric(pt.getValue())) {
            timeoutSeconds = Integer.parseInt(pt.getValue());
        }
        if (timeoutSeconds < 300) {
            timeoutSeconds = 300;
        }
        if (timeoutSeconds > 3600) {
            timeoutSeconds = 3600;
        }

        /**
         * ???
         */
        if (p != null && StringUtils.equals(p.getValue(), "true")) {
            logger.debug("#################3#########################");
            String loginIP = null;
            UserOnline userOnline = userOnlineService.getUserOnline(account);
            logger.debug("userOnline:" + userOnline);
            boolean timeout = false;
            if (userOnline != null) {
                loginIP = userOnline.getLoginIP();
                if (userOnline.getCheckDateMs() != null
                        && System.currentTimeMillis() - userOnline.getCheckDateMs() > timeoutSeconds * 1000) {
                    timeout = true;// ?
                }
                if (userOnline.getLoginDate() != null && System.currentTimeMillis()
                        - userOnline.getLoginDate().getTime() > timeoutSeconds * 1000) {
                    timeout = true;// ?
                }
            }
            logger.info("timeout:" + timeout);
            logger.info("login IP:" + loginIP);
            if (!timeout) {// ????
                if (loginIP != null && !(StringUtils.equals(ipAddr, loginIP))) {// 
                    messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("authorize.login_failure2"));
                    MessageUtils.addMessages(request, messages);
                    logger.debug("?");
                    return new ModelAndView("/modules/login", modelMap);
                }
            }
        }
    }

    Properties props = CallbackProperties.getProperties();
    if (props != null && props.keys().hasMoreElements()) {
        Enumeration<?> e = props.keys();
        while (e.hasMoreElements()) {
            String className = (String) e.nextElement();
            try {
                Object obj = ClassUtils.instantiateObject(className);
                if (obj instanceof LoginCallback) {
                    LoginCallback callback = (LoginCallback) obj;
                    callback.afterLogin(bean.getAccount(), request, response);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                logger.error(ex);
            }
        }
    }

    if (bean.getLoginCount() != null) {
        bean.setLoginCount(bean.getLoginCount() + 1);
    } else {
        bean.setLoginCount(1);
    }

    // ?
    bean.setLastLoginDate(new Date());
    sysUserService.updateUser(bean);

    ContextUtil.put(bean.getAccount(), bean);// ??

    RequestUtils.setLoginUser(request, response, "default", bean.getAccount());
    if (p != null && StringUtils.equals(p.getValue(), "true")) {
        try {
            UserOnline online = new UserOnline();
            online.setActorId(bean.getActorId());
            online.setName(bean.getName());
            online.setCheckDate(new Date());
            online.setLoginDate(new Date());
            online.setLoginIP(ipAddr);
            online.setSessionId(session.getId());
            userOnlineService.login(online);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }

    if (bean.getAccountType() == 1) {// 
        return new ModelAndView("/modules/sp_main", modelMap);
    } else if (bean.getAccountType() == 2) {// 
        return new ModelAndView("/modules/wx_main", modelMap);
    } else {
        return new ModelAndView("/modules/main", modelMap);
    }

}

From source file:forge.game.spellability.AbilityManaPart.java

/**
 * <p>/*from  w w  w  .j a  v a 2s  . c o m*/
 * produceMana.
 * </p>
 * 
 * @param produced
 *            a {@link java.lang.String} object.
 * @param player
 *            a {@link forge.game.player.Player} object.
 * @param sa
 */
public final void produceMana(final String produced, final Player player, SpellAbility sa) {
    final Card source = this.getSourceCard();
    final ManaPool manaPool = player.getManaPool();
    String afterReplace = applyManaReplacement(sa, produced);
    final HashMap<String, Object> repParams = new HashMap<String, Object>();
    repParams.put("Event", "ProduceMana");
    repParams.put("Mana", afterReplace);
    repParams.put("Affected", source);
    repParams.put("Player", player);
    repParams.put("AbilityMana", sa);
    if (player.getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) {
        return;
    }
    ColorSet CID = null;

    if (player.getGame().getRules().hasCommander()) {
        CID = player.getCommander().getRules().getColorIdentity();
    }
    //clear lastProduced
    this.lastManaProduced.clear();

    // loop over mana produced string
    for (final String c : afterReplace.split(" ")) {
        if (StringUtils.isNumeric(c)) {
            for (int i = Integer.parseInt(c); i > 0; i--) {
                this.lastManaProduced.add(new Mana(MagicColor.COLORLESS, source, this));
            }
        } else {
            byte attemptedMana = MagicColor.fromName(c);
            if (CID != null) {
                if (!CID.hasAnyColor(attemptedMana)) {
                    attemptedMana = MagicColor.COLORLESS;
                }
            }

            this.lastManaProduced.add(new Mana(attemptedMana, source, this));
        }
    }

    // add the mana produced to the mana pool
    manaPool.add(this.lastManaProduced);

    // Run triggers
    final HashMap<String, Object> runParams = new HashMap<String, Object>();

    runParams.put("Card", source);
    runParams.put("Player", player);
    runParams.put("AbilityMana", sa);
    runParams.put("Produced", afterReplace);
    player.getGame().getTriggerHandler().runTrigger(TriggerType.TapsForMana, runParams, false);
    // Clear Mana replacement
    this.manaReplaceType = "";
}

From source file:com.glaf.jbpm.web.springmvc.MxJbpmProcessTreeController.java

@RequestMapping
public ModelAndView list(HttpServletRequest request, ModelMap modelMap) {
    String processDefinitionId = request.getParameter("processDefinitionId");
    String processName = request.getParameter("processName");
    List<ProcessDefinition> result = null;
    GraphSession graphSession = null;//  w  ww  .  j  av  a  2s  .  co m
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        graphSession = jbpmContext.getGraphSession();
        if (StringUtils.isNotEmpty(processDefinitionId) && StringUtils.isNumeric(processDefinitionId)) {
            Collection<Long> processDefinitionIds = new java.util.ArrayList<Long>();
            processDefinitionIds.add(Long.parseLong(processDefinitionId));
            result = graphSession.findProcessDefinitions(processDefinitionIds);
        } else {
            if (StringUtils.isNotEmpty(processName)) {
                result = graphSession.findAllProcessDefinitionVersions(processName);
            } else {
                result = graphSession.findAllProcessDefinitions();
            }
        }
        modelMap.put("rows", result);
    } catch (Exception ex) {
        logger.debug(ex);
    } finally {
        Context.close(jbpmContext);
    }

    String jx_view = request.getParameter("jx_view");

    if (StringUtils.isNotEmpty(jx_view)) {
        return new ModelAndView(jx_view, modelMap);
    }

    String x_view = ViewProperties.getString("jbpm_tree.list");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/jbpm/tree/list", modelMap);
}