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.web.module.home.controllers.kandian.KanDianController.java

/**
 * //from   w  w w. j  a  v  a 2  s .  c o  m
 * 
 * @param model
 * @param id ?
 * @return
 */
@RequestMapping("/{id}")
@MethodRemark("remark=")
public String detail(ModelMap model, @PathVariable("id") String id) {
    if (StringUtils.isBlank(id) || !StringUtils.isNumeric(id)) {
        log.error(String.format("???%s", id));
    } else {
        NewsDetailDO kanDian = newsManager.getNews(Long.valueOf(id));
        if (null == kanDian) {
            log.error(String.format("??%s", id));
        } else {
            String scope = kanDian.getScope();
            model.put("description", HtmlUtils.deleteHtmlS(kanDian.getNewsContent()));
            model.put("newsDO", kanDian);
            if ("1".equals(scope)) { // 
                if (hospitalDetail(model, kanDian.getHospitalId())) {
                    return HospitalConstants.VIEW_HOSPITAL_NEWS_DETAIL;
                }
            } else if ("2".equals(scope)) { // 
                if (hospDeptDetail(model, kanDian.getHospDeptId())) {
                    return DepartmentConstants.VIEW_DEPARTMENT_NEWS_DETAIL;
                }
            } else {
                log.error(String.format("%s", scope));
            }
        }
    }
    model.put("error_message", "?");
    return GlobalConstants.ERROR_PAGE;
}

From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.ActionFormatterXml.java

/**
 * {@inheritDoc}//from  ww w.  j a  va  2  s .com
 */
@Override
public String formatError(String strCode, String strMessage) {
    int nIdCode = WorkflowUtils.CONSTANT_ID_NULL;

    if (StringUtils.isNotBlank(strCode) && StringUtils.isNumeric(strCode)) {
        nIdCode = Integer.parseInt(strCode);
    }

    return XMLUtil.formatError(strMessage, nIdCode);
}

From source file:fr.paris.lutece.plugins.workflow.modules.mappings.business.ActionCodeMapping.java

/**
 * {@inheritDoc}/*from   ww  w .j a  v  a 2  s. com*/
 */
public String getLabelReferenceCode(Locale locale) {
    if (StringUtils.isNotBlank(getReferenceCode()) && StringUtils.isNumeric(getReferenceCode())) {
        int nIdAction = Integer.parseInt(getReferenceCode());
        Action action = _actionService.findByPrimaryKey(nIdAction);

        if (action != null) {
            Workflow workflow = _workflowService.findByPrimaryKey(action.getWorkflow().getId());

            if (workflow != null) {
                return workflow.getName() + " - " + action.getName();
            } else {
                AppLogService.error("ActionCodeMapping - The workflow is not found for id workflow "
                        + action.getWorkflow().getId());
            }
        } else {
            AppLogService.error("ActionCodeMapping - The action is not found for id action " + nIdAction);
        }
    } else {
        AppLogService.error("ActionCodeMapping - The reference code '" + getReferenceCode() + "' is invalid.");
    }

    return getReferenceCode();
}

From source file:com.carlos.projects.billing.ui.controllers.AddComponentsController.java

private Document getDocumentWithComponentsAdded(Map<String, String[]> parameterMap) {
    Document document;/*from  w w w. j  a  v a  2 s  .  c  o m*/
    String[] documentId = parameterMap.get("documentId");
    if (documentId != null && (!StringUtils.isEmpty(documentId[0]) && (StringUtils.isNumeric(documentId[0])))) {
        document = documentDAO.getById(Document.class, Long.parseLong(documentId[0]));
    } else {
        document = new Document();
    }
    Set<DocumentComponent> documentComponentsAdded = new HashSet<DocumentComponent>();
    for (String key : parameterMap.keySet()) {
        if (key.startsWith("componentCode")) {
            documentComponentsAdded.add(createDocumentComponent(getComponentCode(key), parameterMap, document));
        }
    }
    document.setDocumentComponents(documentComponentsAdded);
    documentDAO.saveOrUpdate(document);
    return document;
}

From source file:fr.paris.lutece.portal.business.user.parameter.EmailPatternRegularExpressionRemovalListener.java

/**
* Check if the object can be safely removed
* @param strId The object id//  w  ww  .  j a va  2  s. c om
* @return true if the object can be removed otherwise false
*/
public boolean canBeRemoved(String strId) {
    boolean bCanBeRemoved = true;

    if (StringUtils.isNotBlank(strId) && StringUtils.isNumeric(strId)) {
        int nId = Integer.parseInt(strId);
        List<RegularExpression> listRegularExpressions = AdminUserService.getSelectedRegularExpressions();

        for (RegularExpression regularExpression : listRegularExpressions) {
            if (nId == regularExpression.getIdExpression()) {
                bCanBeRemoved = false;

                break;
            }
        }
    }

    return bCanBeRemoved;
}

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

@GET
public Object getType(@PathParam("idOrName") String idOrName) throws FxApplicationException {
    final FxEnvironment env = CacheAdmin.getEnvironment();
    final FxType type;
    if (StringUtils.isNumeric(idOrName)) {
        type = env.getType(Long.parseLong(idOrName));
    } else {//from www  . j  a  va  2 s .c o m
        type = env.getType(idOrName);
    }

    return FxRestApiResponse.ok(FxRestApiUtils.responseMapBuilder().put("name", type.getName())
            .put("id", type.getId()).put("assignments", buildAssignments(env, type), "assignment")
            .put("properties", buildProperties(env, type), "property").build());
}

From source file:com.impetus.client.cassandra.service.CassandraHostConfiguration.java

public CassandraHostConfiguration(Map externalProperties, CassandraSchemaMetadata csmd, String persistenceUnit,
        final KunderaMetadata kunderaMetadata) {
    super(externalProperties, csmd != null ? csmd.getConnectionServers() : new ArrayList<Server>(),
            persistenceUnit, kunderaMetadata);
    connectionProperties.putAll(csmd.getConnectionProperties());
    String property = csmd.getConnectionProperties().getProperty(Constants.RETRY_DELAY);
    if (StringUtils.isNumeric(property)) {
        retryDelay = Integer.parseInt(property);
    }//from w  w  w  . j a va 2s.co  m
}

From source file:com.ewcms.plugin.vote.manager.service.PersonService.java

private void updVoteNumber(Person person) {
    List<Record> records = person.getRecords();
    for (Record record : records) {
        String subjectName = record.getSubjectName();
        String subjectValue = record.getSubjectValue();

        String[] recordNames = subjectName.split("_");
        if (recordNames.length == 2) {
            if (recordNames[0].equals("Subject")) {
                if (!recordNames[1].equals("") && StringUtils.isNumeric(recordNames[1])) {
                    Long subjectId = new Long(recordNames[1]);
                    Subject subject = subjectDAO.get(subjectId);
                    if (subject == null)
                        continue;
                    if (subject.getStatus() == Subject.Status.INPUT) {
                        SubjectItem subjectItem = subjectItemDAO
                                .findSubjectItemBySubjectAndInputStatus(subjectId);
                        if (subjectItem == null)
                            continue;
                        try {
                            subjectItem.setVoteNumber(subjectItem.getVoteNumber() + 1);
                        } catch (NullPointerException e) {
                            subjectItem.setVoteNumber(1L);
                        }//from   w  ww .j av a  2s. c  o  m
                        subjectItemDAO.merge(subjectItem);
                    } else {
                        if (!subjectValue.equals("") && StringUtils.isNumeric(subjectValue)) {
                            Long subjectItemId = new Long(subjectValue);
                            SubjectItem subjectItem = subjectItemDAO.get(subjectItemId);
                            try {
                                subjectItem.setVoteNumber(subjectItem.getVoteNumber() + 1);
                            } catch (NullPointerException e) {
                                subjectItem.setVoteNumber(1L);
                            }
                            subjectItemDAO.merge(subjectItem);
                        }
                    }
                }
            }
        } else if (recordNames.length == 4) {
            if (recordNames[0].equals("Subject") && recordNames[2].equals("Item")) {
                if (!recordNames[3].equals("") && StringUtils.isNumeric(recordNames[3])) {
                    Long subjectItemId = new Long(recordNames[3]);
                    SubjectItem subjectItem = subjectItemDAO.get(subjectItemId);
                    try {
                        subjectItem.setVoteNumber(subjectItem.getVoteNumber() + 1);
                    } catch (NullPointerException e) {
                        subjectItem.setVoteNumber(1L);
                    }
                    subjectItemDAO.merge(subjectItem);
                }
            }
        }
    }
}

From source file:io.github.xxyy.simplegiveall.SimpleGiveallMain.java

private static ItemStack handleGiveallHand(final CommandSender sender, final String[] args) {
    ItemStack finalStack;// w ww.j a  va 2s.c o m

    if (!(sender instanceof Player)) { //If we don't have a player, we can't get the hand stack
        sender.sendMessage(bundle.getString("ERR_NO_PLAYER"));
        return null;
    }

    final Player plr = (Player) sender;
    finalStack = plr.getItemInHand().clone(); //Without clone(), there are some weeeird bugs
    if (finalStack == null || finalStack.getType().equals(Material.AIR) || finalStack.getAmount() == 0) { //If the player has nothing in their hand
        plr.sendMessage(bundle.getString("ERR_NOTHING_IN_HAND"));
        return null;
    }

    if (args.length >= 2 && StringUtils.isNumeric(args[1])) { //If we have an optional numeric argument specifying the amount to give,
        finalStack.setAmount(Integer.parseInt(args[1])); //apply that size to our stack
    }

    return finalStack;
}

From source file:com.pcb.pcbridge.commands.CommandBuySkull.java

@Override
public boolean OnExecute(CommandArgs args) {
    if (!args.IsPlayer()) {
        args.GetSender().sendMessage(ChatColor.RED + "Only players in-game can use this command.");
        return true;
    }//ww  w  .  j av  a  2 s.co  m

    if (args.GetArgs().length == 0 || args.GetArgs().length > 2)
        return false;

    if (args.GetArgs().length == 2 && !StringUtils.isNumeric(args.GetArg(1)))
        return false;

    // check input for player name
    String alias = args.GetArg(0);

    Matcher m = pattern.matcher(alias);
    if (!m.find())
        return false;

    // strip 'player:' from name
    String name = alias.replaceFirst("^(player:)", "");

    int quantity = args.GetArgs().length == 2 ? Integer.parseInt(args.GetArg(1)) : 1;
    int cost = SKULL_COST * quantity;

    // ensure player has enough money for the purchase
    Economy economy = PCBridge.GetVaultHook().GetEconomy();
    if (!economy.has(args.GetPlayer(), cost)) {
        args.GetSender().sendMessage(ChatColor.RED + "You do not have enough money (price: $" + cost + ")");
        return true;
    }

    // ensure player's inventory isn't full
    PlayerInventory inventory = args.GetPlayer().getInventory();
    if (inventory.firstEmpty() == -1) {
        args.GetSender()
                .sendMessage(ChatColor.RED + "Your inventory is full. Please clear a slot and try again.");
        return true;
    }

    // create skull and give it to the player
    ItemStack skull = new ItemStack(Material.SKULL_ITEM, quantity, (short) 3);
    SkullMeta meta = (SkullMeta) skull.getItemMeta();
    meta.setOwner(name);
    skull.setItemMeta(meta);
    inventory.addItem(skull);

    economy.withdrawPlayer(args.GetPlayer(), cost);

    args.GetSender().sendMessage(ChatColor.GREEN + "Purchased skull of " + name + " for $" + cost);

    return true;
}