org.apache.commons.validator.routines.EmailValidator Java Examples
The following examples show how to use
org.apache.commons.validator.routines.EmailValidator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TurnitinReviewServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Is this a valid email the service will recognize * * @param email * @return */ private boolean isValidEmail(String email) { // TODO: Use a generic Sakai utility class (when a suitable one exists) if (email == null || email.equals("")) return false; email = email.trim(); // must contain @ if (email.indexOf("@") == -1) return false; // an email can't contain spaces if (email.indexOf(" ") > 0) return false; // use commons-validator EmailValidator validator = EmailValidator.getInstance(); if (validator.isValid(email)) return true; return false; }
Example #2
Source File: TurnitinReviewServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Is this a valid email the service will recognize * * @param email * @return */ private boolean isValidEmail(String email) { // TODO: Use a generic Sakai utility class (when a suitable one exists) if (email == null || email.equals("")) return false; email = email.trim(); // must contain @ if (email.indexOf("@") == -1) return false; // an email can't contain spaces if (email.indexOf(" ") > 0) return false; // use commons-validator EmailValidator validator = EmailValidator.getInstance(); if (validator.isValid(email)) return true; return false; }
Example #3
Source File: UrkundReviewServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Is this a valid email the service will recognize * * @param email * @return */ private boolean isValidEmail(String email) { if (email == null || email.equals("")) { return false; } email = email.trim(); //must contain @ if (!email.contains("@")) { return false; } //an email can't contain spaces if (email.indexOf(" ") > 0) { return false; } //use commons-validator EmailValidator validator = EmailValidator.getInstance(); return validator.isValid(email); }
Example #4
Source File: UrkundReviewServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Is this a valid email the service will recognize * * @param email * @return */ private boolean isValidEmail(String email) { if (email == null || email.equals("")) { return false; } email = email.trim(); //must contain @ if (!email.contains("@")) { return false; } //an email can't contain spaces if (email.indexOf(" ") > 0) { return false; } //use commons-validator EmailValidator validator = EmailValidator.getInstance(); return validator.isValid(email); }
Example #5
Source File: MailActionExecuter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Return true if address has valid format * @param address String * @return boolean */ private boolean validateAddress(String address) { boolean result = false; // Validate the email, allowing for local email addresses EmailValidator emailValidator = EmailValidator.getInstance(true); if (!validateAddresses || emailValidator.isValid(address)) { result = true; } else { logger.error("Failed to send email to '" + address + "' as the address is incorrectly formatted" ); } return result; }
Example #6
Source File: SignupEmailFacadeImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Helper to convert a signup email notification into a Sakai EmailMessage, which can encapsulate attachments. * * <p>Due to the way the email objects are created, ie one per email that needs to be sent, not one per user, we cannot store any * user specific attachments within the email objects themselves. So this method assembles an EmailMessage per user * * @param email - the signup email obj we will extract info from * @param recipient - list of user to receive the email * @return */ private EmailMessage convertSignupEmail(SignupEmailNotification email, User recipient) { EmailMessage message = new EmailMessage(); //setup message message.setHeaders(email.getHeader()); message.setBody(email.getMessage()); // Pass a flag to the EmailService to indicate that we want the MIME multipart subtype set to alternative // so that an email client can present the message as a meeting invite message.setHeader("multipart-subtype", "alternative"); //note that the headers are largely ignored so we need to repeat some things here that are actually in the headers //if these are eventaully converted to proper email templates, this should be alleviated message.setSubject(email.getSubject()); log.debug("email.getFromAddress(): " + email.getFromAddress()); message.setFrom(email.getFromAddress()); message.setContentType("text/html; charset=UTF-8"); if(!email.isModifyComment()){ //skip ICS attachment file for user comment email for(Attachment a: collectAttachments(email, recipient)){ message.addAttachment(a); } } //add recipient, only if valid email String emailAddress = recipient.getEmail(); if(StringUtils.isNotBlank(emailAddress) && EmailValidator.getInstance().isValid(emailAddress)) { message.addRecipient(EmailAddress.RecipientType.TO, recipient.getDisplayName(), emailAddress); } else { log.debug("Invalid email for user: " + recipient.getDisplayId() + ". No email will be sent to this user"); return null; } return message; }
Example #7
Source File: UsersController.java From pulsar-manager with Apache License 2.0 | 5 votes |
@ApiOperation(value = "Update user by super user") @ApiResponses({ @ApiResponse(code = 200, message = "ok"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 500, message = "Internal server error") }) @RequestMapping(value = "/users/user", method = RequestMethod.POST) public ResponseEntity<Map<String, Object>> updateUser(@RequestBody @Valid UserInfoEntity userInfoEntity) { Map<String, Object> result = Maps.newHashMap(); Optional<UserInfoEntity> userInfoEntityOptional = usersRepository.findByUserName(userInfoEntity.getName()); if (!userInfoEntityOptional.isPresent()) { result.put("error", "Failed update a user, user does not exist"); return ResponseEntity.ok(result); } if (StringUtils.isBlank(userInfoEntity.getEmail())) { result.put("error", "Failed update a user, email is not be empty"); return ResponseEntity.ok(result); } if (!EmailValidator.getInstance().isValid(userInfoEntity.getEmail())) { result.put("error", "Email address illegal"); return ResponseEntity.ok(result); } UserInfoEntity existUerInfoEntity = userInfoEntityOptional.get(); userInfoEntity.setPassword(existUerInfoEntity.getPassword()); userInfoEntity.setAccessToken(existUerInfoEntity.getAccessToken()); usersRepository.update(userInfoEntity); result.put("message", "Update a user success"); return ResponseEntity.ok(result); }
Example #8
Source File: UsersServiceImpl.java From pulsar-manager with Apache License 2.0 | 5 votes |
public Map<String, String> validateUserInfo(UserInfoEntity userInfoEntity) { Map<String, String> validateResult = Maps.newHashMap(); if (StringUtils.isBlank(userInfoEntity.getName())) { validateResult.put("error", "User name cannot be empty"); return validateResult; } if (!(pattern.matcher(userInfoEntity.getName()).matches())) { validateResult.put("error", "User name illegal"); return validateResult; } if (StringUtils.isBlank(userInfoEntity.getEmail())) { validateResult.put("error", "User email cannot be empty"); return validateResult; } if (!EmailValidator.getInstance().isValid(userInfoEntity.getEmail())) { validateResult.put("error", "Email address illegal"); return validateResult; } if (StringUtils.isBlank(userInfoEntity.getPassword()) && StringUtils.isBlank(userInfoEntity.getAccessToken())) { validateResult.put("error", "Fields password and access token cannot be empty at the same time."); return validateResult; } validateResult.put("message", "Validate user success"); return validateResult; }
Example #9
Source File: SignupEmailFacadeImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Helper to convert a signup email notification into a Sakai EmailMessage, which can encapsulate attachments. * * <p>Due to the way the email objects are created, ie one per email that needs to be sent, not one per user, we cannot store any * user specific attachments within the email objects themselves. So this method assembles an EmailMessage per user * * @param email - the signup email obj we will extract info from * @param recipient - list of user to receive the email * @return */ private EmailMessage convertSignupEmail(SignupEmailNotification email, User recipient) { EmailMessage message = new EmailMessage(); //setup message message.setHeaders(email.getHeader()); message.setBody(email.getMessage()); // Pass a flag to the EmailService to indicate that we want the MIME multipart subtype set to alternative // so that an email client can present the message as a meeting invite message.setHeader("multipart-subtype", "alternative"); //note that the headers are largely ignored so we need to repeat some things here that are actually in the headers //if these are eventaully converted to proper email templates, this should be alleviated message.setSubject(email.getSubject()); log.debug("email.getFromAddress(): " + email.getFromAddress()); message.setFrom(email.getFromAddress()); message.setContentType("text/html; charset=UTF-8"); if(!email.isModifyComment()){ //skip ICS attachment file for user comment email for(Attachment a: collectAttachments(email, recipient)){ message.addAttachment(a); } } //add recipient, only if valid email String emailAddress = recipient.getEmail(); if(StringUtils.isNotBlank(emailAddress) && EmailValidator.getInstance().isValid(emailAddress)) { message.addRecipient(EmailAddress.RecipientType.TO, recipient.getDisplayName(), emailAddress); } else { log.debug("Invalid email for user: " + recipient.getDisplayId() + ". No email will be sent to this user"); return null; } return message; }
Example #10
Source File: Validator.java From mangooio with Apache License 2.0 | 5 votes |
/** * Validates a field to be a valid email address * * @param name The field to check * @param message A custom error message instead of the default one */ public void expectEmail(String name, String message) { String value = Optional.ofNullable(get(name)).orElse(""); if (!EmailValidator.getInstance().isValid(value)) { addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.EMAIL_KEY.name(), name))); } }
Example #11
Source File: CubeDesc.java From kylin with Apache License 2.0 | 5 votes |
public void validateNotifyList() { List<String> notifyList = getNotifyList(); if (notifyList != null && !notifyList.isEmpty()) { EmailValidator emailValidator = EmailValidator.getInstance(); for (String email : notifyList) { if (!emailValidator.isValid(email)) { throw new IllegalArgumentException("Email [" + email + "] is not validation."); } } } }
Example #12
Source File: EmailDetector.java From DataDefender with Apache License 2.0 | 5 votes |
/** * @param email Email address * @return true if email is valid, otherwise false */ private static boolean isValidEmail(final String email) { EmailValidator eValidator = EmailValidator.getInstance(); if (eValidator.isValid(email)) { log.debug("*************** Email " + email + " is valid"); return true; } else { return false; } }
Example #13
Source File: EmailFormatValidator.java From json-schema with Apache License 2.0 | 5 votes |
@Override public Optional<String> validate(final String subject) { if (EmailValidator.getInstance(false, true).isValid(subject)) { return Optional.empty(); } return Optional.of(String.format("[%s] is not a valid email address", subject)); }
Example #14
Source File: CubeDesc.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public void validateNotifyList() { List<String> notifyList = getNotifyList(); if (notifyList != null && !notifyList.isEmpty()) { EmailValidator emailValidator = EmailValidator.getInstance(); for (String email : notifyList) { if (!emailValidator.isValid(email)) { throw new IllegalArgumentException("Email [" + email + "] is not validation."); } } } }
Example #15
Source File: UtilValidate.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Checks a String for a valid Email-List seperated by ",". */ public static boolean isEmailList(String s) { if (isEmpty(s)) { return defaultEmptyOK; } String[] emails = s.split(","); for (String email : emails) { if (!EmailValidator.getInstance().isValid(email)) { return false; } } return true; }
Example #16
Source File: AppIdentityTestBase.java From appengine-tck with Apache License 2.0 | 5 votes |
protected static WebArchive getDefaultDeployment() { TestContext context = new TestContext().setUseSystemProperties(true).setCompatibilityProperties(TCK_PROPERTIES); WebArchive war = getTckDeployment(context); war.addClass(AppIdentityTestBase.class); war.addPackage(EmailValidator.class.getPackage()); return war; }
Example #17
Source File: AppIdentityServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testGetServiceAccountName() { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); String serviceAccountName = appIdentity.getServiceAccountName(); String errMsg = serviceAccountName + " is not valid."; Assert.assertTrue(errMsg, EmailValidator.getInstance().isValid(serviceAccountName)); }
Example #18
Source File: PrivateMessagesTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String processPvtMsgSettingsSave() { log.debug("processPvtMsgSettingsSave()"); String email= getForwardPvtMsgEmail(); String activate=getActivatePvtMsg() ; String forward=getForwardPvtMsg() ; if (email != null && (SET_AS_YES.equals(forward)) && !EmailValidator.getInstance().isValid(email) ) { setValidEmail(false); setErrorMessage(getResourceBundleString(PROVIDE_VALID_EMAIL)); setActivatePvtMsg(activate); return null; } else { Area area = prtMsgManager.getPrivateMessageArea(); Boolean formAreaEnabledValue = (SET_AS_YES.equals(activate)) ? Boolean.TRUE : Boolean.FALSE; area.setEnabled(formAreaEnabledValue); try { int formSendToEmail = Integer.parseInt(sendToEmail); area.setSendToEmail(formSendToEmail); } catch (NumberFormatException nfe) { // if this happens, there is likely something wrong in the UI that needs to be fixed log.warn("Non-numeric option for sending email to recipient email address on Message screen. This may indicate a UI problem."); setErrorMessage(getResourceBundleString("pvt_send_to_email_invalid")); return null; } switch (forward) { case SET_AS_YES: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_YES); break; case SET_AS_NO: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_NO); break; default: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_DEFAULT); break; } if (SET_AS_YES.equals(forward)){ forum.setAutoForwardEmail(email); } else{ forum.setAutoForwardEmail(null); } area.setHiddenGroups(new HashSet(hiddenGroups)); prtMsgManager.saveAreaAndForumSettings(area, forum); if (isMessagesandForums()) { return MAIN_PG; } else { return MESSAGE_HOME_PG; } } }
Example #19
Source File: HIPAAMatcherAttributeValue.java From arx with Apache License 2.0 | 4 votes |
@Override public boolean matches(String value) { EmailValidator validator = EmailValidator.getInstance(); return validator.isValid(value); }
Example #20
Source File: UserProfileValidator.java From attic-rave with Apache License 2.0 | 4 votes |
private boolean isInvalidEmailAddress(String emailAddress) { return !EmailValidator.getInstance().isValid(emailAddress); }
Example #21
Source File: NewAccountValidator.java From attic-rave with Apache License 2.0 | 4 votes |
protected boolean isInvalidEmailAddress(String emailAddress) { return !EmailValidator.getInstance().isValid(emailAddress); }
Example #22
Source File: EmailAddress.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 4 votes |
private void checkParameters(final String value) { if (!EmailValidator.getInstance().isValid(value)) { throw new DomainException("error.domain.contacts.EmailAddress.invalid.format", value); } }
Example #23
Source File: EmailValidation.java From metron with Apache License 2.0 | 4 votes |
@Override public Predicate<Object> getPredicate() { return email -> EmailValidator.getInstance().isValid(email == null?null:email.toString()); }
Example #24
Source File: PrivateMessagesTool.java From sakai with Educational Community License v2.0 | 4 votes |
public String processPvtMsgSettingsSave() { log.debug("processPvtMsgSettingsSave()"); String email= getForwardPvtMsgEmail(); String activate=getActivatePvtMsg() ; String forward=getForwardPvtMsg() ; if (email != null && (SET_AS_YES.equals(forward)) && !EmailValidator.getInstance().isValid(email) ) { setValidEmail(false); setErrorMessage(getResourceBundleString(PROVIDE_VALID_EMAIL)); setActivatePvtMsg(activate); return null; } else { Area area = prtMsgManager.getPrivateMessageArea(); Boolean formAreaEnabledValue = (SET_AS_YES.equals(activate)) ? Boolean.TRUE : Boolean.FALSE; area.setEnabled(formAreaEnabledValue); try { int formSendToEmail = Integer.parseInt(sendToEmail); area.setSendToEmail(formSendToEmail); } catch (NumberFormatException nfe) { // if this happens, there is likely something wrong in the UI that needs to be fixed log.warn("Non-numeric option for sending email to recipient email address on Message screen. This may indicate a UI problem."); setErrorMessage(getResourceBundleString("pvt_send_to_email_invalid")); return null; } switch (forward) { case SET_AS_YES: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_YES); break; case SET_AS_NO: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_NO); break; default: forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_DEFAULT); break; } if (SET_AS_YES.equals(forward)){ forum.setAutoForwardEmail(email); } else{ forum.setAutoForwardEmail(null); } area.setHiddenGroups(new HashSet(hiddenGroups)); prtMsgManager.saveAreaAndForumSettings(area, forum); if (isMessagesandForums()) { return MAIN_PG; } else { return MESSAGE_HOME_PG; } } }
Example #25
Source File: EmailAddressValidator.java From jsastrawi with MIT License | 4 votes |
@Override public boolean isValid(String s) { return EmailValidator.getInstance().isValid(s); }
Example #26
Source File: CourseController.java From full-teaching with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/edit/add-attenders/course/{courseId}", method = RequestMethod.PUT) public ResponseEntity<Object> addAttenders( @RequestBody String[] attenderEmails, @PathVariable(value="courseId") String courseId) { ResponseEntity<Object> authorized = authorizationService.checkBackendLogged(); if (authorized != null){ return authorized; }; long id_course = -1; try{ id_course = Long.parseLong(courseId); }catch(NumberFormatException e){ return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } Course c = courseRepository.findOne(id_course); ResponseEntity<Object> teacherAuthorized = authorizationService.checkAuthorization(c, c.getTeacher()); if (teacherAuthorized != null) { // If the user is not the teacher of the course return teacherAuthorized; } else { //Strings with a valid email format Set<String> attenderEmailsValid = new HashSet<>(); //Strings with an invalid email format Set<String> attenderEmailsInvalid = new HashSet<>(); //Strings with a valid email format but no registered in the application Set<String> attenderEmailsNotRegistered = new HashSet<>(); EmailValidator emailValidator = EmailValidator.getInstance(); for (int i = 0; i < attenderEmails.length; i++){ if (emailValidator.isValid(attenderEmails[i])) { attenderEmailsValid.add(attenderEmails[i]); } else { attenderEmailsInvalid.add(attenderEmails[i]); } } Collection<User> newPossibleAttenders = userRepository.findByNameIn(attenderEmailsValid); Collection<User> newAddedAttenders = new HashSet<>(); Collection<User> alreadyAddedAttenders = new HashSet<>(); for (String s : attenderEmailsValid){ if (!this.userListContainsEmail(newPossibleAttenders, s)){ attenderEmailsNotRegistered.add(s); } } for (User attender : newPossibleAttenders){ boolean newAtt = true; if (!attender.getCourses().contains(c)) attender.getCourses().add(c); else newAtt = false; if (!c.getAttenders().contains(attender)) c.getAttenders().add(attender); else newAtt = false; if (newAtt) newAddedAttenders.add(attender); else alreadyAddedAttenders.add(attender); } //Saving the attenders (all of them, just in case a field of the bidirectional relationship is missing in a Course or a User) userRepository.save(newPossibleAttenders); //Saving the modified course courseRepository.save(c); AddAttendersResponse customResponse = new AddAttendersResponse(); customResponse.attendersAdded = newAddedAttenders; customResponse.attendersAlreadyAdded = alreadyAddedAttenders; customResponse.emailsInvalid = attenderEmailsInvalid; customResponse.emailsValidNotRegistered = attenderEmailsNotRegistered; return new ResponseEntity<>(customResponse, HttpStatus.OK); } }
Example #27
Source File: FileReaderController.java From full-teaching with Apache License 2.0 | 4 votes |
private AddAttendersByFileResponse addAttendersFromFile(Course c, String s){ String[] stringArray = s.split("\\s"); List<String> stringList = new ArrayList<String>(Arrays.asList(stringArray)); stringList.removeAll(Arrays.asList("", null)); //Strings with a valid email format Set<String> attenderEmailsValid = new HashSet<>(); //Strings with a valid email format but no registered in the application Set<String> attenderEmailsNotRegistered = new HashSet<>(); EmailValidator emailValidator = EmailValidator.getInstance(); //Getting all the emails in the document and storing them in a String set for (String word : stringList){ if (emailValidator.isValid(word)) { attenderEmailsValid.add(word); } } Collection<User> newPossibleAttenders = userRepository.findByNameIn(attenderEmailsValid); Collection<User> newAddedAttenders = new HashSet<>(); Collection<User> alreadyAddedAttenders = new HashSet<>(); for (String email : attenderEmailsValid){ if (!this.userListContainsEmail(newPossibleAttenders, email)){ attenderEmailsNotRegistered.add(email); } } for (User attender : newPossibleAttenders){ boolean newAtt = true; if (!attender.getCourses().contains(c)) attender.getCourses().add(c); else newAtt = false; if (!c.getAttenders().contains(attender)) c.getAttenders().add(attender); else newAtt = false; if (newAtt) newAddedAttenders.add(attender); else alreadyAddedAttenders.add(attender); } //Saving the attenders (all of them, just in case a field of the bidirectional relationship is missing in a Course or a User) userRepository.save(newPossibleAttenders); //Saving the modified course courseRepository.save(c); AddAttendersByFileResponse customResponse = new AddAttendersByFileResponse(); customResponse.attendersAdded = newAddedAttenders; customResponse.attendersAlreadyAdded = alreadyAddedAttenders; customResponse.emailsValidNotRegistered = attenderEmailsNotRegistered; return customResponse; }
Example #28
Source File: SimpleTokenizer.java From Mutters with Apache License 2.0 | 4 votes |
@Override public String[] tokenize(String text) { String[] tokens = text.trim().split("\\s+"); List<String> finalTokens = new ArrayList<>(); for (String token : tokens) { boolean applyStriping = true; boolean applylowercasing = true; // is it a decimal or negative number if ((token.indexOf('.') != -1 || token.startsWith("-")) && isNumeric(token)) { applyStriping = false; } else { // is it a $ value ? if (token.startsWith("$") && isNumeric(token.substring(1))) { applyStriping = false; } else { // is it an email address ? if (token.indexOf('@') != -1) { if (token.endsWith(".") || token.endsWith(",")) { token = token.substring(0, token.length() - 1); } if (EmailValidator.getInstance().isValid(token)) { applyStriping = false; } } else { // is it a templated utterance tag ? if (token.startsWith("{") && token.endsWith("}")) { applyStriping = false; applylowercasing = false; } } } } // should stripping be applied ? if (applyStriping) { token = token.replaceAll("[^A-Za-z0-9:/]", ""); } // are we lowercasing token ? if (forceLowerCase && applylowercasing) { token = token.toLowerCase(); } // do we have anything left ? if (!StringUtils.isBlank(token)) { finalTokens.add(token); } } return finalTokens.toArray(new String[finalTokens.size()]); }
Example #29
Source File: UtilValidate.java From scipio-erp with Apache License 2.0 | 4 votes |
public static boolean isEmail(String s) { if (isEmpty(s)) { return defaultEmptyOK; } return EmailValidator.getInstance().isValid(s); }
Example #30
Source File: Utils.java From zhcet-web with Apache License 2.0 | 4 votes |
public static boolean isValidEmail(String email) { return EmailValidator.getInstance().isValid(email); }