View Javadoc
1   /*
2    * Copyright 2009-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.admin.web;
17  
18  import java.io.IOException;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.servlet.ServletException;
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  
26  import org.springframework.web.HttpRequestHandler;
27  import org.springframework.web.servlet.View;
28  
29  /**
30   * Trivial HTTP request handler that just renders a view. Useful as an entry
31   * point to present a form for sending data to an HTTP inbound endpoint.
32   * 
33   * @author Dave Syer
34   * 
35   */
36  public class ViewHandler implements HttpRequestHandler {
37  
38  	private View view;
39  
40  	private Map<String, ?> model = new HashMap<String, Object>();
41  
42  	public void setView(View view) {
43  		this.view = view;
44  	}
45  
46  	public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,
47  			IOException {
48  		try {
49  			view.render(model, request, response);
50  		}
51  		catch (IOException e) {
52  			throw e;
53  		}
54  		catch (Exception e) {
55  			throw new ServletException(e);
56  		}
57  	}
58  
59  }