-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileValidator.java
More file actions
41 lines (34 loc) · 1.09 KB
/
FileValidator.java
File metadata and controls
41 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.javaee7.chapter02.jsf;
import java.io.InputStream;
import java.util.Scanner;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.Part;
/**
*
* @author Juneau
*/
@FacesValidator(value = "FileValidator")
public class FileValidator implements Validator {
public FileValidator() {
}
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
Part file = (Part) value;
String text = null;
try {
InputStream is = file.getInputStream();
text = new Scanner(is).useDelimiter("\\A").next();
} catch (Exception ex) {
throw new ValidatorException(new FacesMessage("Exception thrown"));
}
}
}