01: /*
02: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program 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
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package com.nabhinc.portlet.guessnumber;
20:
21: import java.io.IOException;
22: import java.util.Random;
23:
24: import javax.portlet.PortletException;
25: import javax.portlet.PortletSession;
26: import javax.portlet.RenderRequest;
27: import javax.portlet.RenderResponse;
28:
29: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
30: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
31: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
32:
33: /**
34: *
35: *
36: * @author Padmanabh Dabke
37: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
38: */
39: public class UserNumberGenerator extends BaseRequestProcessor implements
40: RenderProcessor {
41: public static final String MIN_NUMBER_ATTRIB = "minNumber";
42: public static final String MAX_NUMBER_ATTRIB = "maxNumber";
43: public static final String CORRECT_NUMBER_ATTRIB = "correctNumber";
44:
45: private int minNumber = 0;
46: private int maxNumber = 10;
47:
48: /* (non-Javadoc)
49: * @see com.nabhinc.portlet.mvcportlet.core.RenderProcessor#process(javax.portlet.RenderRequest, javax.portlet.RenderResponse, com.nabhinc.portlet.mvcportlet.core.RenderConfig)
50: */
51: public String process(RenderRequest request,
52: RenderResponse response, RenderConfig renderConfig)
53: throws PortletException, IOException {
54:
55: PortletSession session = request.getPortletSession();
56: String currentNumber = (String) session
57: .getAttribute(CORRECT_NUMBER_ATTRIB);
58: if (currentNumber != null)
59: return "success";
60:
61: Random randomGR = new Random();
62: String randomInt = Integer
63: .toString(randomGR.nextInt(maxNumber));
64: System.out.println("Duke's number: " + randomInt);
65: session.setAttribute(CORRECT_NUMBER_ATTRIB, randomInt);
66: session.setAttribute(MIN_NUMBER_ATTRIB, new Integer(minNumber));
67: session.setAttribute(MAX_NUMBER_ATTRIB, new Integer(maxNumber));
68: return "success";
69: }
70:
71: }
|