01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.server;
23:
24: import java.util.Locale;
25:
26: /**
27: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
28: * @version $Revision: 8784 $
29: */
30: public class ServerRequest {
31:
32: /** The locales for the scope of the current request. */
33: protected Locale[] locales;
34:
35: /** The server used during the request. */
36: protected Server server;
37:
38: /** . */
39: protected ServerInvocationContext invocationContext;
40:
41: public ServerRequest(ServerInvocationContext invocationContext) {
42: this .invocationContext = invocationContext;
43: }
44:
45: public Server getServer() {
46: return server;
47: }
48:
49: public void setServer(Server server) {
50: this .server = server;
51: }
52:
53: /**
54: * Return the first locale in the locale list or null if the list is empty.
55: *
56: * @return the first locale in the list
57: * @throws IllegalArgumentException if the locales field is null
58: */
59: public Locale getLocale() throws IllegalStateException {
60: if (locales == null) {
61: throw new IllegalStateException(
62: "No locales have been defined in this request");
63: }
64: if (locales.length == 0) {
65: return null;
66: }
67: return locales[0];
68: }
69:
70: /**
71: * Return the locales for the scope of the current request. It can be based on the locale decided by the web browser
72: * available in the original HTTP request or can be based on the current authenticated user that has decided a
73: * specific locale.
74: *
75: * @return the request locale
76: */
77: public Locale[] getLocales() {
78: return locales;
79: }
80:
81: public void setLocales(Locale[] locales) {
82: this.locales = locales;
83: }
84: }
|