01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
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: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package sample.contact;
17:
18: import org.springframework.beans.factory.InitializingBean;
19:
20: import org.springframework.util.Assert;
21:
22: import org.springframework.web.servlet.ModelAndView;
23: import org.springframework.web.servlet.mvc.Controller;
24:
25: import java.io.IOException;
26:
27: import java.util.HashMap;
28: import java.util.List;
29: import java.util.Map;
30:
31: import javax.servlet.ServletException;
32: import javax.servlet.http.HttpServletRequest;
33: import javax.servlet.http.HttpServletResponse;
34:
35: /**
36: * Controller for secure index page.
37: *
38: * @author Ben Alex
39: * @version $Id: SecureIndexController.java 1496 2006-05-23 13:38:33Z benalex $
40: */
41: public class SecureIndexController implements Controller,
42: InitializingBean {
43: //~ Instance fields ================================================================================================
44:
45: private ContactManager contactManager;
46:
47: //~ Methods ========================================================================================================
48:
49: public void afterPropertiesSet() throws Exception {
50: Assert.notNull(contactManager,
51: "A ContactManager implementation is required");
52: }
53:
54: public ContactManager getContactManager() {
55: return contactManager;
56: }
57:
58: public ModelAndView handleRequest(HttpServletRequest request,
59: HttpServletResponse response) throws ServletException,
60: IOException {
61: List myContactsList = contactManager.getAll();
62: Contact[] myContacts;
63:
64: if (myContactsList.size() == 0) {
65: myContacts = null;
66: } else {
67: myContacts = (Contact[]) myContactsList
68: .toArray(new Contact[] {});
69: }
70:
71: Map model = new HashMap();
72: model.put("contacts", myContacts);
73:
74: return new ModelAndView("index", "model", model);
75: }
76:
77: public void setContactManager(ContactManager contact) {
78: this.contactManager = contact;
79: }
80: }
|