Author: ehillenius Date: Thu Jan 18 16:39:39 2007 New Revision: 497661 URL: http://svn.apache.org/viewvc?view=rev&rev=497661 Log: WICKET-224
Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupCacheKeyProvider.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupResourceStreamProvider.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupCacheKeyProvider.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupResourceStreamProvider.java Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/MarkupContainer.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupCache.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupResourceStream.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/WebApplication.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/resource/PropertiesFactory.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/IResourceSettings.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/Settings.java Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/MarkupContainer.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/MarkupContainer.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/MarkupContainer.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/MarkupContainer.java Thu Jan 18 16:39:39 2007 @@ -28,18 +28,14 @@ import wicket.feedback.IFeedback; import wicket.markup.ComponentTag; -import wicket.markup.ContainerInfo; import wicket.markup.MarkupElement; import wicket.markup.MarkupException; import wicket.markup.MarkupNotFoundException; -import wicket.markup.MarkupResourceStream; import wicket.markup.MarkupStream; import wicket.markup.WicketTag; import wicket.markup.resolver.IComponentResolver; import wicket.model.ICompoundModel; import wicket.model.IModel; -import wicket.util.resource.IResourceStream; -import wicket.util.resource.locator.IResourceStreamLocator; import wicket.util.string.Strings; import wicket.version.undo.Change; @@ -849,52 +845,6 @@ + " Enable debug messages for wicket.util.resource to get a list of all filenames tried"), ex); } - } - - /** - * Create a new markup resource stream for the container. - * <p> - * Note: it will only called once, the IResourceStream will be cached by - * MarkupCache. - * <p> - * Note: IResourceStreamLocators should be used in case the strategy to find - * a markup resource should be extended for ALL components of your - * application. - * - * @see wicket.util.resource.locator.IResourceStreamLocator - * @see wicket.markup.MarkupCache - * - * @param containerClass - * The container the markup should be associated with - * @return A IResourceStream if the resource was found - */ - public IResourceStream newMarkupResourceStream(Class containerClass) - { - // Get locator to search for the resource - final IResourceStreamLocator locator = getApplication().getResourceSettings() - .getResourceStreamLocator(); - - // Markup is associated with the containers class. Walk up the class - // hierarchy up to MarkupContainer to find the containers markup - // resource. - while (containerClass != MarkupContainer.class) - { - final IResourceStream resourceStream = locator.locate(containerClass, containerClass - .getName().replace('.', '/'), getStyle(), getLocale(), getMarkupType()); - - // Did we find it already? - if (resourceStream != null) - { - return new MarkupResourceStream(resourceStream, new ContainerInfo(this), - containerClass); - } - - // Walk up the class hierarchy one level, if markup has not - // yet been found - containerClass = containerClass.getSuperclass(); - } - - return null; } /** Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupCacheKeyProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupCacheKeyProvider.java?view=auto&rev=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupCacheKeyProvider.java (added) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupCacheKeyProvider.java Thu Jan 18 16:39:39 2007 @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup; + +import java.util.Locale; + +import wicket.MarkupContainer; +import wicket.util.string.AppendingStringBuffer; + +/** + * Wicket default implementation for the cache key used to reference the cached + * markup resource stream. + * + * @author Jonathan Locke + * @author Juergen Donnerstag + */ +public class DefaultMarkupCacheKeyProvider implements IMarkupCacheKeyProvider +{ + /** + * Constructor. + */ + public DefaultMarkupCacheKeyProvider() + { + } + + /** + * Construct a proper key value for the cache + * + * @param container + * The container requesting the markup + * @param clazz + * The clazz to get the key for + * @return Key that uniquely identifies any markup that might be associated + * with this markup container. + */ + public CharSequence getCacheKey(final MarkupContainer container, final Class clazz) + { + final String classname = clazz.getName(); + final Locale locale = container.getLocale(); + final String style = container.getStyle(); + final String markupType = container.getMarkupType(); + + final AppendingStringBuffer buffer = new AppendingStringBuffer(classname.length() + 32); + buffer.append(classname); + + if (locale != null) + { + // TODO What is wrong with locale.toString()?!? + final boolean l = locale.getLanguage().length() != 0; + final boolean c = locale.getCountry().length() != 0; + final boolean v = locale.getVariant().length() != 0; + buffer.append(locale.getLanguage()); + if (c || (l && v)) + { + buffer.append('_').append(locale.getCountry()); // This may just + // append '_' + } + if (v && (l || c)) + { + buffer.append('_').append(locale.getVariant()); + } + } + if (style != null) + { + buffer.append(style); + } + + buffer.append(markupType); + return buffer; + } +} Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupResourceStreamProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupResourceStreamProvider.java?view=auto&rev=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupResourceStreamProvider.java (added) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/DefaultMarkupResourceStreamProvider.java Thu Jan 18 16:39:39 2007 @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup; + +import java.util.Locale; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import wicket.Application; +import wicket.MarkupContainer; +import wicket.util.resource.IResourceStream; +import wicket.util.resource.locator.IResourceStreamLocator; + +/** + * Wicket default implementation for loading the markup resource stream + * associated with a MarkupContainer. + * + * @author Jonathan Locke + * @author Juergen Donnerstag + */ +public class DefaultMarkupResourceStreamProvider implements IMarkupResourceStreamProvider +{ + /** Log for reporting. */ + private static final Log log = LogFactory.getLog(DefaultMarkupResourceStreamProvider.class); + + /** + * Constructor. + */ + public DefaultMarkupResourceStreamProvider() + { + } + + /** + * Create a new markup resource stream for the container. + * <p> + * Note: it will only called once, the IResourceStream will be cached by + * MarkupCache. + * <p> + * Note: IResourceStreamLocators should be used in case the strategy to find + * a markup resource should be extended for ALL components of your + * application. + * + * @see wicket.util.resource.locator.IResourceStreamFactory + * @see wicket.markup.DefaultMarkupResourceStreamProvider + * + * @param container + * @param containerClass + * The container the markup should be associated with + * @return A IResourceStream if the resource was found + */ + public IResourceStream getMarkupResourceStream(final MarkupContainer container, + Class containerClass) + { + // Get locator to search for the resource + final IResourceStreamLocator locator = Application.get().getResourceSettings() + .getResourceStreamLocator(); + + String style = container.getStyle(); + Locale locale = container.getLocale(); + String ext = container.getMarkupType(); + + // Markup is associated with the containers class. Walk up the class + // hierarchy up to MarkupContainer to find the containers markup + // resource. + while (containerClass != MarkupContainer.class) + { + String path = containerClass.getName().replace('.', '/'); + IResourceStream resourceStream = locator.locate(container.getClass(), path, style, + locale, ext); + + // Did we find it already? + if (resourceStream != null) + { + return new MarkupResourceStream(resourceStream, new ContainerInfo(container), + containerClass); + } + + // Walk up the class hierarchy one level, if markup has not + // yet been found + containerClass = (Class)containerClass.getSuperclass(); + } + + return null; + } +} Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupCacheKeyProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupCacheKeyProvider.java?view=auto&rev=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupCacheKeyProvider.java (added) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupCacheKeyProvider.java Thu Jan 18 16:39:39 2007 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup; + +import wicket.MarkupContainer; + +/** + * To be implemented by MarkupContainers which whish to implement there own + * algorithms for the markup cache key. + * + * @author Juergen Donnerstag + */ +public interface IMarkupCacheKeyProvider +{ + /** + * Provide the markup cache key for the associated Markup resource stream. + * + * @see IMarkupResourceStreamProvider + * + * @param container + * The MarkupContainer object requesting the markup cache key + * @param containerClass + * The container the markup should be associated with + * @return A IResourceStream if the resource was found + */ + CharSequence getCacheKey(final MarkupContainer container, Class containerClass); +} Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupResourceStreamProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupResourceStreamProvider.java?view=auto&rev=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupResourceStreamProvider.java (added) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/IMarkupResourceStreamProvider.java Thu Jan 18 16:39:39 2007 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup; + +import wicket.MarkupContainer; +import wicket.util.resource.IResourceStream; + +/** + * To be implemented by MarkupContainer which whish to implement there own + * algorithms for loading the markup resource stream. + * <p> + * Note: IResourceStreamLocators should be used in case the strategy to find a + * markup resource is meant to be applied to ALL components of your application. + * <p> + * Note: See IMarkupCacheKeyProvider if you whish to implement your own cache + * key algorithm, which sometimes is useful when the MarkupContainer implements + * its own IMarkupResourceStreamProvider as well. + * + * @see IMarkupCacheKeyProvider + * + * @author Juergen Donnerstag + */ +public interface IMarkupResourceStreamProvider +{ + /** + * Create a new markup resource stream for the container. + * <p> + * Note: usually it will only called once, as the IResourceStream will be + * cached by MarkupCache. + * + * @param container + * The MarkupContainer which requests to load the Markup resource + * stream + * @param containerClass + * The container the markup should be associated with + * @return A IResourceStream if the resource was found + */ + IResourceStream getMarkupResourceStream(final MarkupContainer container, Class containerClass); +} Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupCache.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupCache.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupCache.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupCache.java Thu Jan 18 16:39:39 2007 @@ -17,8 +17,6 @@ package wicket.markup; import java.io.IOException; -import java.util.Iterator; -import java.util.Locale; import java.util.Map; import org.apache.commons.logging.Log; @@ -31,7 +29,6 @@ import wicket.util.listener.IChangeListener; import wicket.util.resource.IResourceStream; import wicket.util.resource.ResourceStreamNotFoundException; -import wicket.util.string.AppendingStringBuffer; import wicket.util.watch.ModificationWatcher; import wicket.util.watch.Watcher; @@ -143,33 +140,6 @@ } /** - * Remove the markup from the cache and trigger all associated listeners - * - * @since 1.2.3 - * @param markupResourceStream - * The resource stream - */ - public void removeMarkup(final MarkupResourceStream markupResourceStream) - { - CharSequence key = null; - Iterator iter = this.markupCache.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry entry = (Map.Entry)iter.next(); - if (entry.getValue() == markupResourceStream) - { - key = (CharSequence)entry.getKey(); - break; - } - } - - if (key != null) - { - removeMarkup(key, markupResourceStream); - } - } - - /** * @return the number of elements currently in the cache. */ public int size() @@ -185,14 +155,11 @@ * * @param container * The original requesting markup container - * @param key - * Key under which markup should be cached * @param markup * The markup to checked for inheritance * @return A markup object with the the base markup elements resolved. */ - private Markup checkForMarkupInheritance(final MarkupContainer container, - final CharSequence key, final Markup markup) + private Markup checkForMarkupInheritance(final MarkupContainer container, final Markup markup) { // Check if markup contains <wicket:extend> which tells us that // we need to read the inherited markup as well. @@ -215,40 +182,45 @@ + " Enable debug messages for wicket.util.resource.Resource to get a list of all filenames tried."); } - // register an after-load listener for base markup. The listener - // implementation will remove the derived markup which must be merged - // with the base markup - afterLoadListeners.add(baseMarkup.getResource(), new IChangeListener() - { - /** - * Make sure there is only one listener per derived markup - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) + final CharSequence key = markup.getResource().getCacheKey(); + if (key != null) + { + // register an after-load listener for base markup. The listener + // implementation will remove the derived markup which must be + // merged + // with the base markup + afterLoadListeners.add(baseMarkup.getResource(), new IChangeListener() { - return true; - } + /** + * Make sure there is only one listener per derived markup + * + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) + { + return true; + } - /** - * Make sure there is only one listener per derived markup - * - * @see java.lang.Object#hashCode() - */ - public int hashCode() - { - return key.hashCode(); - } + /** + * Make sure there is only one listener per derived markup + * + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + return key.hashCode(); + } - public void onChange() - { - if (log.isDebugEnabled()) + public void onChange() { - log.debug("Remove derived markup from cache: " + markup.getResource()); + if (log.isDebugEnabled()) + { + log.debug("Remove derived markup from cache: " + markup.getResource()); + } + removeMarkup(markup.getResource()); } - removeMarkup(key, markup.getResource()); - } - }); + }); + } // Merge base and derived markup Markup mergedMarkup = new MergedMarkup(markup, baseMarkup, extendIndex); @@ -282,40 +254,56 @@ } } - // Look up markup tag list by class, locale, style and markup type - final CharSequence key = markupKey(container, clazz); - Markup markup = (Markup)markupCache.get(key); + // Get the cache key to be associated with the markup resource stream + final IMarkupCacheKeyProvider markupCacheKeyProvider = getMarkupCacheKeyProvider(container); + final CharSequence cacheKey = markupCacheKeyProvider.getCacheKey(container, clazz); + + // Markup already in the cache? If cacheKey == null, than don't cache + // the markup resource stream + Markup markup = null; + if (cacheKey != null) + { + markup = (Markup)markupCache.get(cacheKey); + } - // If no markup in the cache + // Must Markup be loaded? if (markup == null) { synchronized (markupCache) { - markup = (Markup)markupCache.get(key); + if (cacheKey != null) + { + markup = (Markup)markupCache.get(cacheKey); + } - // If no markup is in the cache + // Must Markup be loaded? if (markup == null) { - // Ask the container to locate its associated markup - final IResourceStream resourceStream = container - .newMarkupResourceStream(containerClass); + // Who is going to provide the markup resource stream? + final IMarkupResourceStreamProvider markupResourceStreamProvider = getMarkupResourceStreamProvider(container); + + // Ask the provider to locate the markup resource stream + final IResourceStream resourceStream = markupResourceStreamProvider + .getMarkupResourceStream(container, containerClass); // Found markup? if (resourceStream != null) { - final MarkupResourceStream markupResource; + final MarkupResourceStream markupResourceStream; if (resourceStream instanceof MarkupResourceStream) { - markupResource = (MarkupResourceStream)resourceStream; + markupResourceStream = (MarkupResourceStream)resourceStream; } else { - markupResource = new MarkupResourceStream(resourceStream, + markupResourceStream = new MarkupResourceStream(resourceStream, new ContainerInfo(container), containerClass); } + markupResourceStream.setCacheKey(cacheKey); + // load the markup and watch for changes - markup = loadMarkupAndWatchForChanges(container, key, markupResource); + markup = loadMarkupAndWatchForChanges(container, markupResourceStream); } else { @@ -326,7 +314,10 @@ // Save any markup list (or absence of one) for next // time - markupCache.put(key, markup); + if (cacheKey != null) + { + markupCache.put(cacheKey, markup); + } } } } @@ -339,15 +330,14 @@ * * @param container * The original requesting markup container - * @param key - * Key under which markup should be cached * @param markupResourceStream * The markup resource stream to load * @return The markup */ - private final Markup loadMarkup(final MarkupContainer container, final CharSequence key, + private final Markup loadMarkup(final MarkupContainer container, final MarkupResourceStream markupResourceStream) { + CharSequence cacheKey = markupResourceStream.getCacheKey(); try { // read and parse the markup @@ -356,10 +346,13 @@ // Check for markup inheritance. If it contains <wicket:extend> // the two markups get merged. - markup = checkForMarkupInheritance(container, key, markup); + markup = checkForMarkupInheritance(container, markup); // add the markup to the cache - markupCache.put(key, markup); + if (cacheKey != null) + { + markupCache.put(cacheKey, markup); + } // trigger all listeners registered on the markup just loaded afterLoadListeners.notifyListeners(markupResourceStream); @@ -375,10 +368,14 @@ log.error("Unable to read markup from " + markupResourceStream, e); } + // In case of an error, remove the cache entry synchronized (markupCache) { - markupCache.remove(key); - afterLoadListeners.remove(markupResourceStream); + if (cacheKey != null) + { + markupCache.remove(cacheKey); + afterLoadListeners.remove(markupResourceStream); + } } return Markup.NO_MARKUP; @@ -392,104 +389,61 @@ * * @param container * The original requesting markup container - * @param key - * The key for the resource * @param markupResourceStream * The markup stream to load and begin to watch * @return The markup in the stream */ private final Markup loadMarkupAndWatchForChanges(final MarkupContainer container, - final CharSequence key, final MarkupResourceStream markupResourceStream) + final MarkupResourceStream markupResourceStream) { - // Watch file in the future - final ModificationWatcher watcher = application.getResourceSettings().getResourceWatcher(); - if (watcher != null) + if (markupResourceStream.getCacheKey() != null) { - watcher.add(markupResourceStream, new IChangeListener() + // Watch file in the future + final ModificationWatcher watcher = application.getResourceSettings() + .getResourceWatcher(true); + if (watcher != null) { - public void onChange() + watcher.add(markupResourceStream, new IChangeListener() { - if (log.isDebugEnabled()) + public void onChange() { - log.debug("Remove markup from cache: " + markupResourceStream); - } + if (log.isDebugEnabled()) + { + log.debug("Remove markup from cache: " + markupResourceStream); + } - // Remove the markup from the cache. It will be reloaded - // next time it the markup is requested. - removeMarkup(key, markupResourceStream); - watcher.remove(markupResourceStream); - } - }); + // Remove the markup from the cache. It will be reloaded + // next time it the markup is requested. + removeMarkup(markupResourceStream); + watcher.remove(markupResourceStream); + } + }); + } } if (log.isDebugEnabled()) { log.debug("Loading markup from " + markupResourceStream); } - return loadMarkup(container, key, markupResourceStream); - } - - /** - * Construct a proper key value for the cache - * - * @param container - * The container requesting the markup - * @param clazz - * The clazz to get the key for - * @return Key that uniquely identifies any markup that might be associated - * with this markup container. - */ - private final CharSequence markupKey(final MarkupContainer container, final Class clazz) - { - final String classname = clazz.getName(); - final Locale locale = container.getLocale(); - final String style = container.getStyle(); - final String markupType = container.getMarkupType(); - - final AppendingStringBuffer buffer = new AppendingStringBuffer(classname.length() + 32); - buffer.append(classname); - - if (locale != null) - { - boolean l = locale.getLanguage().length() != 0; - boolean c = locale.getCountry().length() != 0; - boolean v = locale.getVariant().length() != 0; - buffer.append(locale.getLanguage()); - if (c || (l && v)) - { - buffer.append('_').append(locale.getCountry()); // This may just - // append '_' - } - if (v && (l || c)) - { - buffer.append('_').append(locale.getVariant()); - } - } - if (style != null) - { - buffer.append(style); - } - - buffer.append(markupType); - return buffer; + return loadMarkup(container, markupResourceStream); } /** * Remove the markup from the cache and trigger all associated listeners * - * @param key - * The cache key * @param markupResourceStream * The resource stream */ - private void removeMarkup(final CharSequence key, - final MarkupResourceStream markupResourceStream) + private void removeMarkup(final MarkupResourceStream markupResourceStream) { - markupCache.remove(key); - - // trigger all listeners registered on the markup that is removed - afterLoadListeners.notifyListeners(markupResourceStream); - afterLoadListeners.remove(markupResourceStream); + CharSequence cacheKey = markupResourceStream.getCacheKey(); + if (cacheKey != null) + { + markupCache.remove(cacheKey); + // trigger all listeners registered on the markup that is removed + afterLoadListeners.notifyListeners(markupResourceStream); + afterLoadListeners.remove(markupResourceStream); + } } /** @@ -517,5 +471,40 @@ } } return -1; + } + + /** + * Determine the markup cache key provider to be used + * + * @param container + * The MarkupContainer requesting the markup resource stream + * @return IMarkupResourceStreamProvider + */ + protected IMarkupCacheKeyProvider getMarkupCacheKeyProvider(final MarkupContainer container) + { + if (container instanceof IMarkupCacheKeyProvider) + { + return (IMarkupCacheKeyProvider)container; + } + + return new DefaultMarkupCacheKeyProvider(); + } + + /** + * Determine the markup resource stream provider to be used + * + * @param container + * The MarkupContainer requesting the markup resource stream + * @return IMarkupResourceStreamProvider + */ + protected IMarkupResourceStreamProvider getMarkupResourceStreamProvider( + final MarkupContainer container) + { + if (container instanceof IMarkupResourceStreamProvider) + { + return (IMarkupResourceStreamProvider)container; + } + + return new DefaultMarkupResourceStreamProvider(); } } Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupResourceStream.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupResourceStream.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupResourceStream.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/MarkupResourceStream.java Thu Jan 18 16:39:39 2007 @@ -49,6 +49,9 @@ */ private final Class markupClass; + /** The key used to cache the markup resource stream */ + private CharSequence cacheKey; + /** * Construct. * @@ -151,6 +154,24 @@ public ContainerInfo getContainerInfo() { return containerInfo; + } + + /** + * Gets cacheKey. + * @return cacheKey + */ + public final CharSequence getCacheKey() + { + return cacheKey; + } + + /** + * Set the cache key + * @param cacheKey + */ + public final void setCacheKey(final CharSequence cacheKey) + { + this.cacheKey = cacheKey; } /** Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/WebApplication.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/WebApplication.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/WebApplication.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/WebApplication.java Thu Jan 18 16:39:39 2007 @@ -468,9 +468,11 @@ */ protected void internalDestroy() { - ModificationWatcher resourceWatcher = getResourceSettings().getResourceWatcher(); + ModificationWatcher resourceWatcher = getResourceSettings().getResourceWatcher(false); if (resourceWatcher != null) + { resourceWatcher.destroy(); + } super.internalDestroy(); bufferedResponses.clear(); // destroy the resource watcher Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/resource/PropertiesFactory.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/resource/PropertiesFactory.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/resource/PropertiesFactory.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/resource/PropertiesFactory.java Thu Jan 18 16:39:39 2007 @@ -80,10 +80,11 @@ } /** - * @see wicket.resource.IPropertiesFactory#get(wicket.Application, java.lang.Class, java.lang.String, java.util.Locale) + * @see wicket.resource.IPropertiesFactory#get(wicket.Application, + * java.lang.Class, java.lang.String, java.util.Locale) */ - public Properties get(final Application application, final Class clazz, - final String style, final Locale locale) + public Properties get(final Application application, final Class clazz, final String style, + final Locale locale) { final String key = createResourceKey(clazz, locale, style); Properties props = (Properties)propertiesCache.get(key); @@ -117,7 +118,7 @@ { return this.propertiesCache; } - + /** * @see wicket.resource.IPropertiesFactory#clearCache() */ @@ -159,7 +160,7 @@ buffer.append(locale.getLanguage()); if (c || (l && v)) { - // This may just append '_' + // This may just append '_' buffer.append('_').append(locale.getCountry()); } if (v && (l || c)) @@ -262,19 +263,20 @@ { // Watch file modifications final ModificationWatcher watcher = Application.get().getResourceSettings() - .getResourceWatcher(); + .getResourceWatcher(true); if (watcher != null) { watcher.add(resourceStream, new IChangeListener() { public void onChange() { - log.info("A properties files has changed. Remove all entries from the cache. Resource: " - + resourceStream); + log.info("A properties files has changed. Remove all entries " + + "from the cache. Resource: " + resourceStream); // Clear the whole cache as associated localized files may - // be affected and may need reloading as well. We make it - // easy. Usually the watcher is activ in dev mode only anyway. + // be affected and may need reloading as well. We make it + // easy. Usually the watcher is activ in dev mode only + // anyway. clearCache(); // Inform all listeners Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/IResourceSettings.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/IResourceSettings.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/IResourceSettings.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/IResourceSettings.java Thu Jan 18 16:39:39 2007 @@ -161,10 +161,14 @@ IResourceStreamLocator getResourceStreamLocator(); /** + * @param start + * boolean if the resource watcher should be started if not + * already started. + * * @return Resource watcher with polling frequency determined by setting, or * null if no polling frequency has been set. */ - ModificationWatcher getResourceWatcher(); + ModificationWatcher getResourceWatcher(boolean start); /** * @return an unmodifiable list of all available string resource loaders Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/Settings.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/Settings.java?view=diff&rev=497661&r1=497660&r2=497661 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/Settings.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/settings/Settings.java Thu Jan 18 16:39:39 2007 @@ -652,11 +652,11 @@ } /** - * @see wicket.settings.IResourceSettings#getResourceWatcher() + * @see wicket.settings.IResourceSettings#getResourceWatcher(boolean) */ - public ModificationWatcher getResourceWatcher() + public ModificationWatcher getResourceWatcher(boolean start) { - if (resourceWatcher == null) + if (resourceWatcher == null && start) { final Duration pollFrequency = getResourcePollFrequency(); if (pollFrequency != null)