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