01: /*
02: * $Id: Home.java 461192 2006-06-28 06:37:16Z ehillenius $ $Revision: 461192 $
03: * $Date: 2006-06-28 08:37:16 +0200 (Wed, 28 Jun 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.encodings;
19:
20: import java.util.Locale;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24:
25: import wicket.PageParameters;
26: import wicket.examples.WicketExamplePage;
27: import wicket.markup.html.basic.Label;
28:
29: /**
30: * Example of configuring locale encodings.
31: *
32: * @author Jonathan Locke
33: */
34: public class Home extends WicketExamplePage {
35: private static final Log log = LogFactory.getLog(Home.class);
36:
37: /**
38: * Constructor
39: *
40: * @param parameters
41: * Page parameters
42: */
43: public Home(final PageParameters parameters) {
44: add(new Label("message", "Hello world! Test: äöü"));
45: }
46:
47: /**
48: * Because only servlet 2.4 supports web.xml locale-encoding-mapping-list
49: * deployment descriptors, this is a workaround for servlet 2.3
50: */
51: protected void configureResponse() {
52: final Locale originalLocale = getSession().getLocale();
53: getSession().setLocale(Locale.GERMANY);
54:
55: super .configureResponse();
56:
57: // This is no longer useful in many cases, since we now forward the
58: // <?xml ..encoding=".." ?> from the Page's markup and use it explicitly
59: // set the responses encoding (see super class implementation).
60: // It is however not completely useless, as many html (not xhtml) pages
61: // might not have that xml declaration <?xml ..?> string.
62: /*
63: * final String encoding = "text/" + getMarkupType() + "; charset=" +
64: * CharSetUtil.getEncoding(getRequestCycle());
65: *
66: * getResponse().setContentType(encoding);
67: */
68: getSession().setLocale(originalLocale);
69: }
70: }
|