01: /**
02: * Copyright (c) 2006 Red Hat, Inc. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17: * USA
18: *
19: * Component of: Red Hat Application Server
20: *
21: * Initial Developers: Greg Lapouchnian
22: * Patrick Smith
23: *
24: */package olstore.controller;
25:
26: import java.util.Collection;
27: import java.util.Map;
28:
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.http.HttpServletResponse;
31:
32: import olstore.domain.logic.OlstoreFacade;
33:
34: import org.springframework.web.servlet.ModelAndView;
35: import org.springframework.web.servlet.mvc.Controller;
36:
37: /**
38: * The controller used for the view index action.
39: */
40: public class ViewIndexController implements Controller {
41:
42: // The olstore bean instance supplied via Spring.
43: private OlstoreFacade olstore;
44:
45: /**
46: * The Spring injection method to set the olstore bean's instance.
47: * @param olstore the bean instance set via Spring.
48: */
49: public void setOlstore(OlstoreFacade olstore) {
50: this .olstore = olstore;
51: }
52:
53: /**
54: * When spring intercepts a request to the specified path (in olstore-servlet.xml) the
55: * request is handled here.
56: *
57: * @param request the HttpServletRequest object.
58: * @param response The HttpServletResponse object.
59: * @throws Exception
60: */
61: public ModelAndView handleRequest(HttpServletRequest request,
62: HttpServletResponse response) throws Exception {
63: Map model = ControllerHelper.initModel(request, olstore);
64: model.put("user", olstore.getUser(request.getRemoteUser()));
65: model.put("friendSet", ((Collection) olstore
66: .findByMainPageAndFriendsOf(request.getRemoteUser())));
67: model.put("specialSet", ((Collection) olstore
68: .findByMainPageAndSpecialOffer()));
69: model.put("otherSet", ((Collection) olstore.findByMainPage()));
70: model.put("page_title", "RHAPS Olstore Demo");
71: return new ModelAndView("index", model);
72: }
73:
74: }
|