Java Code Examples for org.apache.commons.validator.routines.EmailValidator#isValid()

The following examples show how to use org.apache.commons.validator.routines.EmailValidator#isValid() . 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: MailActionExecuter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 2
Source File: UrkundReviewServiceImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
* 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 3
Source File: TurnitinReviewServiceImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * 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 4
Source File: UrkundReviewServiceImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
* 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: TurnitinReviewServiceImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * 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 6
Source File: CubeDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
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 7
Source File: CubeDesc.java    From kylin with Apache License 2.0 5 votes vote down vote up
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 8
Source File: EmailDetector.java    From DataDefender with Apache License 2.0 5 votes vote down vote up
/**
 * @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 9
Source File: FileReaderController.java    From full-teaching with Apache License 2.0 4 votes vote down vote up
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 10
Source File: CourseController.java    From full-teaching with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: HIPAAMatcherAttributeValue.java    From arx with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(String value) {
    EmailValidator validator = EmailValidator.getInstance();
    return validator.isValid(value);
}
 
Example 12
Source File: StringUtil.java    From peer-os with Apache License 2.0 3 votes vote down vote up
/**
 * ***********************************************************************************
 * Removes Special HTML Tags and Non-AlfaNumeric Chars
 *
 * @param email Email to be validated
 *
 * @return Is valid mail
 */
public static boolean isValidEmail( String email )
{
    EmailValidator emailvalidator = EmailValidator.getInstance();

    return emailvalidator.isValid( email );
}
 
Example 13
Source File: SiteAddParticipantHandler.java    From sakai with Educational Community License v2.0 3 votes vote down vote up
private boolean isValidMail(String email) {
	if (email == null || "".equals(email))
		return false;
	
	email = email.trim();
	
	EmailValidator ev = EmailValidator.getInstance();
	return ev.isValid(email);
	
}
 
Example 14
Source File: SiteAddParticipantHandler.java    From sakai with Educational Community License v2.0 3 votes vote down vote up
private boolean isValidMail(String email) {
	if (email == null || "".equals(email))
		return false;
	
	email = email.trim();
	
	EmailValidator ev = EmailValidator.getInstance();
	return ev.isValid(email);
	
}