View Javadoc

1   package pl.psnc.dl.ege.webapp.request;
2   
3   import javax.servlet.http.HttpServletRequest;
4   
5   import pl.psnc.dl.ege.types.DataType;
6   
7   /**
8    * <p>RequestResolver extension for validation operation of web service.</p>
9    * Decodes request URL and marks one of the available validation operations.
10   * 
11   * @author mariuszs
12   */
13  public class ValidationRequestResolver extends RequestResolver
14  {
15  	private static final String SLICE_BASE = "Validation/";
16  	
17  	
18  	public ValidationRequestResolver(HttpServletRequest request, Method method) throws RequestResolvingException{
19  		this.request = request;
20  		this.method = method;
21  		init();
22  	}
23  	
24  	private void init() throws RequestResolvingException{
25  		if(method.equals(Method.POST)){
26  			resolvePOST();
27  		}
28  		else if(method.equals(Method.GET)){
29  			resolveGET();
30  		}
31  	}
32  	
33  	private void resolvePOST() throws RequestResolvingException{
34  		String[] queries = resolveQueries();
35  		if(queries.length > 1){
36  			DataType dataType = decodeDataType(queries[1]);
37  			data = dataType;
38  			operation = OperationId.PERFORM_VALIDATION;
39  		}
40  		else{
41  			throw new RequestResolvingException(RequestResolvingException.Status.BAD_REQUEST);
42  		}
43  	}
44  	
45  	private void resolveGET() throws RequestResolvingException{
46  		String[] queries = resolveQueries();
47  		if(queries.length == 1){
48  			 operation = OperationId.PRINT_VALIDATIONS;
49  		}
50  		else{
51  			throw new RequestResolvingException(RequestResolvingException.Status.WRONG_METHOD);
52  		}
53  	}
54  	
55  	private String[] resolveQueries()
56  	{
57  		String params = request.getRequestURL().toString();
58  		params = (params.endsWith(SLASH) ? params : params + SLASH);
59  		params = params.substring(params.indexOf(SLICE_BASE),
60  			params.length());
61  		String[] queries = params.split(SLASH);
62  		return queries;
63  	}
64  	
65  	
66  	@Override
67  	public String getLocale()
68  	{
69  		return null;
70  	}
71  	
72  }