List of usage examples for org.apache.commons.validator GenericValidator isEmail
public static boolean isEmail(String value)
Checks if a field has a valid e-mail address.
From source file:gov.nih.nci.cabig.caaers.validation.fields.validators.EmailValidator.java
@Override public boolean isValid(Object fieldValue) { if (fieldValue == null) return true; // null email is considered as valid return GenericValidator.isEmail(fieldValue.toString()); }
From source file:com.ao.service.ValidatorService.java
/** * Checks if the given email address is valid, or not. * @param email The email address./*w ww . jav a 2 s . co m*/ * @return True if the email is valid, false otherwise. */ public static boolean validEmail(String email) { return GenericValidator.isEmail(email); }
From source file:bookproject.web.action.SavePublisherAction.java
@Override public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String publisherName = request.getParameter("name"); String address = request.getParameter("address"); String email = request.getParameter("email"); if (!GenericValidator.isBlankOrNull(publisherName) && !GenericValidator.isBlankOrNull(address) && GenericValidator.isEmail(email)) { Publisher publisher = new Publisher(); publisher.setName(publisherName); publisher.setAddress(address);//from www . j av a 2 s .c o m publisher.setEmail(email); boolean success = dbHelper.savePublisher(publisher); // page = WebConstants.PAGE_PUBLISHER_LIST; page = "cs?action=showPublisherList"; forward = false; } else { this.errorList.clear(); this.errorList.add("Name, address and email can not empty"); request.setAttribute(WebConstants.ATTR_ERROR_LIST, errorList); page = WebConstants.PAGE_ADD_PUBLISHER; forward = true; } }
From source file:com.surveypanel.form.validation.EmailValidation.java
@Override public void validate(QuestionImpl question, FormData formData, Locale locale, Map<String, String> config, ValidationResult validationResult) throws Exception { String errorMsg = config.containsKey("errorKey") ? config.get("errorKey") : "form.error.email"; if (!question.isMulti()) { Object value = formData.getValue(); if (value instanceof String) { if (!GenericValidator.isEmail((String) value)) { validationResult//from ww w .ja v a2 s . co m .addError(qDefinition.getText(errorMsg, new Object[] { question.getName() }, locale)); } } } }
From source file:com.panet.imeta.job.entry.validator.EmailValidator.java
public boolean validate(CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { String value = null;//from ww w . j av a2s . c om value = getValueAsString(source, propertyName); if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) { JobEntryValidatorUtils.addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME)); return false; } else { return true; } }
From source file:com.primeleaf.krystal.web.action.console.ShareDocumentAction.java
public WebView execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); User loggedInUser = (User) session.getAttribute(HTTPConstants.SESSION_KRYSTAL); try {/*ww w .ja v a 2 s . co m*/ String documentid = request.getParameter("documentid") != null ? request.getParameter("documentid") : ""; String revisionid = request.getParameter("revisionid") != null ? request.getParameter("revisionid") : ""; String emailId = request.getParameter("txtEmail") != null ? request.getParameter("txtEmail") : ""; String userComments = request.getParameter("txtComments") != null ? request.getParameter("txtComments") : ""; String emailIDs[] = emailId.split(","); for (String emailAddress : emailIDs) { if (!GenericValidator.isEmail(emailAddress)) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid input"); return (new AJAXResponseView(request, response)); } } int documentId = Integer.parseInt(documentid); Document document = DocumentDAO.getInstance().readDocumentById(documentId); if (document == null) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid document"); return (new AJAXResponseView(request, response)); } DocumentRevision documentRevision = DocumentRevisionDAO.getInstance() .readDocumentRevisionById(documentId, revisionid); if (documentRevision == null) { request.setAttribute(HTTPConstants.REQUEST_ERROR, "Invalid document"); return (new AJAXResponseView(request, response)); } document.setRevisionId(revisionid); for (String emailAddress : emailIDs) { SharedDocument sharedDocument = new SharedDocument(); sharedDocument.setUsername(loggedInUser.getUserName()); sharedDocument.setObjectId(documentId); sharedDocument.setRevisionId(revisionid); sharedDocument.setEmailId(emailAddress); String comments = ""; EmailMessage emailMessage = new EmailMessage(); emailMessage.setSubject("Shared Document"); emailMessage.setFrom(loggedInUser.getUserEmail()); StringBuffer message = new StringBuffer(); message.append("Hello,"); message.append("<p>" + loggedInUser.getRealName() + " has shared a document with you.</p>"); emailMessage.setTo(emailAddress); sharedDocument.setValidity(Integer.MAX_VALUE); DocumentManager dm = new DocumentManager(); documentRevision = dm.retreiveDocument(document); emailMessage.setAttachmentFile(documentRevision.getDocumentFile()); message.append("<p>Please find attached document.</p>"); if (userComments.trim().length() > 0) {//User has put some comments message.append("<p>Message from :" + loggedInUser.getRealName() + "</p>"); message.append("<p><i>" + userComments + "</i></p>"); } message.append("<p>Regards,<br/>DMS Administrator</p>"); emailMessage.setMessage(message.toString()); emailMessage.send(); document = DocumentDAO.getInstance().readDocumentById(documentId); Date lastAccessed = new Date(); document.setLastAccessed(new java.sql.Timestamp(lastAccessed.getTime())); DocumentDAO.getInstance().updateDocument(document); AuditLogManager.log(new AuditLogRecord(Integer.parseInt(documentid), AuditLogRecord.OBJECT_DOCUMENT, AuditLogRecord.ACTION_SHARED, loggedInUser.getUserName(), request.getRemoteAddr(), AuditLogRecord.LEVEL_INFO, emailAddress, comments)); } request.setAttribute(HTTPConstants.REQUEST_MESSAGE, "Document shared successfully"); } catch (Exception e) { e.printStackTrace(); } return (new AJAXResponseView(request, response)); }
From source file:com.ssbusy.register.validator.MyRegisterCustomerValidator.java
public void validate(Object obj, Errors errors, boolean useEmailForUsername) { RegisterCustomerForm form = (RegisterCustomerForm) obj; Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername()); if (customerFromDb != null) { if (useEmailForUsername) { errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null); } else {/*from w w w . jav a2 s.co m*/ errors.rejectValue("customer.username", "username.used", null, null); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", // "firstName.required"); // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", // "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (!errors.hasErrors()) { if (form.getPassword().length() < 4 || form.getPassword().length() > 15) { errors.rejectValue("password", "password.invalid", null, null); } if (!form.getPassword().equals(form.getPasswordConfirm())) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) { errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null); } } }
From source file:gov.nih.nci.cabig.caaers.service.UnreportedSAENotificationProcessService.java
@Transactional public void process() { // get all the distinct report definitions List<ReportDefinition> rds = adverseEventRecommendedReportDao.getAllRecommendedReportsNotReported(); // get planned notifications associated with the report definitions for (ReportDefinition rd1 : rds) { for (PlannedNotification plannedNotification : rd1.getUnreportedAePlannedNotification()) { Set<String> contactBasedEmailAddresses = new HashSet<String>(); //find emails of direct recipients if (CollectionUtils.isNotEmpty(plannedNotification.getContactMechanismBasedRecipients())) { for (ContactMechanismBasedRecipient recipient : plannedNotification .getContactMechanismBasedRecipients()) { String contact = recipient.getContact(); if (GenericValidator.isEmail(contact)) contactBasedEmailAddresses.add(contact); }/* w ww.j av a 2s .c o m*/ } //now process the notifications. PlannedEmailNotification plannedemailNotification = (PlannedEmailNotification) plannedNotification; String rawSubjectLine = plannedemailNotification.getSubjectLine(); String rawBody = plannedNotification.getNotificationBodyContent().getBody(); Integer dayOfNotification = plannedemailNotification.getIndexOnTimeScale(); List<AdverseEventRecommendedReport> aeRecomReports = adverseEventRecommendedReportDao .getAllAdverseEventsGivenReportDefinition(rd1); for (AdverseEventRecommendedReport aeRecomReport : aeRecomReports) { Set<String> roleBasedEmailAddresses = new HashSet<String>(); Study study = aeRecomReport.getAdverseEvent().getReportingPeriod().getStudy(); StudySite studySite = aeRecomReport.getAdverseEvent().getReportingPeriod().getStudySite(); //find emails of role recipients List<RoleBasedRecipient> roleRecipients = plannedNotification.getRoleBasedRecipients(); if (CollectionUtils.isNotEmpty(roleRecipients)) { List<String> emails = null; for (RoleBasedRecipient recipient : roleRecipients) { if ("SAE Reporter".equals(recipient.getRoleName()) && aeRecomReport.getAdverseEvent().getReporterEmail() != null) { // add adverse event reporter email for email notification roleBasedEmailAddresses.add(aeRecomReport.getAdverseEvent().getReporterEmail()); } else if (ArrayUtils.contains(RoleUtils.reportSpecificRoles, recipient.getRoleName())) { // since there is no report yet, skip if the role is report specific continue; } else if (ArrayUtils.contains(RoleUtils.sponsorAndCoordinatingCenterSpecificRoles, recipient.getRoleName())) { emails = study.getStudyCoordinatingCenter() .findEmailAddressByRole(recipient.getRoleName()); emails.addAll(study.getStudyFundingSponsors().get(0) .findEmailAddressByRole(recipient.getRoleName())); } else if (ArrayUtils.contains(RoleUtils.studySiteSpecificRoles, recipient.getRoleName())) { emails = studySite.findEmailAddressByRole(recipient.getRoleName()); } else { emails = study.findEmailAddressByRole(recipient.getRoleName()); } //now add the valid email addresses obtained if (CollectionUtils.isNotEmpty(emails)) { for (String email : emails) { if (GenericValidator.isEmail(email)) roleBasedEmailAddresses.add(email); } } } } if (aeRecomReport.getAdverseEvent().getGradedDate() != null) { long daysPassedSinceGradedDate = DateUtils.differenceInDays(new Date(), aeRecomReport.getAdverseEvent().getGradedDate()); if (daysPassedSinceGradedDate != dayOfNotification) { continue; } } // get the graded date and compare with the day of notification to check if notification is configured on this day Map<Object, Object> contextVariableMap = aeRecomReport.getAdverseEvent().getContextVariables(); //get the AE reporting deadline contextVariableMap.put("aeReportingDeadline", aeRecomReport.getDueDate().toString()); //apply the replacements. String subjectLine = freeMarkerService.applyRuntimeReplacementsForReport(rawSubjectLine, contextVariableMap); String body = freeMarkerService.applyRuntimeReplacementsForReport(rawBody, contextVariableMap); //create the message SimpleMailMessage mailMsg = new SimpleMailMessage(); mailMsg.setSentDate(new Date()); mailMsg.setSubject(subjectLine); mailMsg.setText(body); // collect emails of both contact based and role based recipients Set<String> allEmailAddresses = new HashSet<String>(); allEmailAddresses.addAll(roleBasedEmailAddresses); allEmailAddresses.addAll(contactBasedEmailAddresses); //send email to each contact based recipient for (String email : allEmailAddresses) { mailMsg.setTo(email); try { caaersJavaMailSender.send(mailMsg); } catch (Exception e) { //no need to throw and rollback logger.warn("Error while emailing to [" + email + "]", e); } } } } } }
From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java
public void validateEmail(Object propertyValidator) { BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent(); logger.info("validation " + inputComponent.getFieldName() + ": is email"); String valorCampo = (String) inputComponent.getValue(); if (valorCampo != null) { StringTokenizer st = new StringTokenizer(valorCampo, ","); while (st.hasMoreTokens()) { String email = st.nextToken(); if (!GenericValidator.isEmail(email)) { logger.info("validation [FAIL]"); throw new AWValidationException("sw.error.validate.email", Arrays.asList(new Object[] { inputComponent })); }/*from ww w . j ava 2 s. c om*/ } } }
From source file:gov.nih.nci.cabig.caaers.domain.Notification.java
public ValidationErrors validate() { ValidationErrors validationErrors = new ValidationErrors(); if (StringUtils.isEmpty(emails) && StringUtils.isEmpty(roles)) { validationErrors.addValidationError("NF_001", "Invalid recipient information"); }//w w w . j a v a 2s.c om for (String email : getRecipientEmails()) { if (!GenericValidator.isEmail(email)) { validationErrors.addValidationError("NF_001", "Invalid recipient information"); break; } } if (StringUtils.isEmpty(name)) validationErrors.addValidationError("NF_005", "Name cannot be empty"); if (StringUtils.isEmpty(subject)) validationErrors.addValidationError("NF_002", "Subject cannot be empty"); if (study == null) validationErrors.addValidationError("NF_003", "Study cannot be empty"); if (StringUtils.isEmpty(content)) validationErrors.addValidationError("NF_004", "Content cannot be empty"); return validationErrors; }