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:fr.paris.lutece.plugins.directory.modules.pdfproducerarchive.web.ZipBasketJspBean.java
/** * display the basket basket/*from w w w. j ava 2s . c o m*/ * @param request request * @return page to manage zip * @throws AccessDeniedException exception if the user does not have the right */ public String getManageZipToBasket(HttpServletRequest request) throws AccessDeniedException { String strIdDirectory = request.getParameter(PARAMETER_ID_DIRECTORY); if (!RBACService.isAuthorized(Directory.RESOURCE_TYPE, strIdDirectory, DirectoryPDFProducerArchiveResourceIdService.PERMISSION_GENERATE_ZIP, getUser()) || StringUtils.isBlank(strIdDirectory) || !StringUtils.isNumeric(strIdDirectory)) { throw new AccessDeniedException(); } Map<String, Object> model = new HashMap<String, Object>(); List<ZipBasket> listZipBasket = _manageZipBasketService.loadAllZipBasketByAdminUserOrder(getPlugin(), getUser().getUserId(), DirectoryUtils.convertStringToInt(strIdDirectory)); String strSortedAttributeName = request.getParameter(Parameters.SORTED_ATTRIBUTE_NAME); String strAscSort = null; if (strSortedAttributeName != null) { strAscSort = request.getParameter(Parameters.SORTED_ASC); boolean bIsAscSort = Boolean.parseBoolean(strAscSort); Collections.sort(listZipBasket, new AttributeComparator(strSortedAttributeName, bIsAscSort)); } model.put(MARK_ID_DIRECTORY, strIdDirectory); model.put(MARK_LIST_ZIPBASKET, listZipBasket); model.put(MARK_PERMISSION_DELETE_ZIP, RBACService.isAuthorized(Directory.RESOURCE_TYPE, strIdDirectory, DirectoryPDFProducerArchiveResourceIdService.PERMISSION_DELETE_ZIP, getUser())); Directory directory = _manageZipBasketService .getDirectory(DirectoryUtils.convertStringToInt(strIdDirectory)); if (!listZipBasket.isEmpty() && (directory != null)) { for (ZipBasket zipBasket : listZipBasket) { zipBasket.setListZipBasketAction(_manageZipBasketService.selectActionsByZipBasketState( DirectoryUtils.convertStringToInt(zipBasket.getZipStatus()), getLocale(), directory, getUser(), getPlugin())); } } model.put(MARK_DAEMON_NEXT_SCHEDULE, getLabelTimeBeforeNextDaemonPassage(MESSAGE_DAEMON_NEXT_PASS, MESSAGE_DAEMON_RUNNING, request, DAEMON_ARCHIVE_ID)); model.put(MARK_DAEMON_UPDATE_STATUS_NEXT_SCHEDULE, getLabelTimeBeforeNextDaemonPassage(MESSAGE_DAEMON_UPDATE_STATUS_NEXT_PASS, MESSAGE_DAEMON_UPDATE_STATUS_RUNNING, request, DAEMON_UPDATE_STATUS_ID)); HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_MANAGE_ZIP_BASKET, getLocale(), model); return getAdminPage(templateList.getHtml()); }
From source file:com.salesmanager.central.profile.StoreAction.java
/** * Invoked from CRUD actions/*from w w w . ja v a2 s. c om*/ * * @return */ public String saveStore() { super.setPageTitle("label.menu.group.store"); MerchantStore store = null; try { Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context); Integer merchantid = ctx.getMerchantid(); MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); store = mservice.getMerchantStore(merchantid.intValue()); //validation /* if (StringUtils.isBlank(merchantProfile.getTemplateModule())) { super.setErrorMessage("errors.store.emptytemplate"); return INPUT; } */ if (store == null) { store = new MerchantStore(); store.setTemplateModule(CatalogConstants.DEFAULT_TEMPLATE); } else { store.setTemplateModule(merchantProfile.getTemplateModule()); } java.util.Date dt = new java.util.Date(); StringBuffer languages = new StringBuffer(); List langs = this.getSupportedLanguages(); if (langs != null && langs.size() > 0) { int sz = 0; Iterator i = langs.iterator(); while (i.hasNext()) { String lang = (String) i.next(); languages.append(lang); if (sz < langs.size() - 1) { languages.append(";"); } sz++; } store.setSupportedlanguages(languages.toString()); } else { MessageUtil.addErrorMessage(super.getServletRequest(), LabelUtil.getInstance().getText("message.confirmation.languagerequired")); store.setSupportedlanguages(Constants.ENGLISH_CODE); return SUCCESS; } store.setStorename(merchantProfile.getStorename()); store.setStoreemailaddress(merchantProfile.getStoreemailaddress()); store.setStoreaddress(merchantProfile.getStoreaddress()); store.setStorecity(merchantProfile.getStorecity()); store.setStorepostalcode(merchantProfile.getStorepostalcode()); store.setCountry(merchantProfile.getCountry()); store.setZone(merchantProfile.getZone()); store.setCurrency(merchantProfile.getCurrency()); if (!StringUtils.isBlank(merchantProfile.getWeightunitcode())) { store.setWeightunitcode(merchantProfile.getWeightunitcode().trim()); } if (!StringUtils.isBlank(merchantProfile.getSeizeunitcode())) { store.setSeizeunitcode(merchantProfile.getSeizeunitcode().trim()); } store.setStorelogo(merchantProfile.getStorelogo()); store.setStorephone(merchantProfile.getStorephone()); store.setBgcolorcode(merchantProfile.getBgcolorcode()); store.setContinueshoppingurl(merchantProfile.getContinueshoppingurl()); store.setUseCache(merchantProfile.isUseCache()); store.setDomainName(merchantProfile.getDomainName()); store.setMerchantId(merchantid.intValue()); store.setLastModified(new java.util.Date(dt.getTime())); if (!StringUtils.isNumeric(merchantProfile.getZone())) { store.setStorestateprovince(merchantProfile.getStorestateprovince()); ctx.setZoneid(0); } else {// get the value from zone ctx.setZoneid(Integer.parseInt(merchantProfile.getZone())); Map zones = RefCache.getInstance() .getAllZonesmap(LanguageUtil.getLanguageNumberCode(ctx.getLang())); Zone z = (Zone) zones.get(Integer.parseInt(merchantProfile.getZone())); if (z != null) { store.setStorestateprovince(z.getZoneName());// @todo, // localization } else { store.setStorestateprovince("N/A"); } } if (!StringUtils.isBlank(this.getInBusinessSince())) { Date businessDate = DateUtil.getDate(this.getInBusinessSince()); store.setInBusinessSince(businessDate); } super.prepareSelections(store.getCountry()); mservice.saveOrUpdateMerchantStore(store); super.getContext().setExistingStore(true); // refresh context ctx.setCountryid(merchantProfile.getCountry()); ctx.setSizeunit(merchantProfile.getSeizeunitcode()); ctx.setWeightunit(merchantProfile.getWeightunitcode()); LanguageHelper.setLanguages(languages.toString(), ctx); ctx.setCurrency(merchantProfile.getCurrency()); // refresh the locale Map countries = RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(ctx.getLang())); Country c = (Country) countries.get(merchantProfile.getCountry()); Locale locale = new Locale("en", c.getCountryIsoCode2()); ActionContext.getContext().setLocale(locale); Map sessions = ActionContext.getContext().getSession(); sessions.put("WW_TRANS_I18N_LOCALE", locale); MessageUtil.addMessage(super.getServletRequest(), LabelUtil.getInstance().getText("message.confirmation.success")); } catch (Exception e) { log.error(e); super.setTechnicalMessage(); } return SUCCESS; }
From source file:br.com.nordestefomento.jrimum.vallia.digitoverificador.Modulo.java
/** * <p>// ww w . j a v a 2s .c o m * Realiza o clculo da soma na forma do mdulo 10. * </p> * <p> * O mdulo 10 funciona da seguinte maneira: * </p> * <p> * Cada dgito do nmero, comeando da direita para a esquerda (menos * significativo para o mais significativo), multiplicado pelo nmeros * limite mnimo, limite mnimo + 1, limite mnimo + 2 e assim * sucessivamente at o limite mxmio definido, ento inicia-se novamente a * contagem. * </p> * <p> * Exemplo para o nmero <tt>123456</tt>: * * <pre> * +---+---+---+---+---+---+ * | 1 | 2 | 3 | 4 | 5 | 6 | * +---+---+---+---+---+---+ * | | | | | | * x1 x2 x1 x2 x1 x2 * | | | | | | * =1 =4 =3 =8 =5 =[ 3 <= ( 1 + 2 <==12 ) ] = 24 * +---+---+---+---+---+-> = (24 / 10) = 3, resto 3; Ento o mdulo igual a 3. * </pre> * * </p> * * <p> * Geralmente os limites para o mdulo 10 so mnimo 1 e mximo 2 apenas. * </p> * * @param numero * @param limiteMin * @param limiteMax * @return soma sequencial usada no clculo do mdulo * @throws IllegalArgumentException * * @since 0.2 */ public static int calculeSomaSequencialMod10(String numero, int limiteMin, int limiteMax) throws IllegalArgumentException { int produto = 0; int peso = 0; int soma = 0; if (StringUtils.isNotBlank(numero) && StringUtils.isNumeric(numero)) { StringBuilder sb = new StringBuilder(numero); sb.reverse(); peso = limiteMax; for (char c : sb.toString().toCharArray()) { produto = peso * Character.getNumericValue(c); if (produto > 9) { soma += produto / 10; soma += produto % 10; } else soma += produto; peso = (peso == limiteMax) ? limiteMin : limiteMax; } } else throw new IllegalArgumentException(O_ARGUMENTO_DEVE_CONTER_APENAS_NUMEROS); return soma; }
From source file:com.evolveum.midpoint.web.page.admin.configuration.PageSystemConfiguration.java
@Override protected void onBeforeRender() { super.onBeforeRender(); if (!initialized) { PageParameters params = getPageParameters(); StringValue val = params.get(SELECTED_TAB_INDEX); String value = null;// w ww . j a v a 2s . c o m if (val != null && !val.isNull()) { value = val.toString(); } int index = StringUtils.isNumeric(value) ? Integer.parseInt(value) : CONFIGURATION_TAB_BASIC; getTabPanel().setSelectedTab(index); initialized = true; } }
From source file:fr.paris.lutece.plugins.calendar.service.CalendarService.java
/** * Reset the cache from the given agenda ID * @param strAgendaId the agenda ID//from w w w . j a va2 s .co m */ public void removeCache(String strAgendaId) { if (StringUtils.isNotBlank(strAgendaId) && StringUtils.isNumeric(strAgendaId)) { int nAgendaId = Integer.parseInt(strAgendaId); removeCache(nAgendaId); } }
From source file:com.cloudera.whirr.cm.server.impl.CmServerImpl.java
private static int getVersionApi(String version, String versionApi) throws CmServerException { Integer versionApiValidated = null; if (version == null || version.equals("")) { version = VERSION_CM_API_MATRIX_CM_MAX; }/*from w ww . ja v a2 s . c om*/ if (!version.contains(".")) { String versionLatest = null; for (String versionIterator : VERSION_CM_API_MATRIX.keySet()) { if (versionIterator.startsWith(version)) { versionLatest = versionIterator; } } version = versionLatest; } if (version != null) { ArtifactVersion versionArtifact = new DefaultArtifactVersion(version); for (String versionUpperBound : VERSION_CM_API_MATRIX.keySet()) { if (versionArtifact.compareTo(new DefaultArtifactVersion(versionUpperBound)) <= 0) { versionApiValidated = VERSION_CM_API_MATRIX.get(versionUpperBound); break; } if (versionApiValidated == null) { versionApiValidated = VERSION_CM_API_MATRIX_API_MAX; } } } if (version == null || versionApi != null && !versionApi.equals("") && (new DefaultArtifactVersion(versionApi) .compareTo(new DefaultArtifactVersion(versionApiValidated.toString())) > 0 || new DefaultArtifactVersion(versionApi) .compareTo(new DefaultArtifactVersion("" + CM_VERSION_API_EARLIEST)) < 0)) { throw new CmServerException("Requested CM API version [" + versionApi + "] of CM version [" + version + "] could not be reconciled with CM API version matrix " + VERSION_CM_API_MATRIX); } if (versionApi != null && !StringUtils.isNumeric(versionApi)) { throw new CmServerException("CM API version requested is non-numeric [" + versionApi + "]"); } return versionApi == null ? versionApiValidated : Integer.parseInt(versionApi); }
From source file:net.mindengine.oculus.frontend.service.project.JdbcProjectDAO.java
public SqlSearchCondition createSearchCondition(ProjectSearchFilter filter) { SqlSearchCondition condition = new SqlSearchCondition(); // Name/* w w w .ja v a 2 s. co m*/ { String name = filter.getName(); if (name != null && !name.isEmpty()) { if (name.contains(",")) { condition.append(condition.createArrayCondition(name, "p.name")); } else { condition.append(condition.createSimpleCondition(name, true, "p.name")); } } } // Project { String project = filter.getProject(); if (project != null && !project.isEmpty()) { // checking whether it is an id of project or just a name if (StringUtils.isNumeric(project)) { // The id of a project was provided condition.append(condition.createSimpleCondition(false, "pp.id", project)); } else { if (project.contains(",")) { condition.append(condition.createArrayCondition(project, "pp.name")); } else { condition.append(condition.createSimpleCondition(project, true, "pp.name")); } } } } // User { String user = filter.getDesigner(); if (user != null && !user.isEmpty()) { if (user.contains(",")) { condition.append(condition.createArrayCondition(user, "u.name", "u.login")); } else { condition.append(condition.createSimpleCondition(user, true, "u.name", "u.login")); } } } return condition; }
From source file:com.impetus.client.redis.RedisClientFactory.java
/** * Retrieving connection from connection pool. * // w ww .j a v a 2 s .c om * @return returns jedis instance. */ Jedis getConnection() { if (logger.isDebugEnabled()) logger.info("borrowing connection from pool"); Object poolOrConnection = getConnectionPoolOrConnection(); if (poolOrConnection != null && poolOrConnection instanceof JedisPool) { Jedis connection = ((JedisPool) getConnectionPoolOrConnection()).getResource(); connection.getClient().setTimeoutInfinite(); Map props = RedisPropertyReader.rsmd.getProperties(); // set external xml properties. if (props != null) { // props. for (Object key : props.keySet()) { connection.configSet(key.toString(), props.get(key).toString()); } } return connection; } else { PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = puMetadata.getProperties(); String contactNode = null; String defaultPort = null; String password = null; if (externalProperties != null) { contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES); defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT); password = (String) externalProperties.get(PersistenceProperties.KUNDERA_PASSWORD); } if (contactNode == null) { contactNode = RedisPropertyReader.rsmd.getHost() != null ? RedisPropertyReader.rsmd.getHost() : (String) props.get(PersistenceProperties.KUNDERA_NODES); } if (defaultPort == null) { defaultPort = RedisPropertyReader.rsmd.getPort() != null ? RedisPropertyReader.rsmd.getPort() : (String) props.get(PersistenceProperties.KUNDERA_PORT); } if (password == null) { password = RedisPropertyReader.rsmd.getPassword() != null ? RedisPropertyReader.rsmd.getPassword() : (String) props.get(PersistenceProperties.KUNDERA_PASSWORD); } if (defaultPort == null || !StringUtils.isNumeric(defaultPort)) { throw new RuntimeException("Invalid port provided: " + defaultPort); } Jedis connection = new Jedis(contactNode, Integer.parseInt(defaultPort)); if (password != null) { connection.auth(password); } connection.connect(); return connection; } }
From source file:fr.paris.lutece.plugins.crm.modules.mylutece.web.CRMMyluteceJspBean.java
/** * Do reinit password./* www. j a v a2 s.co m*/ * * @param request the request * @return the string */ public String doReinitPassword(HttpServletRequest request) { String strIdCRMUser = request.getParameter(PARAMETER_ID_CRM_USER); if (StringUtils.isBlank(strIdCRMUser) || !StringUtils.isNumeric(strIdCRMUser)) { return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } int nIdCRMUser = Integer.parseInt(strIdCRMUser); CRMUser user = _crmUserService.findByPrimaryKey(nIdCRMUser); if (user != null) { MyLuteceUserManager.doReinitPassword(user.getUserGuid(), request, getLocale()); } return getUrlManageUsers(request, true).getUrl(); }
From source file:fr.paris.lutece.plugins.crm.web.category.CategoryJspBean.java
/** * Process the change form of a category * @param request The Http request/*from w w w .j a va 2 s. co m*/ * @return The Jsp URL of the process result */ public String doModifyCategory(HttpServletRequest request) { String strUrl = StringUtils.EMPTY; String strCategoryId = request.getParameter(CRMConstants.PARAMETER_CATEGORY_ID_CATEGORY); if (StringUtils.isNotBlank(strCategoryId) && StringUtils.isNumeric(strCategoryId)) { String strName = request.getParameter(CRMConstants.PARAMETER_CATEGORY_NAME); String strDescription = request.getParameter(CRMConstants.PARAMETER_CATEGORY_DESCRIPTION); if (StringUtils.isNotBlank(strName) && StringUtils.isNotBlank(strDescription)) { int nId = Integer.parseInt(strCategoryId); Category category = _categoryService.findByPrimaryKey(nId); if (category != null) { category.setName(strName); category.setDescription(strDescription); _categoryService.updateCategory(category); strUrl = JSP_REDIRECT_TO_MANAGE_CATEGORIES; } else { strUrl = AdminMessageService.getMessageUrl(request, CRMConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP); } } else { strUrl = AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } } else { strUrl = AdminMessageService.getMessageUrl(request, CRMConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP); } return strUrl; }