Updated Branches: refs/heads/master a293ddf75 -> 2b03c0253
WICKET-4530 new interface IResourceNameIterator, allowing custom iteration Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2b03c025 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2b03c025 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2b03c025 Branch: refs/heads/master Commit: 2b03c02537fef242d761c5ba59de1087b54fee7e Parents: a293ddf Author: Sven Meier <[email protected]> Authored: Tue May 8 23:59:14 2012 +0200 Committer: Sven Meier <[email protected]> Committed: Tue May 8 23:59:14 2012 +0200 ---------------------------------------------------------------------- .../resource/locator/IResourceNameIterator.java | 57 +++++++++++++++ .../resource/locator/IResourceStreamLocator.java | 18 +++--- .../resource/locator/ResourceNameIterator.java | 22 +++--- .../resource/locator/ResourceStreamLocator.java | 22 +++--- .../caching/CachingResourceStreamLocator.java | 8 +- .../loader/ComponentStringResourceLoader.java | 16 ++-- .../loader/PackageStringResourceLoader.java | 4 +- 7 files changed, 102 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceNameIterator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceNameIterator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceNameIterator.java new file mode 100644 index 0000000..44d2ac2 --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceNameIterator.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.wicket.core.util.resource.locator; + +import java.util.Iterator; +import java.util.Locale; + +/** + * Contains the logic to locate a resource based on a path, style (see + * {@link org.apache.wicket.Session}), variation, locale and extension strings. + * + * @author Juergen Donnerstag + */ +public interface IResourceNameIterator extends Iterator<String> +{ + /** + * Get the exact Locale which has been used for the latest resource path. + * + * @return current Locale + */ + public Locale getLocale(); + + /** + * Get the exact Style which has been used for the latest resource path. + * + * @return current Style + */ + public String getStyle(); + + /** + * Get the exact Variation which has been used for the latest resource path. + * + * @return current Variation + */ + public String getVariation(); + + /** + * Get the exact filename extension used for the latest resource path. + * + * @return current filename extension + */ + public String getExtension(); +} http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java index cf52ce4..86fa41a 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java @@ -23,7 +23,7 @@ import org.apache.wicket.util.resource.IResourceStream; /** * Interface for code that locates resources. - * + * * @author Jonathan Locke */ public interface IResourceStreamLocator @@ -32,15 +32,15 @@ public interface IResourceStreamLocator * Locate a resource, given a path and class. Typically this method is either called by external * clients if they are not interested in a lookup that takes the style and locale into account, * or it is called by the implementation of - * {@link #locate(Class, String, String, String, java.util.Locale, String, boolean)} where the latter just takes care of - * trying out the different combinations for the provided style and locale and uses this method - * to actually load the resource stream. - * + * {@link #locate(Class, String, String, String, java.util.Locale, String, boolean)} where the + * latter just takes care of trying out the different combinations for the provided style and + * locale and uses this method to actually load the resource stream. + * * @param clazz * The class loader for delegating the loading of the resource * @param path * The path of the resource - * + * * @return The resource or null */ IResourceStream locate(Class<?> clazz, String path); @@ -48,7 +48,7 @@ public interface IResourceStreamLocator /** * Locate a resource by combining the given path, style, variation, locale and extension * parameters. The exact search order depends on the implementation. - * + * * @param clazz * The class loader for delegating the loading of the resource * @param path @@ -72,7 +72,7 @@ public interface IResourceStreamLocator * Markup resources and Properties files both need to iterate over different combinations of * locale, style, etc.. And though no single locate(..) method exists which is used by both, * they both use ResourceNameIterators. - * + * * @param path * The path of the resource * @param style @@ -87,6 +87,6 @@ public interface IResourceStreamLocator * whether the specified attributes must match exactly * @return resource name iterator */ - ResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, + IResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, String variation, String extension, boolean strict); } http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceNameIterator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceNameIterator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceNameIterator.java index 899042e..66de15c 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceNameIterator.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceNameIterator.java @@ -17,7 +17,6 @@ package org.apache.wicket.core.util.resource.locator; import java.util.Arrays; -import java.util.Iterator; import java.util.Locale; import org.apache.wicket.WicketRuntimeException; @@ -44,10 +43,10 @@ import org.apache.wicket.util.string.Strings; * <li><language>_<country></li> * <li><language></li> * </ol> - * + * * @author Juergen Donnerstag */ -public class ResourceNameIterator implements Iterator<String> +public class ResourceNameIterator implements IResourceNameIterator { // The base path without extension, style, locale etc. private final String path; @@ -69,7 +68,7 @@ public class ResourceNameIterator implements Iterator<String> /** * Construct. - * + * * @param path * The path of the resource. In case the parameter 'extensions' is null, the path * will be checked and if a filename extension is present, it'll be used instead. @@ -109,7 +108,7 @@ public class ResourceNameIterator implements Iterator<String> /** * Get the exact Locale which has been used for the latest resource path. - * + * * @return current Locale */ public final Locale getLocale() @@ -119,7 +118,7 @@ public class ResourceNameIterator implements Iterator<String> /** * Get the exact Style which has been used for the latest resource path. - * + * * @return current Style */ public final String getStyle() @@ -129,7 +128,7 @@ public class ResourceNameIterator implements Iterator<String> /** * Get the exact Variation which has been used for the latest resource path. - * + * * @return current Variation */ public final String getVariation() @@ -139,7 +138,7 @@ public class ResourceNameIterator implements Iterator<String> /** * Get the exact filename extension used for the latest resource path. - * + * * @return current filename extension */ public final String getExtension() @@ -237,7 +236,7 @@ public class ResourceNameIterator implements Iterator<String> } /** - * + * * @param string * @param prepend * @return The string prepended with the char @@ -259,7 +258,7 @@ public class ResourceNameIterator implements Iterator<String> } /** - * + * * @param style * @param variation * @return new iterator @@ -274,7 +273,8 @@ public class ResourceNameIterator implements Iterator<String> * @param extensions * @return New iterator */ - protected ExtensionResourceNameIterator newExtensionResourceNameIterator(final Iterable<String> extensions) + protected ExtensionResourceNameIterator newExtensionResourceNameIterator( + final Iterable<String> extensions) { return new ExtensionResourceNameIterator(extensions); } http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java index 2cbbc2a..1fa1f0e 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java @@ -23,11 +23,11 @@ import java.util.Collections; import java.util.Locale; import org.apache.wicket.Application; +import org.apache.wicket.core.util.resource.UrlResourceStream; import org.apache.wicket.util.file.IResourceFinder; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.ResourceUtils; import org.apache.wicket.util.resource.ResourceUtils.PathLocale; -import org.apache.wicket.core.util.resource.UrlResourceStream; import org.apache.wicket.util.string.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +55,7 @@ import org.slf4j.LoggerFactory; * <li><language>_<country></li> * <li><language></li> * </ol> - * + * * @author Juergen Donnerstag * @author Jonathan Locke */ @@ -78,7 +78,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator /** * Constructor - * + * * @param finder * resource finder */ @@ -88,7 +88,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator } /** - * + * * @see org.apache.wicket.core.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, * java.lang.String) */ @@ -114,7 +114,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator } /** - * + * * @see org.apache.wicket.core.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, * java.lang.String, java.lang.String, java.lang.String, java.util.Locale, * java.lang.String, boolean) @@ -132,7 +132,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator } // Try the various combinations of style, locale and extension to find the resource. - ResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation, + IResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation, extension, strict); while (iter.hasNext()) { @@ -153,7 +153,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator /** * Search the the resource my means of the various classloaders available - * + * * @param clazz * @param path * @return resource stream @@ -190,7 +190,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator /** * Get the resource - * + * * @param classLoader * @param path * @return resource stream @@ -225,7 +225,7 @@ public class ResourceStreamLocator implements IResourceStreamLocator /** * Search the resource by means of the application registered resource finder - * + * * @param clazz * @param path * @return resource stream @@ -248,12 +248,12 @@ public class ResourceStreamLocator implements IResourceStreamLocator } /** - * + * * @see org.apache.wicket.core.util.resource.locator.IResourceStreamLocator#newResourceNameIterator(java.lang.String, * java.util.Locale, java.lang.String, java.lang.String, java.lang.String, boolean) */ @Override - public ResourceNameIterator newResourceNameIterator(final String path, final Locale locale, + public IResourceNameIterator newResourceNameIterator(final String path, final Locale locale, final String style, final String variation, final String extension, final boolean strict) { final Iterable<String> extensions; http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/caching/CachingResourceStreamLocator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/caching/CachingResourceStreamLocator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/caching/CachingResourceStreamLocator.java index 84c105a..48506d8 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/caching/CachingResourceStreamLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/caching/CachingResourceStreamLocator.java @@ -21,8 +21,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.wicket.core.util.resource.UrlResourceStream; +import org.apache.wicket.core.util.resource.locator.IResourceNameIterator; import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator; -import org.apache.wicket.core.util.resource.locator.ResourceNameIterator; import org.apache.wicket.request.resource.ResourceReference.Key; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.resource.FileResourceStream; @@ -49,7 +49,7 @@ public class CachingResourceStreamLocator implements IResourceStreamLocator /** * Construct. - * + * * @param resourceStreamLocator * the delegate */ @@ -64,7 +64,7 @@ public class CachingResourceStreamLocator implements IResourceStreamLocator /** * {@inheritDoc} - * + * * Checks for {@link IResourceStreamReference} in the cache and returns <code>null</code> if the * result is {@link NullResourceStreamReference#INSTANCE}, or {@link FileResourceStream} / * {@link UrlResourceStream} if there is an entry in the cache. Otherwise asks the delegate to @@ -132,7 +132,7 @@ public class CachingResourceStreamLocator implements IResourceStreamLocator } @Override - public ResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, + public IResourceNameIterator newResourceNameIterator(String path, Locale locale, String style, String variation, String extension, boolean strict) { return delegate.newResourceNameIterator(path, locale, style, variation, extension, strict); http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java b/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java index c9bfcf1..f549983 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java @@ -24,6 +24,8 @@ import org.apache.wicket.Application; import org.apache.wicket.Component; import org.apache.wicket.MarkupContainer; import org.apache.wicket.Page; +import org.apache.wicket.core.util.resource.locator.IResourceNameIterator; +import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator; import org.apache.wicket.markup.html.WebComponent; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.WebPage; @@ -31,8 +33,6 @@ import org.apache.wicket.markup.repeater.AbstractRepeater; import org.apache.wicket.resource.IPropertiesFactory; import org.apache.wicket.resource.Properties; import org.apache.wicket.util.lang.Args; -import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator; -import org.apache.wicket.core.util.resource.locator.ResourceNameIterator; import org.apache.wicket.util.string.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -135,7 +135,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader String path = clazz.getName().replace('.', '/'); // Iterator over all the combinations - ResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation); + IResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation); while (iter.hasNext()) { String newPath = iter.next(); @@ -182,7 +182,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader * @param variation * @return resource name iterator */ - protected ResourceNameIterator newResourceNameIterator(final String path, final Locale locale, + protected IResourceNameIterator newResourceNameIterator(final String path, final Locale locale, final String style, final String variation) { return Application.get() @@ -232,7 +232,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader { // get current component class final Class<?> clazz = current.getClass(); - + // first, try the fully qualified resource name relative to the // component on the path from page down. if (Strings.isEmpty(prefix) == false) @@ -246,7 +246,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader return string; } - // shorten resource key prefix when going downwards (skip for repeaters) + // shorten resource key prefix when going downwards (skip for repeaters) if ((current instanceof AbstractRepeater) == false) { prefix = Strings.afterFirst(prefix, '.'); @@ -277,7 +277,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader Component current = Args.notNull(component, "component"); final StringBuilder buffer = new StringBuilder(); - + while (current.getParent() != null) { final boolean skip = current.getParent() instanceof AbstractRepeater; @@ -296,7 +296,7 @@ public class ComponentStringResourceLoader implements IStringResourceLoader } /** - * return the trail of components from page to specified component + * return the trail of components from page to specified component * * @param component * The component to retrieve path for http://git-wip-us.apache.org/repos/asf/wicket/blob/2b03c025/wicket-core/src/main/java/org/apache/wicket/resource/loader/PackageStringResourceLoader.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/loader/PackageStringResourceLoader.java b/wicket-core/src/main/java/org/apache/wicket/resource/loader/PackageStringResourceLoader.java index b526e71..8b191c3 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/loader/PackageStringResourceLoader.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/loader/PackageStringResourceLoader.java @@ -19,9 +19,9 @@ package org.apache.wicket.resource.loader; import java.util.Locale; import org.apache.wicket.Application; +import org.apache.wicket.core.util.resource.locator.IResourceNameIterator; import org.apache.wicket.resource.IPropertiesFactory; import org.apache.wicket.resource.Properties; -import org.apache.wicket.core.util.resource.locator.ResourceNameIterator; import org.apache.wicket.util.string.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +93,7 @@ public class PackageStringResourceLoader extends ComponentStringResourceLoader } // Iterator over all the combinations - ResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation); + IResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation); while (iter.hasNext()) { String newPath = iter.next();
