You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2007/03/25 11:07:32 UTC
svn commit: r522181 [2/2] - in
/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src: main/java/wicket/
main/java/wicket/markup/ main/java/wicket/markup/html/
main/java/wicket/markup/parser/filter/ main/java/wicket/resource/
main/java/wicket/resourc...
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/FileResourceStream.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/FileResourceStream.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/FileResourceStream.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/FileResourceStream.java Sun Mar 25 02:07:30 2007
@@ -31,7 +31,7 @@
* @see wicket.util.watch.IModifiable
* @author Jonathan Locke
*/
-public class FileResourceStream extends AbstractResourceStream
+public class FileResourceStream extends AbstractResourceStream implements IFixedLocationResourceStream
{
private static final long serialVersionUID = 1L;
@@ -143,5 +143,17 @@
return file.length();
}
return 0;
+ }
+
+ /**
+ * @see wicket.util.resource.IFixedLocationResourceStream#locationAsString()
+ */
+ public String locationAsString()
+ {
+ if (file != null)
+ {
+ return file.getAbsolutePath();
+ }
+ return null;
}
}
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/IFixedLocationResourceStream.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/IFixedLocationResourceStream.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/IFixedLocationResourceStream.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/IFixedLocationResourceStream.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,33 @@
+/*
+ * 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.util.resource;
+
+/**
+ * Non-dynamic resource streams point to fixed locations, like a file or a url.
+ * Such resources should implement this interface and provide clients with
+ * information about the resource location, such that the client is able to
+ * deduct e.g. an extension or URL schema.
+ *
+ * @author eelcohillenius
+ */
+public interface IFixedLocationResourceStream
+{
+ /**
+ * @return The fixed location as a string, e.g. the file name or the URL
+ */
+ String locationAsString();
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/IFixedLocationResourceStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/UrlResourceStream.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/UrlResourceStream.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/UrlResourceStream.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/UrlResourceStream.java Sun Mar 25 02:07:30 2007
@@ -39,7 +39,7 @@
* @see wicket.util.watch.IModifiable
* @author Jonathan Locke
*/
-public class UrlResourceStream extends AbstractResourceStream
+public class UrlResourceStream extends AbstractResourceStream implements IFixedLocationResourceStream
{
private static final long serialVersionUID = 1L;
@@ -306,5 +306,13 @@
public long length()
{
return contentLength;
+ }
+
+ /**
+ * @see wicket.util.resource.IFixedLocationResourceStream#locationAsString()
+ */
+ public String locationAsString()
+ {
+ return url.toExternalForm();
}
}
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ExtensionResourceNameIterator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ExtensionResourceNameIterator.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ExtensionResourceNameIterator.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ExtensionResourceNameIterator.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,113 @@
+/*
+ * 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.util.resource.locator;
+
+import java.util.Iterator;
+
+import wicket.util.string.Strings;
+
+/**
+ * Contains the logic to build the various combinations of file path, style and
+ * locale required while searching for Wicket resources. The full filename will
+ * be built like: <path>_<style>_<locale>.<extension>.
+ * <p>
+ * Resource matches will be attempted in the following order:
+ * <ol>
+ * <li>1. <path>_<style>_<locale>.<extension></li>
+ * <li>2. <path>_<locale>.<extension></li>
+ * <li>3. <path>_<style>.<extension></li>
+ * <li>4. <path>.<extension></li>
+ * </ol>
+ * <p>
+ * Locales may contain a language, a country and a region or variant.
+ * Combinations of these components will be attempted in the following order:
+ * <ol>
+ * <li>locale.toString() see javadoc for Locale for more details</li>
+ * <li><language>_<country></li>
+ * <li><language></li>
+ * </ol>
+ *
+ * @author Juergen Donnerstag
+ * @author Jonathan Locke
+ */
+public class ExtensionResourceNameIterator implements Iterator
+{
+ /** The base path */
+ private final String path;
+
+ private final String[] extensions;
+
+ private int index;
+
+ /**
+ * Construct.
+ *
+ * @param path
+ * @param extension
+ */
+ public ExtensionResourceNameIterator(String path, final String extension)
+ {
+ if (extension == null)
+ {
+ // Get the extension from the path provided
+ extensions = new String[] { "." + Strings.lastPathComponent(path, '.') };
+ path = Strings.beforeLastPathComponent(path, '.');
+ }
+ else
+ {
+ // Extension can be a comma separated list
+ extensions = Strings.split(extension, ',');
+ for (int i = extensions.length - 1; i >= 0; i--)
+ {
+ extensions[i] = extensions[i].trim();
+ if (!extensions[i].startsWith("."))
+ {
+ extensions[i] = "." + extensions[i];
+ }
+ }
+ }
+
+ this.path = path;
+ this.index = 0;
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext()
+ {
+ return (this.index < this.extensions.length);
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next()
+ {
+ return path + this.extensions[this.index++];
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ }
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ExtensionResourceNameIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/IResourceStreamLocator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/IResourceStreamLocator.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/IResourceStreamLocator.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/IResourceStreamLocator.java Sun Mar 25 02:07:30 2007
@@ -46,4 +46,16 @@
*/
public IResourceStream locate(Class clazz, String path, String style, Locale locale,
String extension);
+
+ /**
+ * Loads a resource, given a path, style, locale and extension.
+ *
+ * @param clazz
+ * The class loader for delegating the loading of the resource
+ * @param path
+ * The path of the resource
+ *
+ * @return The resource
+ */
+ public IResourceStream locate(Class clazz, String path);
}
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/LocaleResourceNameIterator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/LocaleResourceNameIterator.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/LocaleResourceNameIterator.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/LocaleResourceNameIterator.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,165 @@
+/*
+ * 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.util.resource.locator;
+
+import java.util.Iterator;
+import java.util.Locale;
+
+import wicket.util.string.Strings;
+
+/**
+ * Contains the logic to build the various combinations of file path, style and
+ * locale required while searching for Wicket resources. The full filename will
+ * be built like: <path>_<style>_<locale>.<extension>.
+ * <p>
+ * Resource matches will be attempted in the following order:
+ * <ol>
+ * <li>1. <path>_<style>_<locale>.<extension></li>
+ * <li>2. <path>_<locale>.<extension></li>
+ * <li>3. <path>_<style>.<extension></li>
+ * <li>4. <path>.<extension></li>
+ * </ol>
+ * <p>
+ * Locales may contain a language, a country and a region or variant.
+ * Combinations of these components will be attempted in the following order:
+ * <ol>
+ * <li>locale.toString() see javadoc for Locale for more details</li>
+ * <li><language>_<country></li>
+ * <li><language></li>
+ * </ol>
+ *
+ * @author Juergen Donnerstag
+ * @author Jonathan Locke
+ */
+public class LocaleResourceNameIterator implements Iterator
+{
+ /** The base path */
+ private final String path;
+
+ /** The locale (see Session) */
+ private final Locale locale;
+
+ /** Internal state */
+ private int state = 0;
+
+ /**
+ * While iterating the various combinations, it will always contain the
+ * current combination used to create the path
+ */
+ private Locale currentLocale;
+
+ /** Internal: used to compare with previous path to avoid duplicates */
+ private String currentPath;
+
+ /**
+ * Construct.
+ *
+ * @param path
+ * @param locale
+ * @param style
+ */
+ public LocaleResourceNameIterator(final String path, final Locale locale)
+ {
+ this.path = path;
+ this.locale = locale;
+ }
+
+ /**
+ * @return Locale
+ */
+ public Locale getLocale()
+ {
+ return currentLocale;
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext()
+ {
+ return (this.state < 4);
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next()
+ {
+ if (locale == null)
+ {
+ state = 999;
+ return path;
+ }
+
+ // 1. Apply Locale default toString() implementation. See Locale.
+ if (state == 0)
+ {
+ this.state++;
+ this.currentLocale = locale;
+ this.currentPath = path + '_' + locale.toString();
+ return this.currentPath;
+ }
+
+ // Get language and country, either of which may be the empty string
+ final String language = locale.getLanguage();
+ final String country = locale.getCountry();
+
+ // 2. If country and language are available
+ if (state == 1)
+ {
+ this.state++;
+
+ if (!Strings.isEmpty(language) && !Strings.isEmpty(country))
+ {
+ this.currentLocale = new Locale(language, country);
+ String newPath = path + '_' + language + '_' + country;
+ if (this.currentPath.equals(newPath) == false)
+ {
+ return newPath;
+ }
+ }
+ }
+
+ // 3. If language is available
+ if (state == 2)
+ {
+ this.state++;
+
+ if (!Strings.isEmpty(language))
+ {
+ this.currentLocale = new Locale(language);
+ return path + '_' + language;
+ }
+ }
+
+ // 4. The path only; without locale
+ this.state++;
+
+ this.currentLocale = null;
+ return path;
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ }
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/LocaleResourceNameIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/OsgiResourceStreamLocator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/OsgiResourceStreamLocator.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/OsgiResourceStreamLocator.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/OsgiResourceStreamLocator.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.util.resource.locator;
+
+import wicket.util.file.IResourceFinder;
+import wicket.util.resource.IResourceStream;
+
+/**
+ * OSGI specific resource stream factory
+ *
+ * @author Juergen Donnerstah
+ */
+public class OsgiResourceStreamLocator extends ResourceStreamLocator
+{
+ /**
+ * Construct.
+ */
+ public OsgiResourceStreamLocator()
+ {
+ }
+
+ /**
+ * Construct.
+ *
+ * @param finder
+ */
+ public OsgiResourceStreamLocator(final IResourceFinder finder)
+ {
+ super(finder);
+ }
+
+ /**
+ *
+ * @see wicket.util.resource.locator.ResourceStreamLocator#locate(java.lang.Class, java.lang.String)
+ */
+ public IResourceStream locate(final Class clazz, final String path)
+ {
+ return super.locate(clazz, "/" + path);
+ }
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/OsgiResourceStreamLocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceNameIterator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceNameIterator.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceNameIterator.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceNameIterator.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,179 @@
+/*
+ * 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.util.resource.locator;
+
+import java.util.Iterator;
+import java.util.Locale;
+
+import wicket.WicketRuntimeException;
+
+/**
+ * Contains the logic to locate a resource based on a path, a style (see
+ * {@link wicket.Session}), a locale and a extension strings. The full filename
+ * will be built like:
+ * <path>_<style>_<locale>.<extension>.
+ * <p>
+ * Resource matches will be attempted in the following order:
+ * <ol>
+ * <li>1. <path>_<style>_<locale>.<extension></li>
+ * <li>2. <path>_<locale>.<extension></li>
+ * <li>3. <path>_<style>.<extension></li>
+ * <li>4. <path>.<extension></li>
+ * </ol>
+ * <p>
+ * Locales may contain a language, a country and a region or variant.
+ * Combinations of these components will be attempted in the following order:
+ * <ol>
+ * <li>locale.toString() see javadoc for Locale for more details</li>
+ * <li><language>_<country></li>
+ * <li><language></li>
+ * </ol>
+ * <p>
+ * Extensions may be a comma separated list of extensions, e.g. "properties,xml"
+ *
+ * @author Juergen Donnerstag
+ */
+public class ResourceNameIterator implements Iterator
+{
+ // The locale to search for the resource file
+ private final Locale locale;
+
+ // The extensions (comma separated) to search for the resource file
+ private final String extensions;
+
+ // The various iterators used to locate the resource file
+ private Iterator styleIterator;
+ private LocaleResourceNameIterator localeIterator;
+ private Iterator extenstionsIterator;
+
+ // The latest exact Locale used
+ private Locale currentLocale;
+
+ /**
+ * Construct.
+ *
+ * @param path
+ * The path of the resource without extension
+ * @param style
+ * A theme or style (see {@link wicket.Session})
+ * @param locale
+ * The Locale to apply
+ * @param extensions
+ * the filname's extensions (comma separated)
+ */
+ public ResourceNameIterator(String path, final String style, final Locale locale,
+ final String extensions)
+ {
+ this.locale = locale;
+ this.extensions = extensions;
+
+ this.styleIterator = new StyleAndVariationResourceNameIterator(path, style, null);
+ }
+
+ /**
+ * Get the exact Locale which has been used for the latest resource path.
+ *
+ * @return current Locale
+ */
+ public final Locale getLocale()
+ {
+ return this.currentLocale;
+ }
+
+ /**
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext()
+ {
+ // Most inner loop. Loop through all extensions provided
+ if (this.extenstionsIterator != null)
+ {
+ if (this.extenstionsIterator.hasNext() == true)
+ {
+ return true;
+ }
+
+ // If there are no more extensions, than return to the next outer
+ // loop (locale), get the next value from that loop and start
+ // over again with the first extension in the list.
+ extenstionsIterator = null;
+ }
+
+ // 2nd inner loop: Loop through all Locale combinations
+ if (this.localeIterator != null)
+ {
+ while (this.localeIterator.hasNext())
+ {
+ // Get the next Locale from the iterator and start the next
+ // inner iterator over again.
+ String newPath = (String) this.localeIterator.next();
+ this.currentLocale = this.localeIterator.getLocale();
+ this.extenstionsIterator = new ExtensionResourceNameIterator(newPath,
+ this.extensions);
+ if (this.extenstionsIterator.hasNext() == true)
+ {
+ return true;
+ }
+ }
+ this.localeIterator = null;
+ }
+
+ // Most outer loop: Loop through all combinations of styles and
+ // variations
+ while (this.styleIterator.hasNext())
+ {
+ String newPath = (String) this.styleIterator.next();
+
+ this.localeIterator = new LocaleResourceNameIterator(newPath, this.locale);
+ while (this.localeIterator.hasNext())
+ {
+ newPath = (String) this.localeIterator.next();
+ this.currentLocale = this.localeIterator.getLocale();
+ this.extenstionsIterator = new ExtensionResourceNameIterator(newPath,
+ this.extensions);
+ if (this.extenstionsIterator.hasNext() == true)
+ {
+ return true;
+ }
+ }
+ }
+
+ // No more combinations found. End of iteration.
+ return false;
+ }
+
+ /**
+ * @see java.util.Iterator#next()
+ */
+ public Object next()
+ {
+ if (extenstionsIterator != null)
+ {
+ return extenstionsIterator.next();
+ }
+ throw new WicketRuntimeException(
+ "Illegal call of next(). Iterator not properly initialized");
+ }
+
+ /**
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ // ignore
+ }
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceNameIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceStreamLocator.java (from r521998, incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/AbstractResourceStreamLocator.java)
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceStreamLocator.java?view=diff&rev=522181&p1=incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/AbstractResourceStreamLocator.java&r1=521998&p2=incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceStreamLocator.java&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/AbstractResourceStreamLocator.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/ResourceStreamLocator.java Sun Mar 25 02:07:30 2007
@@ -16,13 +16,19 @@
*/
package wicket.util.resource.locator;
+import java.net.URL;
import java.util.Locale;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import wicket.Application;
+import wicket.util.file.IResourceFinder;
import wicket.util.resource.IResourceStream;
-import wicket.util.string.Strings;
+import wicket.util.resource.UrlResourceStream;
/**
- * Base class for implementing IResourceStreamLocators.
+ * Locate Wicket resource.
* <p>
* Contains the logic to locate a resource based on a path, a style (see
* {@link wicket.Session}), a locale and an extension string. The full filename
@@ -48,153 +54,155 @@
* @author Juergen Donnerstag
* @author Jonathan Locke
*/
-public abstract class AbstractResourceStreamLocator implements IResourceStreamLocator
+public class ResourceStreamLocator implements IResourceStreamLocator
{
+ /** Logging */
+ private static final Log log = LogFactory.getLog(ResourceStreamLocator.class);
+
+ /** If null, the application registered finder will be used */
+ private IResourceFinder finder;
+
+ /**
+ * Constructor
+ */
+ public ResourceStreamLocator()
+ {
+ }
+
/**
* Constructor
+ *
+ * @param finder resource finder
*/
- protected AbstractResourceStreamLocator()
+ public ResourceStreamLocator(final IResourceFinder finder)
{
+ this.finder = finder;
}
/**
- * Locate a resource. See class comments for more details.
+ * Helper to get the Application registered resource stream locator
*
- * @param clazz
- * The class requesting the resource
- * @param path
- * The path of the resource without extension
- * @param style
- * A theme or style (see {@link wicket.Session})
- * @param locale
- * The Locale to apply
- * @param extension
- * the filname's extensions
+ * @return resource stream locator
+ */
+ public static IResourceStreamLocator get()
+ {
+ return Application.get().getResourceSettings().getResourceStreamLocator();
+ }
+
+ /**
*
- * @return The Resource, or null if not found.
+ * @see wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, java.lang.String, java.lang.String, java.util.Locale, java.lang.String)
*/
public IResourceStream locate(final Class clazz, String path, final String style,
- final Locale locale, String extension)
+ final Locale locale, final String extension)
{
- if (extension == null)
- {
- extension = "." + Strings.lastPathComponent(path, '.');
- path = Strings.beforeLastPathComponent(path, '.');
- }
- else
- {
- if (!extension.startsWith("."))
- {
- extension = "." + extension;
- }
- }
-
- // 1. Try style, locale and extension
- if (style != null && locale != null)
- {
- final IResourceStream resource = locate(clazz, path + '_' + style, locale, extension);
- if (resource != null)
+ // Try the various combinations of style, locale and extension to find
+ // the resource.
+ ResourceNameIterator iter = new ResourceNameIterator(path, style, locale, extension);
+ while (iter.hasNext())
+ {
+ String newPath = (String) iter.next();
+
+ IResourceStream stream = locate(clazz, newPath);
+ if (stream != null)
{
- return resource;
+ stream.setLocale(iter.getLocale());
+ return stream;
}
}
- // 2. Try locale and extension
- if (locale != null)
+ return null;
+ }
+
+ /**
+ *
+ * @see wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, java.lang.String)
+ */
+ public IResourceStream locate(final Class clazz, final String path)
+ {
+ // First search it on the resource on the classpath
+ IResourceStream stream = locateByClassLoader(clazz, path);
+ if (stream != null)
{
- final IResourceStream resource = locate(clazz, path, locale, extension);
- if (resource != null)
- {
- return resource;
- }
+ return stream;
}
- // 3. Try style and extension
- if (style != null)
+ // Than try the resource finder registered with the application
+ stream = locateByResourceFinder(clazz, path);
+ if (stream != null)
{
- final IResourceStream resource = locate(clazz, path + '_' + style + extension);
- if (resource != null)
- {
- return resource;
- }
+ return stream;
}
- // 4. Try just extension
- return locate(clazz, path + extension);
+ return null;
}
/**
- * Subclass implementation locates the resource at the given path. Different
- * subclasses may take different approaches to the search.
+ * Search the the resource my means of the various classloaders available
*
* @param clazz
- * The class requesting the resource
- *
* @param path
- * The complete path of the resource to locate. Separators must
- * be forward slashes.
- * @return The Resource, or null if not found.
+ * @return resource stream
*/
- protected abstract IResourceStream locate(final Class clazz, final String path);
+ protected IResourceStream locateByClassLoader(final Class clazz, final String path)
+ {
+ ClassLoader classLoader = null;
+ if (clazz != null)
+ {
+ classLoader = clazz.getClassLoader();
+ }
+
+ if (classLoader == null)
+ {
+ // use context classloader when no specific classloader is set
+ // (package resources for instance)
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ if (classLoader == null)
+ {
+ // use Wicket classloader when no specific classloader is set
+ classLoader = getClass().getClassLoader();
+ }
+
+ // Log attempt
+ if (log.isDebugEnabled())
+ {
+ log.debug("Attempting to locate resource '" + path + "' using classloader "
+ + classLoader);
+ }
+
+ // Try loading path using classloader
+ final URL url = classLoader.getResource(path);
+ if (url != null)
+ {
+ return new UrlResourceStream(url);
+ }
+ return null;
+ }
/**
- * Locate a file based on its path (potentially with a style), a locale and
- * an extension. See class comments for more details on how the locale is
- * used and the order applied to find the resource.
+ * Search the resource by means of the application registered resource
+ * finder
*
* @param clazz
- * The class requesting the resource
* @param path
- * Full path to resource, possibly including style, but not
- * locale or extension
- * @param locale
- * The locale to apply
- * @param extension
- * The resource's extension
- * @return The resource, or null if not found.
- */
- private IResourceStream locate(final Class clazz, final String path, final Locale locale,
- final String extension)
- {
- // 1. Apply Locale default toString() implementation. See Locale.
- {
- final IResourceStream resource = locate(clazz, path + '_' + locale.toString()
- + extension);
- if (resource != null)
- {
- resource.setLocale(locale);
- return resource;
- }
- }
-
- // Get language and country, either of which may be the empty string
- final String language = locale.getLanguage();
- final String country = locale.getCountry();
-
- // 2. If country and language are available
- if (!Strings.isEmpty(language) && !Strings.isEmpty(country))
- {
- final IResourceStream resource = locate(clazz, path + '_' + language + '_' + country
- + extension);
- if (resource != null)
- {
- resource.setLocale(new Locale(language, country));
- return resource;
- }
+ * @return resource stream
+ */
+ protected IResourceStream locateByResourceFinder(final Class clazz, final String path)
+ {
+ if (this.finder == null)
+ {
+ finder = Application.get().getResourceSettings().getResourceFinder();
}
- // 3. If language is available
- if (!Strings.isEmpty(language))
+ // Log attempt
+ if (log.isDebugEnabled())
{
- final IResourceStream resource = locate(clazz, path + '_' + language + extension);
- if (resource != null)
- {
- resource.setLocale(new Locale(language));
- return resource;
- }
+ log.debug("Attempting to locate resource '" + path + "' on path " + finder);
}
- // Not found
- return null;
+ // Try to find file resource on the path supplied
+ return finder.find(clazz, path);
}
}
Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/StyleAndVariationResourceNameIterator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/StyleAndVariationResourceNameIterator.java?view=auto&rev=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/StyleAndVariationResourceNameIterator.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/StyleAndVariationResourceNameIterator.java Sun Mar 25 02:07:30 2007
@@ -0,0 +1,117 @@
+/*
+ * 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.util.resource.locator;
+
+import java.util.Iterator;
+
+/**
+ * Contains the logic to build the various combinations of file path, style and
+ * locale required while searching for Wicket resources. The full filename will
+ * be built like: <path>_<style>_<locale>.<extension>.
+ * <p>
+ * Resource matches will be attempted in the following order:
+ * <ol>
+ * <li>1. <path>_<style>_<locale>.<extension></li>
+ * <li>2. <path>_<locale>.<extension></li>
+ * <li>3. <path>_<style>.<extension></li>
+ * <li>4. <path>.<extension></li>
+ * </ol>
+ * <p>
+ * Locales may contain a language, a country and a region or variant.
+ * Combinations of these components will be attempted in the following order:
+ * <ol>
+ * <li>locale.toString() see javadoc for Locale for more details</li>
+ * <li><language>_<country></li>
+ * <li><language></li>
+ * </ol>
+ *
+ * @author Juergen Donnerstag
+ * @author Jonathan Locke
+ */
+public class StyleAndVariationResourceNameIterator implements Iterator
+{
+ /** The base path */
+ private final String path;
+
+ /** The style (see Session) */
+ private final String style;
+
+ /** The variation (see Component) */
+ private final String variation;
+
+ /** Internal state */
+ private int state = 0;
+
+ /**
+ * Construct.
+ *
+ * @param path
+ * @param style
+ * @param variation
+ */
+ public StyleAndVariationResourceNameIterator(final String path, final String style, final String variation)
+ {
+ this.path = path;
+ this.style = style;
+ this.variation = variation;
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext()
+ {
+ return (this.state < 3);
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next()
+ {
+ if (state == 0)
+ {
+ state++;
+ if ((style != null) && (variation != null))
+ {
+ return path + '_' + style + '_' + variation;
+ }
+ }
+
+ if (state == 1)
+ {
+ state++;
+ if (style != null)
+ {
+ return path + '_' + style;
+ }
+ }
+
+ state = 3;
+ return path;
+ }
+
+ /**
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ }
+}
Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/util/resource/locator/StyleAndVariationResourceNameIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ApplicationSettingsTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ApplicationSettingsTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ApplicationSettingsTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ApplicationSettingsTest.java Sun Mar 25 02:07:30 2007
@@ -117,7 +117,7 @@
Settings settings = new Settings(dummy);
settings.addStringResourceLoader(new BundleStringResourceLoader(
"wicket.resource.DummyResources"));
- settings.addStringResourceLoader(new ComponentStringResourceLoader(dummy));
+ settings.addStringResourceLoader(new ComponentStringResourceLoader());
List loaders = settings.getStringResourceLoaders();
Assert.assertEquals("There should be 2 overridden loaders", 2, loaders.size());
Assert.assertTrue("First loader one should be the bundle one",
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/LocalizerTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/LocalizerTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/LocalizerTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/LocalizerTest.java Sun Mar 25 02:07:30 2007
@@ -67,7 +67,7 @@
public void testGetStringValidString()
{
Assert.assertEquals("Expected string should be returned", "This is a test", localizer
- .getString("test.string", null, null, null, null, "DEFAULT"));
+ .getString("test.string", null, null, "DEFAULT"));
}
/**
@@ -77,7 +77,7 @@
{
settings.setUseDefaultOnMissingResource(true);
Assert.assertEquals("Default string should be returned", "DEFAULT", localizer.getString(
- "unknown.string", null, null, null, null, "DEFAULT"));
+ "unknown.string", null, null, "DEFAULT"));
}
/**
@@ -90,7 +90,7 @@
Assert.assertEquals("Wrapped key should be returned on no default",
"[Warning: String resource for 'unknown.string' not found]", localizer.getString(
- "unknown.string", null, null, null, null, null));
+ "unknown.string", null, null, null));
}
/**
@@ -102,7 +102,7 @@
settings.setThrowExceptionOnMissingResource(false);
Assert.assertEquals("Wrapped key should be returned on not using default and no exception",
"[Warning: String resource for 'unknown.string' not found]", localizer.getString(
- "unknown.string", null, null, null, null, "DEFAULT"));
+ "unknown.string", null, null, "DEFAULT"));
}
/**
@@ -114,7 +114,7 @@
settings.setThrowExceptionOnMissingResource(true);
try
{
- localizer.getString("unknown.string", null, null, null, null, "DEFAULT");
+ localizer.getString("unknown.string", null, null, "DEFAULT");
Assert.fail("MissingResourceException expected");
}
catch (MissingResourceException e)
@@ -132,7 +132,7 @@
vm.put("user", "John Doe");
Model model = new Model(vm);
Assert.assertEquals("Property substitution should occur", "Welcome, John Doe", localizer
- .getString("test.substitute", null, model, null, null, null));
+ .getString("test.substitute", null, model, null));
}
/**
@@ -151,7 +151,7 @@
Session.get().setLocale(Locale.ENGLISH);
MyMockPage page = new MyMockPage();
Application.get().getResourceSettings().addStringResourceLoader(
- new ComponentStringResourceLoader(Application.get()));
+ new ComponentStringResourceLoader());
Localizer localizer = Application.get().getResourceSettings().getLocalizer();
String drop1 = localizer.getString("null", page.drop1);
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/MarkupParserTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/MarkupParserTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/MarkupParserTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/MarkupParserTest.java Sun Mar 25 02:07:30 2007
@@ -32,8 +32,8 @@
import wicket.markup.parser.filter.WicketTagIdentifier;
import wicket.util.resource.IResourceStream;
import wicket.util.resource.ResourceStreamNotFoundException;
-import wicket.util.resource.locator.ClassLoaderResourceStreamLocator;
import wicket.util.resource.locator.IResourceStreamLocator;
+import wicket.util.resource.locator.ResourceStreamLocator;
import wicket.util.string.StringValueConversionException;
@@ -202,7 +202,7 @@
final MarkupParser parser = new MarkupParser(new XmlPullParser());
parser.setWicketNamespace("wcn");
- IResourceStreamLocator locator = new ClassLoaderResourceStreamLocator();
+ IResourceStreamLocator locator = new ResourceStreamLocator();
MarkupResourceStream resource = newMarkupResourceStream(locator, this.getClass(), "1",
null, "html");
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/AutolinkPageExpectedResult_1.html
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/AutolinkPageExpectedResult_1.html?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/AutolinkPageExpectedResult_1.html (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/AutolinkPageExpectedResult_1.html Sun Mar 25 02:07:30 2007
@@ -25,9 +25,9 @@
<wicket:link autolink="true"/>
<a href="?wicket:bookmarkablePage=%3Awicket.markup.html.link.subdir.Page1">Home</a>
<link href="resources/wicket.markup.html.link.AutolinkPage_1/test_myStyle.css"/>
-<link href="resources/wicket.markup.html.link.AutolinkPage_1/test2_myStyle.css"/>
-<link href="resources/wicket.markup.html.link.AutolinkPage_1/test3_myStyle_de_DE.css"/>
-<link href="resources/wicket.markup.html.link.AutolinkPage_1/../../html/link/test2_myStyle.css"/>
+<link href="test2.css"/>
+<link href="test3.css"/>
+<link href="../../html/link/test2.css"/>
<a href="/root/test.html">Home</a>
<a href="?wicket:bookmarkablePage=%3Awicket.markup.html.link.Page1">Home</a>
<a href="http://www.google.com">Google</a>
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/properties/PropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/properties/PropertiesTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/properties/PropertiesTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/properties/PropertiesTest.java Sun Mar 25 02:07:30 2007
@@ -20,7 +20,6 @@
import wicket.WicketTestCase;
import wicket.protocol.http.WebRequestCycle;
-import wicket.resource.loader.WicketBundleStringResourceLoader;
import wicket.util.tester.WicketTester;
/**
@@ -54,11 +53,6 @@
*/
public void test_1()
{
- // Add the string resource loader with the special Bundle like
- // behavior
- tester.getApplication().getResourceSettings().addStringResourceLoader(
- new WicketBundleStringResourceLoader(tester.getApplication()));
-
tester.setupRequestAndResponse();
WebRequestCycle cycle = tester.createRequestCycle();
TestPage page = new TestPage();
@@ -77,11 +71,6 @@
*/
public void test_2()
{
- // Add the string resource loader with the special Bundle like
- // behavior
- tester.getApplication().getResourceSettings().addStringResourceLoader(
- new WicketBundleStringResourceLoader(tester.getApplication()));
-
tester.setupRequestAndResponse();
WebRequestCycle cycle = tester.createRequestCycle();
cycle.getSession().setLocale(Locale.GERMANY);
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ApplicationStringResourceLoaderTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ApplicationStringResourceLoaderTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ApplicationStringResourceLoaderTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ApplicationStringResourceLoaderTest.java Sun Mar 25 02:07:30 2007
@@ -46,7 +46,7 @@
*/
protected IStringResourceLoader createLoader()
{
- return new ClassStringResourceLoader(application, application.getClass());
+ return new ClassStringResourceLoader(application.getClass());
}
/**
@@ -56,7 +56,7 @@
{
WicketTester tester = new WicketTester();
WebApplication app = tester.getApplication();
- IStringResourceLoader loader = new ClassStringResourceLoader(app, app.getClass());
+ IStringResourceLoader loader = new ClassStringResourceLoader(app.getClass());
Assert.assertNull("Unknown resource should return null", loader.loadStringResource(component.getClass(),
"test.string", Locale.getDefault(), null));
tester.destroy();
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ComponentStringResourceLoaderTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ComponentStringResourceLoaderTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ComponentStringResourceLoaderTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/resource/ComponentStringResourceLoaderTest.java Sun Mar 25 02:07:30 2007
@@ -45,7 +45,7 @@
*/
protected IStringResourceLoader createLoader()
{
- return new ComponentStringResourceLoader(tester.getApplication());
+ return new ComponentStringResourceLoader();
}
/**
@@ -59,7 +59,7 @@
};
DummyPage page = new DummyPage();
page.add(c);
- IStringResourceLoader loader = new ComponentStringResourceLoader(tester.getApplication());
+ IStringResourceLoader loader = new ComponentStringResourceLoader();
Assert.assertNull("Missing resource should return null", loader.loadStringResource(c.getClass(), "test.string.bad",
Locale.getDefault(), null));
}
@@ -117,7 +117,7 @@
p.add(panel);
DummyComponent c = new DummyComponent("hello", application);
panel.add(c);
- IStringResourceLoader loader = new ComponentStringResourceLoader(tester.getApplication());
+ IStringResourceLoader loader = new ComponentStringResourceLoader();
Assert.assertEquals("Valid resourse string should be found", "Component string", loader
.loadStringResource(c.getClass(), "component.string", Locale.getDefault(), null));
}
@@ -128,7 +128,7 @@
public void testLoadDirectFromPage()
{
DummyPage p = new DummyPage();
- IStringResourceLoader loader = new ComponentStringResourceLoader(tester.getApplication());
+ IStringResourceLoader loader = new ComponentStringResourceLoader();
Assert.assertEquals("Valid resourse string should be found", "Another string", loader.loadStringResource(
p.getClass(), "another.test.string", Locale.getDefault(), null));
}
@@ -139,7 +139,7 @@
public void testSearchClassHierarchyFromPage()
{
DummySubClassPage p = new DummySubClassPage();
- IStringResourceLoader loader = new ComponentStringResourceLoader(tester.getApplication());
+ IStringResourceLoader loader = new ComponentStringResourceLoader();
Assert.assertEquals("Valid resource string should be found", "SubClass Test String",
loader.loadStringResource(p.getClass(), "subclass.test.string", Locale.getDefault(), null));
Assert.assertEquals("Valid resource string should be found", "Another string",
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/util/resource/ResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/util/resource/ResourceTest.java?view=diff&rev=522181&r1=522180&r2=522181
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/util/resource/ResourceTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/util/resource/ResourceTest.java Sun Mar 25 02:07:30 2007
@@ -25,9 +25,8 @@
import junit.framework.TestCase;
import wicket.util.file.Folder;
import wicket.util.file.Path;
-import wicket.util.resource.locator.ClassLoaderResourceStreamLocator;
-import wicket.util.resource.locator.CompoundResourceStreamLocator;
import wicket.util.resource.locator.IResourceStreamLocator;
+import wicket.util.resource.locator.ResourceStreamLocator;
import wicket.util.string.Strings;
@@ -63,7 +62,7 @@
*/
public void createAndTestResource(Path sourcePath, String style, Locale locale, String extension)
{
- IResourceStreamLocator locator = new CompoundResourceStreamLocator(sourcePath);
+ IResourceStreamLocator locator = new ResourceStreamLocator(sourcePath);
IResourceStream resource = locator.locate(this.getClass(), this.getClass().getName().replace('.', '/'),style, locale, "txt");
compareFilename(resource, extension);
}
@@ -99,7 +98,7 @@
createAndTestResource(sourcePath, null, locale_fr_FR, "_fr");
createAndTestResource(sourcePath, null, locale_fr_FR_WIN, "_fr");
createAndTestResource(sourcePath, null, locale_fr_WIN, "_fr");
- createAndTestResource(sourcePath, "style", locale_fr_WIN, "_fr");
+ createAndTestResource(sourcePath, "style", locale_fr_WIN, "_style");
}
/**
@@ -111,7 +110,7 @@
executeMultiple(new Path());
// Determine source path
- IResourceStreamLocator locator = new ClassLoaderResourceStreamLocator();
+ IResourceStreamLocator locator = new ResourceStreamLocator();
IResourceStream resource = locator.locate(getClass(),this.getClass().getName().replace('.', '/'), null, null, "txt");
String path = getPath(resource);
path = Strings.beforeLastPathComponent(path, '/') + "/sourcePath";