List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:edu.usu.sdl.openstorefront.service.search.ComponentSearchHandler.java
@Override protected ValidationResult internalValidate() { ValidationResult validationResult = new ValidationResult(); for (SearchElement searchElement : searchElements) { if (StringUtils.isBlank(searchElement.getField())) { validationResult.getRuleResults().add(getRuleResult("field", "Required")); }// w w w.j av a2 s. c o m if (StringUtils.isBlank(searchElement.getValue())) { validationResult.getRuleResults().add(getRuleResult("value", "Required")); } Field field = ReflectionUtil.getField(new Component(), searchElement.getField()); if (field == null) { validationResult.getRuleResults().add(getRuleResult("field", "Doesn't exist on component")); } else { Class type = field.getType(); if (type.getSimpleName().equals(String.class.getSimpleName())) { //Nothing to check } else if (type.getSimpleName().equals(Integer.class.getSimpleName())) { if (StringUtils.isNumeric(searchElement.getValue()) == false) { validationResult.getRuleResults() .add(getRuleResult("value", "Value should be an integer for this field")); } } else if (type.getSimpleName().equals(Date.class.getSimpleName())) { if (searchElement.getStartDate() == null && searchElement.getEndDate() == null) { validationResult.getRuleResults().add( getRuleResult("startDate", "Start or End date should be entered for this field")); validationResult.getRuleResults().add( getRuleResult("endDate", "Start or End date should be entered for this field")); } } else if (type.getSimpleName().equals(Boolean.class.getSimpleName())) { //Nothing to check } else { validationResult.getRuleResults() .add(getRuleResult("field", "Field type handling not supported")); } } } return validationResult; }
From source file:com.clican.pluto.common.bean.PropertyIntialHashMap.java
@SuppressWarnings("unchecked") public void initProperty() { String[] entries = propertyStr.split(";"); for (String entry : entries) { try {// w w w .j av a2 s . c o m String[] str = entry.split("=>"); Object key = str[0].trim(); if (((String) key).indexOf("'") == -1) { key = context.getBean((String) key); } else { key = ((String) key).replaceAll("\\'", "").trim(); } Object value = null; if (str[1].indexOf("{") != -1 && str[1].indexOf("}") != -1) { value = new ArrayList<Object>(); String[] values = str[1].replaceAll("\\{", "").replaceAll("\\}", "").split(","); for (String v : values) { v = v.trim(); if (v.indexOf("'") == -1) { if (StringUtils.isNumeric(v)) { ((List<Object>) value).add(new Long(v)); } ((List<Object>) value).add(context.getBean(v)); } else { v = v.replaceAll("\\'", "").trim(); ((List<Object>) value).add(v); } } } else { value = str[1].trim(); if (((String) value).indexOf("'") == -1) { if (StringUtils.isNumeric(value.toString())) { ((List<Object>) value).add(new Long(value.toString())); } value = context.getBean((String) value); } else { value = ((String) value).replaceAll("\\'", "").trim(); } } put((K) key, (V) value); } catch (Exception e) { throw new IllegalArgumentException("Initial property error,[" + entry + "]The initial property must like 'a'=>{'a1','a2','a3'}, 'b'=>{'b1','b2'}, 'c'=>{}, d=>{d1,d2,d3}, 'e'=>'e1', f=f1. the value is in '' will be convert to string, the value is not in '' will be convert as a spring bean name", e); } } }
From source file:edu.usu.sdl.openstorefront.service.search.ReviewSearchHandler.java
@Override protected ValidationResult internalValidate() { ValidationResult validationResult = new ValidationResult(); for (SearchElement searchElement : searchElements) { if (StringUtils.isBlank(searchElement.getField())) { validationResult.getRuleResults().add(getRuleResult("field", "Required")); }/* w ww . ja v a 2 s.c o m*/ if (StringUtils.isBlank(searchElement.getValue())) { validationResult.getRuleResults().add(getRuleResult("value", "Required")); } Field field = ReflectionUtil.getField(new ComponentReview(), searchElement.getField()); if (field == null) { validationResult.getRuleResults().add(getRuleResult("field", "Doesn't exist on component review")); } else { Class type = field.getType(); if (type.getSimpleName().equals(String.class.getSimpleName())) { //Nothing to check } else if (type.getSimpleName().equals(Integer.class.getSimpleName())) { if (StringUtils.isNumeric(searchElement.getValue()) == false) { validationResult.getRuleResults() .add(getRuleResult("value", "Value should be an integer for this field")); } } else if (type.getSimpleName().equals(Date.class.getSimpleName())) { if (searchElement.getStartDate() == null && searchElement.getEndDate() == null) { validationResult.getRuleResults().add( getRuleResult("startDate", "Start or End date should be entered for this field")); validationResult.getRuleResults().add( getRuleResult("endDate", "Start or End date should be entered for this field")); } } else if (type.getSimpleName().equals(Boolean.class.getSimpleName())) { //Nothing to check } else { validationResult.getRuleResults() .add(getRuleResult("field", "Field type handling not supported")); } } } return validationResult; }
From source file:fr.paris.lutece.plugins.stock.modules.billetterie.service.ProductExtendableResourceService.java
/** * {@inheritDoc}//from w w w . ja va 2s .co m */ @Override public IExtendableResource getResource(String strIdResource, String strResourceType) { IExtendableResource resources = null; if (StringUtils.isNotBlank(strIdResource) && StringUtils.isNumeric(strIdResource)) { int nIdProduct = Integer.parseInt(strIdResource); resources = _serviceProduct.findById(nIdProduct); } return resources; }
From source file:com.noah.ai.platform.pub.entity.Pager.java
public Pager(HttpServletRequest request, HttpServletResponse response, int defaultPageSize) { // ??repage???? String no = request.getParameter("pageNo"); if (StringUtils.isNumeric(no)) { CookieUtils.setCookie(response, "pageNo", no); this.setPageNo(Integer.parseInt(no)); } else if (request.getParameter("repage") != null) { no = CookieUtils.getCookie(request, "pageNo"); if (StringUtils.isNumeric(no)) { this.setPageNo(Integer.parseInt(no)); }//from w w w. j a v a2s .c o m } // ???repage????? String size = request.getParameter("pageSize"); if (StringUtils.isNumeric(size)) { CookieUtils.setCookie(response, "pageSize", size); this.setPageSize(Integer.parseInt(size)); } else if (request.getParameter("repage") != null) { no = CookieUtils.getCookie(request, "pageSize"); if (StringUtils.isNumeric(size)) { this.setPageSize(Integer.parseInt(size)); } } else if (defaultPageSize != -2) { this.pageSize = defaultPageSize; } }
From source file:de.cosmocode.palava.legacy.UtilityJobImpl.java
@Override public int getOptInt(String key, int defaultValue) { if (hasArgument(key)) { final String val = getOptional(key); if (StringUtils.isNumeric(val)) { return Integer.parseInt(val); }// www. java 2s . c o m } return defaultValue; }
From source file:br.com.nordestefomento.jrimum.bopepo.campolivre.CampoLivreFactory.java
/** * Devolve um CampoLivre de acordo a partir de uma String. * // www. j a va2s . c o m * @param strCampoLivre * * @return Uma referncia para um ICampoLivre. * * @throws NullPointerException * @throws IllegalArgumentException */ public static CampoLivre create(String strCampoLivre) { CampoLivre campoLivre = null; ObjectUtil.checkNotNull(strCampoLivre); StringUtil.checkNotBlank(strCampoLivre, "O Campo Livre no deve ser vazio!"); strCampoLivre = StringUtils.strip(strCampoLivre); if (strCampoLivre.length() == CampoLivre.STRING_LENGTH) { if (StringUtils.remove(strCampoLivre, ' ').length() == CampoLivre.STRING_LENGTH) { if (StringUtils.isNumeric(strCampoLivre)) { campoLivre = new CampoLivre() { private static final long serialVersionUID = -7592488081807235080L; Field<String> campo = new Field<String>(StringUtils.EMPTY, STRING_LENGTH, Filler.ZERO_LEFT); public void read(String str) { campo.read(str); } public String write() { return campo.write(); } }; campoLivre.read(strCampoLivre); } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] deve ser uma String numrica!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] no deve conter espaos em branco!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException("O tamanho do Campo Livre [ " + strCampoLivre + " ] deve ser igual a 25 e no [" + strCampoLivre.length() + "]!"); log.error(StringUtils.EMPTY, e); throw e; } return campoLivre; }
From source file:fr.paris.lutece.plugins.suggest.service.SuggestExtendableResourceService.java
/** * {@inheritDoc}//from w ww . j a va 2 s.c o m */ @Override public IExtendableResource getResource(String strIdResource, String strResourceType) { if (StringUtils.isNotBlank(strIdResource) && StringUtils.isNumeric(strIdResource)) { int nIdSuggest = Integer.parseInt(strIdResource); return SuggestHome.findByPrimaryKey(nIdSuggest, PluginService.getPlugin(SuggestPlugin.PLUGIN_NAME)); } return null; }
From source file:br.com.nordestefomento.jrimum.bopepo.campolivre.guia.CampoLivreFactory.java
/** * Devolve um CampoLivre de acordo a partir de uma String. * /*w w w .j a va 2s.c o m*/ * @param strCampoLivre * * @return Uma referncia para um CampoLivre. * * @throws NullPointerException * @throws IllegalArgumentException */ public static CampoLivre create(String strCampoLivre, TipoSeguimento tipoSeguimento) { CampoLivre campoLivre = null; final Integer tamanhoCorreto = CampoLivreUtil.getTamanhoCorreto(tipoSeguimento); ObjectUtil.checkNotNull(strCampoLivre); StringUtil.checkNotBlank(strCampoLivre, "O Campo Livre no deve ser vazio!"); strCampoLivre = StringUtils.strip(strCampoLivre); if (CampoLivreUtil.tamanhoEstaCorreto(strCampoLivre, tipoSeguimento)) { if (CampoLivreUtil.naoExisteEspacoEmBranco(strCampoLivre, tipoSeguimento)) { if (StringUtils.isNumeric(strCampoLivre)) { campoLivre = new CampoLivre() { private static final long serialVersionUID = -7592488081807235080L; Field<String> campo = new Field<String>(StringUtils.EMPTY, tamanhoCorreto, Filler.ZERO_LEFT); public void read(String str) { campo.read(str); } public String write() { return campo.write(); } }; campoLivre.read(strCampoLivre); } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] deve ser uma String numrica!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] no deve conter espaos em branco!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException("O tamanho do Campo Livre [ " + strCampoLivre + " ] deve ser igual a " + tamanhoCorreto + " e no [" + strCampoLivre.length() + "]!"); log.error(StringUtils.EMPTY, e); throw e; } return campoLivre; }
From source file:co.mcme.warps.commands.WarpListCommand.java
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { ArrayList<PlayerWarp> list = new ArrayList(); if (sender instanceof Player) { for (PlayerWarp warp : WarpDatabase.getWarps().values()) { if (warp.canWarp((Player) sender)) { list.add(warp);// w w w .ja v a 2 s . c o m } } } else { list.addAll(WarpDatabase.getWarps().values()); } StringBuilder lines = new StringBuilder(); boolean first = true; for (PlayerWarp warp : list) { if (!first) { lines.append("\n"); } ChatColor col = ChatColor.GREEN; if (warp.isInviteonly()) { col = ChatColor.RED; } Date date = new Date(warp.getCreateStamp()); lines.append(col).append(warp.getName()).append(ChatColor.GRAY).append(" by ").append(ChatColor.AQUA) .append(warp.getOwner()).append(ChatColor.GRAY).append(" on ").append(ChatColor.AQUA) .append(Warps.getShortDateformat().format(date)); if (first) { first = false; } } if (args.length > 0 && StringUtils.isNumeric(args[0])) { ChatPaginator.ChatPage page = ChatPaginator.paginate(lines.toString(), Integer.valueOf(args[0]), ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH, 8); sender.sendMessage(ChatColor.GRAY + "Warp List page " + ChatColor.AQUA + page.getPageNumber() + ChatColor.GRAY + " of " + ChatColor.AQUA + page.getTotalPages()); for (String line : page.getLines()) { sender.sendMessage(line); } return true; } else { ChatPaginator.ChatPage page = ChatPaginator.paginate(lines.toString(), 1, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH, 8); sender.sendMessage(ChatColor.GRAY + "Warp List page " + ChatColor.AQUA + page.getPageNumber() + ChatColor.GRAY + " of " + ChatColor.AQUA + page.getTotalPages()); for (String line : page.getLines()) { sender.sendMessage(line); } return true; } }