01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.navigate.spring;
16:
17: import java.util.Map;
18:
19: import javax.servlet.http.HttpServletRequest;
20: import javax.servlet.http.HttpServletResponse;
21:
22: import org.springframework.web.servlet.View;
23: import org.strecks.context.ActionContext;
24: import org.strecks.exceptions.ApplicationRuntimeException;
25: import org.strecks.util.Assert;
26: import org.strecks.view.RenderingViewAdapter;
27:
28: /**
29: * Implementation of <code>RenderingViewAdapter</code> which renders a Spring <code>View</code>
30: * using the method
31: * <code>void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception;</code>
32: * @author Phil Zoio
33: */
34: public class SpringRenderingViewAdapter implements RenderingViewAdapter {
35:
36: private View view;
37:
38: private Map model;
39:
40: public SpringRenderingViewAdapter(View view, Map model) {
41: super ();
42: Assert.notNull(view);
43: this .model = model;
44: this .view = view;
45: }
46:
47: public void render(ActionContext actionContext) {
48: try {
49: HttpServletRequest request = actionContext.getRequest();
50: HttpServletResponse response = actionContext.getResponse();
51: view.render(model, request, response);
52: } catch (Exception e) {
53: throw new ApplicationRuntimeException(
54: "Exception thrown during rendering of view "
55: + view.getClass().getName(), e);
56: }
57: }
58:
59: Map getModel() {
60: return model;
61: }
62:
63: View getView() {
64: return view;
65: }
66:
67: }
|