001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup; 018 019import java.util.Locale; 020 021import org.apache.wicket.MarkupContainer; 022 023 024/** 025 * Wicket default implementation for the cache key used to reference the cached markup resource 026 * stream. 027 * 028 * @author Jonathan Locke 029 * @author Juergen Donnerstag 030 */ 031public class DefaultMarkupCacheKeyProvider implements IMarkupCacheKeyProvider 032{ 033 /** 034 * Constructor. 035 */ 036 public DefaultMarkupCacheKeyProvider() 037 { 038 } 039 040 /** 041 * Construct a proper key value for the cache 042 * 043 * @param container 044 * The container requesting the markup 045 * @param clazz 046 * The clazz to get the key for 047 * @return Key that uniquely identifies any markup that might be associated with this markup 048 * container. 049 */ 050 @Override 051 public String getCacheKey(final MarkupContainer container, final Class<?> clazz) 052 { 053 final String classname = clazz.getName(); 054 final StringBuilder buffer = new StringBuilder(classname.length() + 64); 055 buffer.append(classname); 056 057 final String variation = container.getVariation(); 058 if (variation != null) 059 { 060 buffer.append('_').append(variation); 061 } 062 063 final String style = container.getStyle(); 064 if (style != null) 065 { 066 buffer.append('_').append(style); 067 } 068 069 final Locale locale = container.getLocale(); 070 if (locale != null) 071 { 072 buffer.append('_').append(locale.toString()); 073 } 074 075 buffer.append('.').append(container.getMarkupType().getExtension()); 076 return buffer.toString(); 077 } 078}