01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * @author www.gerdziegler.de
13: */
14:
15: package org.ztemplates.web.impl;
16:
17: import javax.servlet.ServletContext;
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpServletResponse;
20:
21: import org.ztemplates.web.ZIServiceRepository;
22: import org.ztemplates.web.ZIServletService;
23:
24: public class ZServletServiceImpl implements ZIServletService {
25: private HttpServletRequest request;
26:
27: private HttpServletResponse response;
28:
29: private ServletContext servletContext;
30:
31: private ZIServiceRepository serviceRepository;
32:
33: public void init(ZIServiceRepository serviceRepository)
34: throws Exception {
35: this .serviceRepository = serviceRepository;
36: this .request = serviceRepository.getRequest();
37: this .response = serviceRepository.getResponse();
38: this .servletContext = request.getSession().getServletContext();
39: }
40:
41: public HttpServletRequest getRequest() {
42: return request;
43: }
44:
45: public HttpServletResponse getResponse() {
46: return response;
47: }
48:
49: public ServletContext getServletContext() {
50: return servletContext;
51: }
52:
53: public void render(Object obj) throws Exception {
54: render(obj, "text/html");
55: }
56:
57: public void render(Object obj, String mimeType) throws Exception {
58: String html = serviceRepository.getRenderService().render(obj);
59: response.setContentType(mimeType);
60: response.getWriter().print(html);
61: }
62:
63: public String createUrl(Object action) throws Exception {
64: return serviceRepository.getActionService().createUrl(action);
65: }
66:
67: public void sendRedirect(Object action) throws Exception {
68: String url = createUrl(action);
69: response.sendRedirect(url);
70: }
71:
72: }
|