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.workflow.modules.mappings.web.component.ActionMappingTypeComponent.java
/** * {@inheritDoc}// w w w . j a va 2s .co m */ @Override public void addParameter(HttpServletRequest request, UrlItem url) { super.addParameter(request, url); String strIdWorkflow = request.getParameter(PARAMETER_ID_WORKFLOW); if (StringUtils.isNotBlank(strIdWorkflow) && StringUtils.isNumeric(strIdWorkflow)) { url.addParameter(PARAMETER_ID_WORKFLOW, strIdWorkflow); } }
From source file:eu.eidas.auth.commons.EIDASUtil.java
/** * Gets the Eidas error message in the saml message if exists! * * @param errorMessage The message to get in the saml message if exists; * @return the error message if exists. Returns the original message otherwise. *//* www . jav a 2s . c o m*/ public static String getEidasErrorMessage(final String errorMessage) { if (StringUtils.isNotBlank(errorMessage) && errorMessage.indexOf(EIDASValues.ERROR_MESSAGE_SEP.toString()) >= 0) { final String[] msgSplitted = errorMessage.split(EIDASValues.ERROR_MESSAGE_SEP.toString()); if (msgSplitted.length == 2 && StringUtils.isNumeric(msgSplitted[0])) { return msgSplitted[1]; } } return errorMessage; }
From source file:com.enonic.cms.core.portal.PageRequestContextResolver.java
private boolean pathMatchesPermaLinkPattern(Path pathToMenuItem) { // Pattern for content on root: /<key>/<title> final boolean correctNumberOfElements = pathToMenuItem.numberOfElements() == CONTENT_ON_ROOT_PATH_ELEMENTS; if (!correctNumberOfElements) { return false; }/*from w w w .ja v a 2 s . c o m*/ String firstElement = pathToMenuItem.getFirstPathElement(); if (!StringUtils.isNumeric(firstElement)) { return false; } return true; }
From source file:fr.paris.lutece.plugins.directory.web.action.MassWorkflowDirectoryAction.java
/** * Redirects to {@link #JSP_DO_PROCESS_ACTION_WORKFLOW} *//* w w w .j av a2 s . com*/ public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response, AdminUser adminUser, DirectoryAdminSearchFields sessionFields) throws AccessDeniedException { DefaultPluginActionResult result = new DefaultPluginActionResult(); String strRedirect = StringUtils.EMPTY; if ((sessionFields.getSelectedRecords() != null) && !sessionFields.getSelectedRecords().isEmpty()) { String strIdDirectory = request.getParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY); String strIdAction = request.getParameter(DirectoryUtils.PARAMETER_ID_ACTION); UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_DO_PROCESS_ACTION_WORKFLOW); url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY, strIdDirectory); url.addParameter(DirectoryUtils.PARAMETER_ID_ACTION, strIdAction); url.addParameter(DirectoryUtils.PARAMETER_SHOW_ACTION_RESULT, DirectoryUtils.CONSTANT_TRUE); for (String strIdRecord : sessionFields.getSelectedRecords()) { if (StringUtils.isNotBlank(strIdRecord) && StringUtils.isNumeric(strIdRecord)) { url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD, strIdRecord); } } strRedirect = url.getUrl(); } else { strRedirect = AdminMessageService.getMessageUrl(request, DirectoryUtils.MESSAGE_SELECT_RECORDS, AdminMessage.TYPE_INFO); } result.setRedirect(strRedirect); return result; }
From source file:br.com.nordestefomento.jrimum.vallia.digitoverificador.Modulo.java
/** * <p>//w w w .ja v a 2 s.c om * Realiza o clculo da soma na forma do mdulo 11. * </p> * <p> * O mdulo 11 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>654321</tt>: * * <pre> * +---+---+---+---+---+---+ * | 6 | 5 | 4 | 3 | 2 | 1 | * +---+---+---+---+---+---+ * | | | | | | * x7 x6 x5 x4 x3 x2 * | | | | | | * =42 =30 =20 =12 =6 =2 * +---+---+---+---+---+-> * </pre * * </p> * * @param numero * @param limiteMin * @param limiteMax * @return * @throws IllegalArgumentException * * @since 0.2 */ public static int calculeSomaSequencialMod11(String numero, int limiteMin, int limiteMax) throws IllegalArgumentException { int peso = 0; int soma = 0; if (StringUtils.isNotBlank(numero) && StringUtils.isNumeric(numero)) { StringBuilder sb = new StringBuilder(numero); sb.reverse(); peso = limiteMin; for (char c : sb.toString().toCharArray()) { soma += peso * Character.getNumericValue(c); peso++; if (peso > limiteMax) peso = limiteMin; } } else throw new IllegalArgumentException(O_ARGUMENTO_DEVE_CONTER_APENAS_NUMEROS); return soma; }
From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java
public static Date parseDate(String dateStr, String... parsePatterns) throws ParseException { if (dateStr == null || parsePatterns == null) { throw new IllegalArgumentException("Date and Patterns must not be null"); }/*w w w. ja va2s . c om*/ String strDate = dateStr; //do year correction. (partial year >=50 will be 1999 and <50 will be 2000) String[] parts = StringUtils.split(dateStr, '/'); int len = parts.length; if (len != 3 || parts[0].length() > 2 || parts[1].length() > 2) throw new ParseException("Unable to parse the date " + strDate, -1); String yStr = parts[2]; if (!(yStr.length() == 4 || yStr.length() == 2 || yStr.length() == 10)) throw new ParseException("Unable to parse the date " + strDate, -1); if (yStr.length() == 2 && StringUtils.isNumeric(yStr)) { if (Integer.parseInt(yStr) < 50) yStr = "20" + yStr; else yStr = "19" + yStr; parts[2] = yStr; strDate = StringUtils.join(parts, '/'); } //BJ: date formats are not thread save, so we need to create one each time. SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { parser = new SimpleDateFormat(parsePatterns[0]); } else { parser.applyPattern(parsePatterns[i]); } pos.setIndex(0); Date date = parser.parse(strDate, pos); if (date != null && pos.getIndex() == strDate.length()) { return date; } } throw new ParseException("Unable to parse the date: " + strDate, -1); }
From source file:net.bible.service.format.osistohtml.NoteAndReferenceHandler.java
/** create a link tag from an OSISref and the content of the tag *//*from w w w . j a va 2s . com*/ private String getReferenceTag(String reference, String content) { StringBuilder result = new StringBuilder(); try { //JSword does not know the basis (default book) so prepend it if it looks like JSword failed to work it out //We only need to worry about the first ref because JSword uses the first ref as the basis for the subsequent refs // if content starts with a number and is not followed directly by an alpha char e.g. 1Sa if (reference == null && content != null && content.length() > 0 && StringUtils.isNumeric(content.subSequence(0, 1)) && (content.length() < 2 || !StringUtils.isAlphaSpace(content.subSequence(1, 2)))) { // maybe should use VerseRangeFactory.fromstring(orig, basis) // this check for a colon to see if the first ref is verse:chap is not perfect but it will do until JSword adds a fix int firstColonPos = content.indexOf(":"); boolean isVerseAndChapter = firstColonPos > 0 && firstColonPos < 4; if (isVerseAndChapter) { reference = parameters.getBasisRef().getBook().getOSIS() + " " + content; } else { reference = parameters.getBasisRef().getBook().getOSIS() + " " + parameters.getBasisRef().getChapter() + ":" + content; } log.debug("Patched reference:" + reference); } else if (reference == null) { reference = content; } Passage ref = (Passage) PassageKeyFactory.instance().getKey(reference); boolean isSingleVerse = ref.countVerses() == 1; boolean isSimpleContent = content.length() < 3 && content.length() > 0; Iterator<Key> it = ref.rangeIterator(RestrictionType.CHAPTER); if (isSingleVerse && isSimpleContent) { // simple verse no e.g. 1 or 2 preceding the actual verse in TSK result.append("<a href='").append(Constants.BIBLE_PROTOCOL).append(":") .append(it.next().getOsisRef()).append("'>"); result.append(content); result.append("</a>"); } else { // multiple complex references boolean isFirst = true; while (it.hasNext()) { Key key = it.next(); if (!isFirst) { result.append(" "); } result.append("<a href='").append(Constants.BIBLE_PROTOCOL).append(":") .append(key.iterator().next().getOsisRef()).append("'>"); result.append(key); result.append("</a> "); isFirst = false; } } } catch (Exception e) { log.error("Error parsing OSIS reference:" + reference, e); // just return the content with no html markup result.append(content); } return result.toString(); }
From source file:fr.paris.lutece.plugins.extend.modules.rating.web.type.VoteTypeJspBean.java
/** * Do modify vote type.//from w w w.j av a 2 s.c o m * * @param request the request * @return the string */ public String doModifyVoteType(HttpServletRequest request) { String strCancel = request.getParameter(RatingConstants.PARAMETER_CANCEL); if (StringUtils.isBlank(strCancel)) { String strIdVoteType = request.getParameter(RatingConstants.PARAMETER_ID_VOTE_TYPE); if (StringUtils.isBlank(strIdVoteType) || !StringUtils.isNumeric(strIdVoteType)) { return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } int nIdVoteType = Integer.parseInt(strIdVoteType); VoteType voteType = _voteService.findByPrimaryKey(nIdVoteType, true); if (voteType == null) { return AdminMessageService.getMessageUrl(request, RatingConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP); } populate(voteType, request); // Check mandatory fields Set<ConstraintViolation<VoteType>> constraintViolations = BeanValidationUtil.validate(voteType); if (constraintViolations.size() > 0) { Object[] params = { ExtendUtils.buildStopMessage(constraintViolations) }; return AdminMessageService.getMessageUrl(request, RatingConstants.MESSAGE_STOP_GENERIC_MESSAGE, params, AdminMessage.TYPE_STOP); } _voteService.update(voteType); } return AppPathService.getBaseUrl(request) + JSP_URL_MANAGE_VOTE_TYPES; }
From source file:fr.paris.lutece.portal.service.admin.ImportAdminUserService.java
/** * {@inheritDoc}//from w w w. j a v a 2s . c om */ @Override protected List<CSVMessageDescriptor> readLineOfCSVFile(String[] strLineDataArray, int nLineNumber, Locale locale, String strBaseUrl) { List<CSVMessageDescriptor> listMessages = new ArrayList<CSVMessageDescriptor>(); int nIndex = 0; String strAccessCode = strLineDataArray[nIndex++]; String strLastName = strLineDataArray[nIndex++]; String strFirstName = strLineDataArray[nIndex++]; String strEmail = strLineDataArray[nIndex++]; boolean bUpdateUser = getUpdateExistingUsers(); int nUserId = 0; if (bUpdateUser) { int nAccessCodeUserId = AdminUserHome.checkAccessCodeAlreadyInUse(strAccessCode); int nEmailUserId = AdminUserHome.checkEmailAlreadyInUse(strEmail); if (nAccessCodeUserId > 0) { nUserId = nAccessCodeUserId; } else if (nEmailUserId > 0) { nUserId = nEmailUserId; } bUpdateUser = nUserId > 0; } String strStatus = strLineDataArray[nIndex++]; int nStatus = 0; if (StringUtils.isNotEmpty(strStatus) && StringUtils.isNumeric(strStatus)) { nStatus = Integer.parseInt(strStatus); } else { Object[] args = { strLastName, strFirstName, nStatus }; String strMessage = I18nService.getLocalizedString(MESSAGE_NO_STATUS, args, locale); CSVMessageDescriptor message = new CSVMessageDescriptor(CSVMessageLevel.INFO, nLineNumber, strMessage); listMessages.add(message); } String strLocale = strLineDataArray[nIndex++]; String strLevelUser = strLineDataArray[nIndex++]; int nLevelUser = 3; if (StringUtils.isNotEmpty(strLevelUser) && StringUtils.isNumeric(strLevelUser)) { nLevelUser = Integer.parseInt(strLevelUser); } else { Object[] args = { strLastName, strFirstName, nLevelUser }; String strMessage = I18nService.getLocalizedString(MESSAGE_NO_LEVEL, args, locale); CSVMessageDescriptor message = new CSVMessageDescriptor(CSVMessageLevel.INFO, nLineNumber, strMessage); listMessages.add(message); } // We ignore the rest password attribute because we set it to true anyway. // String strResetPassword = strLineDataArray[nIndex++]; nIndex++; boolean bResetPassword = true; String strAccessibilityMode = strLineDataArray[nIndex++]; boolean bAccessibilityMode = Boolean.parseBoolean(strAccessibilityMode); // We ignore the password max valid date attribute because we changed the password. // String strPasswordMaxValidDate = strLineDataArray[nIndex++]; nIndex++; Timestamp passwordMaxValidDate = null; // We ignore the account max valid date attribute // String strAccountMaxValidDate = strLineDataArray[nIndex++]; nIndex++; Timestamp accountMaxValidDate = AdminUserService.getAccountMaxValidDate(); String strDateLastLogin = strLineDataArray[nIndex++]; Timestamp dateLastLogin = new Timestamp(AdminUser.DEFAULT_DATE_LAST_LOGIN.getTime()); if (StringUtils.isNotBlank(strDateLastLogin)) { DateFormat dateFormat = new SimpleDateFormat(); Date dateParsed; try { dateParsed = dateFormat.parse(strDateLastLogin); } catch (ParseException e) { AppLogService.error(e.getMessage(), e); dateParsed = null; } if (dateParsed != null) { dateLastLogin = new Timestamp(dateParsed.getTime()); } } AdminUser user = null; if (bUpdateUser) { user = AdminUserHome.findByPrimaryKey(nUserId); } else { user = new LuteceDefaultAdminUser(); } user.setAccessCode(strAccessCode); user.setLastName(strLastName); user.setFirstName(strFirstName); user.setEmail(strEmail); user.setStatus(nStatus); user.setUserLevel(nLevelUser); user.setLocale(new Locale(strLocale)); user.setAccessibilityMode(bAccessibilityMode); if (bUpdateUser) { user.setUserId(nUserId); // We update the user AdminUserHome.update(user); } else { // We create the user user.setPasswordReset(bResetPassword); user.setPasswordMaxValidDate(passwordMaxValidDate); user.setAccountMaxValidDate(accountMaxValidDate); user.setDateLastLogin(dateLastLogin); if (AdminAuthenticationService.getInstance().isDefaultModuleUsed()) { LuteceDefaultAdminUser defaultAdminUser = (LuteceDefaultAdminUser) user; String strPassword = AdminUserService.makePassword(); String strEncryptedPassword = AdminUserService.encryptPassword(strPassword); defaultAdminUser.setPassword(strEncryptedPassword); AdminUserHome.create(defaultAdminUser); // We un-encrypt the password to send it in an email defaultAdminUser.setPassword(strPassword); AdminUserService.notifyUser(AppPathService.getProdUrl(strBaseUrl), user, PROPERTY_MESSAGE_EMAIL_SUBJECT_NOTIFY_USER, TEMPLATE_NOTIFY_USER); } else { AdminUserHome.create(user); } } // We remove any previous right, roles, workgroup adn attributes of the user AdminUserHome.removeAllRightsForUser(user.getUserId()); AdminUserHome.removeAllRolesForUser(user.getUserId()); AdminUserFieldFilter auFieldFilter = new AdminUserFieldFilter(); auFieldFilter.setIdUser(user.getUserId()); AdminUserFieldHome.removeByFilter(auFieldFilter); // We get every attribute, role, right and workgroup of the user Map<Integer, List<String>> mapAttributesValues = new HashMap<Integer, List<String>>(); List<String> listAdminRights = new ArrayList<String>(); List<String> listAdminRoles = new ArrayList<String>(); List<String> listAdminWorkgroups = new ArrayList<String>(); while (nIndex < strLineDataArray.length) { String strValue = strLineDataArray[nIndex]; if (StringUtils.isNotBlank(strValue) && (strValue.indexOf(getAttributesSeparator()) > 0)) { int nSeparatorIndex = strValue.indexOf(getAttributesSeparator()); String strLineId = strValue.substring(0, nSeparatorIndex); if (StringUtils.isNotBlank(strLineId)) { if (StringUtils.equalsIgnoreCase(strLineId, CONSTANT_RIGHT)) { listAdminRights.add(strValue.substring(nSeparatorIndex + 1)); } else if (StringUtils.equalsIgnoreCase(strLineId, CONSTANT_ROLE)) { listAdminRoles.add(strValue.substring(nSeparatorIndex + 1)); } else if (StringUtils.equalsIgnoreCase(strLineId, CONSTANT_WORKGROUP)) { listAdminWorkgroups.add(strValue.substring(nSeparatorIndex + 1)); } else { int nAttributeId = Integer.parseInt(strLineId); String strAttributeValue = strValue.substring(nSeparatorIndex + 1); List<String> listValues = mapAttributesValues.get(nAttributeId); if (listValues == null) { listValues = new ArrayList<String>(); } listValues.add(strAttributeValue); mapAttributesValues.put(nAttributeId, listValues); } } } nIndex++; } // We create rights for (String strRight : listAdminRights) { AdminUserHome.createRightForUser(user.getUserId(), strRight); } // We create roles for (String strRole : listAdminRoles) { AdminUserHome.createRoleForUser(user.getUserId(), strRole); } // We create workgroups for (String strWorkgoup : listAdminWorkgroups) { AdminWorkgroupHome.addUserForWorkgroup(user, strWorkgoup); } List<IAttribute> listAttributes = _attributeService.getAllAttributesWithoutFields(locale); Plugin pluginCore = PluginService.getCore(); // We save the attributes found for (IAttribute attribute : listAttributes) { if (attribute instanceof ISimpleValuesAttributes) { List<String> listValues = mapAttributesValues.get(attribute.getIdAttribute()); if ((listValues != null) && (listValues.size() > 0)) { int nIdField = 0; boolean bCoreAttribute = (attribute.getPlugin() == null) || StringUtils.equals(pluginCore.getName(), attribute.getPlugin().getName()); for (String strValue : listValues) { int nSeparatorIndex = strValue.indexOf(getAttributesSeparator()); if (nSeparatorIndex >= 0) { nIdField = 0; try { nIdField = Integer.parseInt(strValue.substring(0, nSeparatorIndex)); } catch (NumberFormatException e) { nIdField = 0; } strValue = strValue.substring(nSeparatorIndex + 1); } else { nIdField = 0; } String[] strValues = { strValue }; try { List<AdminUserField> listUserFields = ((ISimpleValuesAttributes) attribute) .getUserFieldsData(strValues, user); for (AdminUserField userField : listUserFields) { if (userField != null) { userField.getAttributeField().setIdField(nIdField); AdminUserFieldHome.create(userField); } } if (!bCoreAttribute) { for (AdminUserFieldListenerService adminUserFieldListenerService : SpringContextService .getBeansOfType(AdminUserFieldListenerService.class)) { adminUserFieldListenerService.doCreateUserFields(user, listUserFields, locale); } } } catch (Exception e) { AppLogService.error(e.getMessage(), e); String strErrorMessage = I18nService .getLocalizedString(MESSAGE_ERROR_IMPORTING_ATTRIBUTES, locale); CSVMessageDescriptor error = new CSVMessageDescriptor(CSVMessageLevel.ERROR, nLineNumber, strErrorMessage); listMessages.add(error); } } } } } return listMessages; }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity.java
public String buildIdentifer() { String typeIdentifier = getResourceRelationType().getIdentifierOrTypeBName(); if (StringUtils.isNotBlank(getIdentifier()) && !StringUtils.isNumeric(getIdentifier())) { return getIdentifier(); } else if (masterResource.getResourceType().isDefaultResourceType()) { // use localPortId if available typeIdentifier = (slaveResource.getLocalPortId() != null) ? slaveResource.getLocalPortId() : slaveResource.getName(); }/* w w w . j a v a2 s. c om*/ if (StringUtils.isNotBlank(getIdentifier()) && StringUtils.isNumeric(getIdentifier())) { typeIdentifier += "_" + getIdentifier(); } return typeIdentifier; }