package org.yacos.web.author.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.yacos.web.author.form.FormSubmission;


public class ValidateSubmission implements Validator {

	public boolean supports(Class arg0) {
		return FormSubmission.class.isAssignableFrom(arg0);
	}

	public void validate(Object arg0, Errors arg1) {
	   
		  FormSubmission sub=(FormSubmission)arg0;
		  
		  String title=sub.getTitle();
		  String theme=sub.getTheme();
		  String abs=sub.getAbstractText();
		  String mainauthor=sub.getMainauthor();
		  String file=sub.getFile().getName();
		  
		  if (title== null || title.trim().length() == 0) {
			arg1.rejectValue("title",
			"submissionArticle.title",
			"Le title est n��cessaire !");
			}
		  
		 
		  if (theme==null|theme.trim().length()==0)
			  
		  {
	     arg1.rejectValue("theme", "submissionArticle.theme");
	     }
		  
		  
		  if (abs==null|abs.trim().length()==0)
			  
		  { arg1.rejectValue("abstractText", "submissionArticle.abstractText", "text is not nullable");
		  
		   }
		  
		 
		  /*if (mainauthor==null|mainauthor.trim().length()==0)
			  
		  {
	     arg1.rejectValue("mainauthor", "submissionArticle.mainauthor");
	     }*/
		  
		  
		/*  if (file==null|file.trim().length()==0)
			  
		  {
	     arg1.rejectValue("file", "submissionArticle.file");
	     }
		  
*/
	}

}
