KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > web > AppController


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 package org.jboss.tutorial.web;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.jboss.tutorial.ee.service.Horoscope;
29 import org.jboss.tutorial.ee.service.Randomizer;
30 import org.springframework.web.bind.ServletRequestUtils;
31 import org.springframework.web.servlet.ModelAndView;
32 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
33
34 /**
35  * @author <a HREF="mailto:ales.justin@genera-lynx.com">Ales Justin</a>
36  */

37 public class AppController extends MultiActionController
38 {
39
40    private Randomizer randomizer;
41    private Horoscope horoscope;
42
43    public Randomizer getRandomizer()
44    {
45       return randomizer;
46    }
47
48    public void setRandomizer(Randomizer randomizer)
49    {
50       this.randomizer = randomizer;
51    }
52
53    public Horoscope getHoroscope()
54    {
55       return horoscope;
56    }
57
58    public void setHoroscope(Horoscope horoscope)
59    {
60       this.horoscope = horoscope;
61    }
62
63    public ModelAndView numberHandler(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
64          throws Exception JavaDoc
65    {
66       int radius = ServletRequestUtils.getRequiredIntParameter(request, "radius");
67       return new ModelAndView("main", "number", randomizer.getNumber(radius));
68    }
69
70    public ModelAndView wordHandler(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
71          throws Exception JavaDoc
72    {
73       return new ModelAndView("main", "word", randomizer.getWord());
74    }
75
76    public ModelAndView horoscopeHandler(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77          throws Exception JavaDoc
78    {
79       if (ServletRequestUtils.getStringParameter(request, "clear") != null)
80       {
81          horoscope.clear();
82          return new ModelAndView("main");
83       }
84       else
85       {
86          int month = ServletRequestUtils.getRequiredIntParameter(request, "month");
87          return new ModelAndView("main", "horoscope", horoscope.getHoroscope(month));
88       }
89    }
90
91 }
92
Popular Tags