01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.markup;
18:
19: import java.util.Locale;
20:
21: import org.apache.wicket.MarkupContainer;
22: import org.apache.wicket.util.string.AppendingStringBuffer;
23:
24: /**
25: * Wicket default implementation for the cache key used to reference the cached
26: * markup resource stream.
27: *
28: * @author Jonathan Locke
29: * @author Juergen Donnerstag
30: */
31: public class DefaultMarkupCacheKeyProvider implements
32: IMarkupCacheKeyProvider {
33: /**
34: * Constructor.
35: */
36: public DefaultMarkupCacheKeyProvider() {
37: }
38:
39: /**
40: * Construct a proper key value for the cache
41: *
42: * @param container
43: * The container requesting the markup
44: * @param clazz
45: * The clazz to get the key for
46: * @return Key that uniquely identifies any markup that might be associated
47: * with this markup container.
48: */
49: public String getCacheKey(final MarkupContainer container,
50: final Class clazz) {
51: final String classname = clazz.getName();
52: final Locale locale = container.getLocale();
53: // TODO until now getStyle() == style + variation
54: final String style = container.getStyle();
55: final String markupType = container.getMarkupType();
56:
57: final AppendingStringBuffer buffer = new AppendingStringBuffer(
58: classname.length() + 64);
59: buffer.append(classname);
60:
61: if (locale != null) {
62: // TODO What is wrong with locale.toString()?!?
63: final boolean l = locale.getLanguage().length() != 0;
64: final boolean c = locale.getCountry().length() != 0;
65: final boolean v = locale.getVariant().length() != 0;
66: buffer.append(locale.getLanguage());
67: if (c || (l && v)) {
68: buffer.append('_').append(locale.getCountry()); // This may just
69: // append '_'
70: }
71: if (v && (l || c)) {
72: buffer.append('_').append(locale.getVariant());
73: }
74: }
75: if (style != null) {
76: buffer.append(style);
77: }
78:
79: buffer.append(markupType);
80: return buffer.toString();
81: }
82: }
|