01: // Copyright 2007 The Apache Software Foundation
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: package org.apache.tapestry.internal.services;
16:
17: import java.util.Locale;
18:
19: import org.apache.tapestry.services.Cookies;
20: import org.apache.tapestry.services.PersistentLocale;
21:
22: public class PersistentLocaleImpl implements PersistentLocale {
23: /**
24: * Name of the cookie written to the client web browser to identify the locale.
25: */
26: private static final String LOCALE_COOKIE_NAME = "org.apache.tapestry.locale";
27:
28: private Cookies _cookieSource;
29:
30: public PersistentLocaleImpl(Cookies cookieSource) {
31: _cookieSource = cookieSource;
32: }
33:
34: public void set(Locale locale) {
35: _cookieSource.writeCookieValue(LOCALE_COOKIE_NAME, locale
36: .toString());
37: }
38:
39: public Locale get() {
40: String localeCookieValue = getCookieValue();
41:
42: return localeCookieValue != null ? new Locale(localeCookieValue)
43: : null;
44: }
45:
46: private String getCookieValue() {
47: return _cookieSource.readCookieValue(LOCALE_COOKIE_NAME);
48: }
49:
50: public boolean isSet() {
51: return getCookieValue() != null;
52: }
53:
54: }
|