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 org.apache.tapestry.ComponentResources;
18: import org.apache.tapestry.TapestryConstants;
19: import org.apache.tapestry.internal.structure.Page;
20: import org.apache.tapestry.internal.util.ContentType;
21: import org.apache.tapestry.services.MetaDataLocator;
22: import org.apache.tapestry.services.Request;
23:
24: public class RequestEncodingInitializerImpl implements
25: RequestEncodingInitializer {
26: private final RequestPageCache _cache;
27:
28: private final MetaDataLocator _locator;
29:
30: private final Request _request;
31:
32: public RequestEncodingInitializerImpl(RequestPageCache cache,
33: MetaDataLocator locator, Request request) {
34: _cache = cache;
35: _locator = locator;
36: _request = request;
37: }
38:
39: public void initializeRequestEncoding(String pageName) {
40: Page page = _cache.get(pageName);
41: ComponentResources pageResources = page.getRootElement()
42: .getComponentResources();
43:
44: String contentTypeString = _locator.findMeta(
45: TapestryConstants.RESPONSE_CONTENT_TYPE, pageResources);
46: ContentType contentType = new ContentType(contentTypeString);
47:
48: String encoding = contentType.getParameter("charset");
49:
50: if (encoding == null)
51: encoding = _locator.findMeta(
52: TapestryConstants.RESPONSE_ENCODING, pageResources);
53:
54: _request.setEncoding(encoding);
55: }
56:
57: }
|