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/05/12 23:01:10 UTC

svn commit: r537516 - in /incubator/wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/markup/html/image/resource/ main/java/org/apache/wicket/util/resource/locator/ test/java/org/apache/wicket/markup/html/link/

Author: jdonnerstag
Date: Sat May 12 14:01:09 2007
New Revision: 537516

URL: http://svn.apache.org/viewvc?view=rev&rev=537516
Log:
partly solving wicket-513: Example "pub" doesn't work any more. The images are no longer localized

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceNameIterator.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_1.html
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_4.html
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPage_4.html

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java?view=diff&rev=537516&r1=537515&r2=537516
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java Sat May 12 14:01:09 2007
@@ -67,18 +67,21 @@
  * <p>
  * Finally, if there is no SRC attribute and no VALUE attribute, the Image
  * component's model is inspected. If the model contains a resource or resource
- * reference, this image is used, otherwise the model is converted to a 
- * String and that value is used as a path to load the image.
+ * reference, this image is used, otherwise the model is converted to a String
+ * and that value is used as a path to load the image.
  * 
  * @author Jonathan Locke
  */
 public final class LocalizedImageResource implements IClusterable, IResourceListener
 {
 	private static final long serialVersionUID = 1L;
-	
-	/** What kind of resource it is. TRUE==Resource is set, FALSE==ResourceReference is set, null none */
+
+	/**
+	 * What kind of resource it is. TRUE==Resource is set,
+	 * FALSE==ResourceReference is set, null none
+	 */
 	private Boolean resourceKind;
-	
+
 	/** The component that is referencing this image resource */
 	private Component component;
 
@@ -88,8 +91,8 @@
 	/** The resource reference */
 	private ResourceReference resourceReference;
 
-  /** The resource parameters */
-  private ValueMap resourceParameters;
+	/** The resource parameters */
+	private ValueMap resourceParameters;
 
 	/** The locale of the image resource */
 	private transient Locale locale;
@@ -212,7 +215,7 @@
 	{
 		setResourceReference(resourceReference, null);
 	}
-	
+
 	/**
 	 * @return If it is stateless (if resource is null)
 	 */
@@ -220,18 +223,19 @@
 	{
 		return this.resource == null;
 	}
-	
+
 	/**
 	 * @param resourceReference
 	 *            The resource to set.
-	 * @param resourceParameters 
-	 * 			  The resource parameters for the shared resource
+	 * @param resourceParameters
+	 *            The resource parameters for the shared resource
 	 */
-	public final void setResourceReference(final ResourceReference resourceReference,final ValueMap resourceParameters)
+	public final void setResourceReference(final ResourceReference resourceReference,
+			final ValueMap resourceParameters)
 	{
 		resourceKind = Boolean.FALSE;
 		this.resourceReference = resourceReference;
-	    this.resourceParameters = resourceParameters;
+		this.resourceParameters = resourceParameters;
 		bind();
 	}
 
@@ -247,9 +251,11 @@
 	{
 		// If locale has changed from the initial locale used to attach image
 		// resource, then we need to reload the resource in the new locale
-		if ( resourceKind == null && 
-				(!Objects.equal(locale, component.getLocale())
-				|| !Objects.equal(style, component.getStyle())))
+		Locale l = component.getLocale();
+		String s = component.getStyle();
+		if (resourceKind == null &&
+				(!Objects.equal(locale, component.getLocale()) || !Objects.equal(style, component
+						.getStyle())))
 		{
 			// Get new component locale and style
 			this.locale = component.getLocale();
@@ -261,19 +267,24 @@
 		}
 		else
 		{
-			// TODO post 1.2: should we have support for locale changes when the 
+			// TODO post 1.2: should we have support for locale changes when the
 			// resource reference (or resource??) is set manually..
-			// We should get a new resource reference for the current locale then
-			// that points to the same resource but with another locale if it exists.
-			// something like SharedResource.getResourceReferenceForLocale(resourceReference);
+			// We should get a new resource reference for the current locale
+			// then that points to the same resource but with another locale if
+			// it exists. Something like
+			// SharedResource.getResourceReferenceForLocale(resourceReference);
 		}
-		
-		// check if the model contains a resource, if so, load the resource from the model.
+
+		// check if the model contains a resource, if so, load the resource from
+		// the model.
 		Object modelObject = component.getModelObject();
-		if ( modelObject instanceof ResourceReference ) {
-			resourceReference = (ResourceReference) modelObject;
-		} else if ( modelObject instanceof Resource ) {
-			resource = (Resource) modelObject;
+		if (modelObject instanceof ResourceReference)
+		{
+			resourceReference = (ResourceReference)modelObject;
+		}
+		else if (modelObject instanceof Resource)
+		{
+			resource = (Resource)modelObject;
 		}
 
 		// Need to load image resource for this component?
@@ -317,7 +328,7 @@
 		}
 
 		// Set the SRC attribute to point to the component or shared resource
-		tag.put("src", RequestCycle.get().getOriginalResponse().encodeURL(url));	
+		tag.put("src", RequestCycle.get().getOriginalResponse().encodeURL(url));
 	}
 
 	/**
@@ -332,13 +343,14 @@
 	private IResourceFactory getResourceFactory(final Application application,
 			final String factoryName)
 	{
-		final IResourceFactory factory = application.getResourceSettings().getResourceFactory(factoryName);
+		final IResourceFactory factory = application.getResourceSettings().getResourceFactory(
+				factoryName);
 
 		// Found factory?
 		if (factory == null)
 		{
-			throw new WicketRuntimeException("Could not find image resource factory named "
-					+ factoryName);
+			throw new WicketRuntimeException("Could not find image resource factory named " +
+					factoryName);
 		}
 		return factory;
 	}
@@ -357,10 +369,10 @@
 		if ((path.indexOf("..") != -1) || (path.indexOf("./") != -1) || (path.indexOf("/.") != -1))
 		{
 			throw new WicketRuntimeException(
-					"The 'src' attribute must not contain any of the following strings: '..', './', '/.': path=" 
-					+ path);
+					"The 'src' attribute must not contain any of the following strings: '..', './', '/.': path=" +
+							path);
 		}
-		
+
 		MarkupContainer parent = component.findParentWithAssociatedMarkup();
 		if (parent instanceof Border)
 		{
@@ -370,13 +382,14 @@
 		this.resourceReference = new ResourceReference(scope, path)
 		{
 			private static final long serialVersionUID = 1L;
-			
+
 			/**
 			 * @see org.apache.wicket.ResourceReference#newResource()
 			 */
 			protected Resource newResource()
 			{
-				PackageResource pr = PackageResource.get(getScope(), getName(), LocalizedImageResource.this.locale, style);
+				PackageResource pr = PackageResource.get(getScope(), getName(),
+						LocalizedImageResource.this.locale, style);
 				locale = pr.getLocale();
 				return pr;
 			}
@@ -401,22 +414,24 @@
 		if (valueParser.matches())
 		{
 			final String imageReferenceName = valueParser.getImageReferenceName();
-			final String specification = Strings.replaceHtmlEscapeNumber(valueParser.getSpecification());
+			final String specification = Strings.replaceHtmlEscapeNumber(valueParser
+					.getSpecification());
 			final String factoryName = valueParser.getFactoryName();
 			final Application application = component.getApplication();
-			
+
 			// Do we have a reference?
 			if (!Strings.isEmpty(imageReferenceName))
 			{
 				// Is resource already available via the application?
-				if (application.getSharedResources().get(Application.class, imageReferenceName, locale, style, true) == null)
+				if (application.getSharedResources().get(Application.class, imageReferenceName,
+						locale, style, true) == null)
 				{
 					// Resource not available yet, so create it with factory and
 					// share via Application
 					final Resource imageResource = getResourceFactory(application, factoryName)
 							.newResource(specification, locale, style);
-					application.getSharedResources().add(Application.class, imageReferenceName, locale, style,
-							imageResource);
+					application.getSharedResources().add(Application.class, imageReferenceName,
+							locale, style, imageResource);
 				}
 
 				// Create resource reference
@@ -427,16 +442,16 @@
 			}
 			else
 			{
-				this.resource = getResourceFactory(application, factoryName)
-						.newResource(specification, locale, style);
+				this.resource = getResourceFactory(application, factoryName).newResource(
+						specification, locale, style);
 			}
 		}
 		else
 		{
 			throw new WicketRuntimeException(
-					"Could not generate image for value attribute '"
-							+ value
-							+ "'.  Was expecting a value attribute of the form \"[resourceFactoryName]:[resourceReferenceName]?:[factorySpecification]\".");
+					"Could not generate image for value attribute '" +
+							value +
+							"'.  Was expecting a value attribute of the form \"[resourceFactoryName]:[resourceReferenceName]?:[factorySpecification]\".");
 		}
 	}
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceNameIterator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceNameIterator.java?view=diff&rev=537516&r1=537515&r2=537516
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceNameIterator.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceNameIterator.java Sat May 12 14:01:09 2007
@@ -20,6 +20,7 @@
 import java.util.Locale;
 
 import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.util.string.Strings;
 
 
 /**
@@ -80,7 +81,15 @@
 			final String extensions)
 	{
 		this.locale = locale;
-		this.extensions = extensions;
+		if (extensions == null)
+		{
+			this.extensions = Strings.afterLast(path, '.');
+			path = Strings.beforeLast(path, '.');
+		}
+		else
+		{
+			this.extensions = extensions;
+		}
 
 		this.styleIterator = new StyleAndVariationResourceNameIterator(path, style, null);
 	}

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_1.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_1.html?view=diff&rev=537516&r1=537515&r2=537516
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_1.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_1.html Sat May 12 14:01:09 2007
@@ -25,9 +25,9 @@
 <wicket:link autolink="true">
 <a href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.markup.html.link.subdir.Page1">Home</a>
 <link href="resources/org.apache.wicket.markup.html.link.AutolinkPage_1/test_myStyle.css"/>
-<link href="test2.css"/>
-<link href="test3.css"/>
-<link href="../../html/link/test2.css"/>
+<link href="resources/org.apache.wicket.markup.html.link.AutolinkPage_1/test2_myStyle.css"/>
+<link href="resources/org.apache.wicket.markup.html.link.AutolinkPage_1/test3_myStyle_de_DE.css"/>
+<link href="resources/org.apache.wicket.markup.html.link.AutolinkPage_1/../../html/link/test2_myStyle.css"/>
 <a href="/root/test.html">Home</a>
 <a href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.markup.html.link.Page1">Home</a>
   <a href="http://www.google.com">Google</a>

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_4.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_4.html?view=diff&rev=537516&r1=537515&r2=537516
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_4.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPageExpectedResult_4.html Sat May 12 14:01:09 2007
@@ -4,9 +4,8 @@
   <!-- File/page does not exist => Do not change href at all -->
   <a href="PageDoesNotExist.html">Home</a>
   <!-- Reference an internal target => Do not change href at all -->
-  <a href="#link1">Link 1</a>
-  <!-- Not sure what it should do, but it is obviously valid => Do not change href at all -->
-  <a href="">Link 1</a>
+  <a href="resources/org.apache.wicket.markup.html.link.AutolinkPage_4/#link1">Link 1</a>
+  <a href="resources/org.apache.wicket.markup.html.link.AutolinkPage_4/">Link 1</a>
   <!-- Supported since 1.2 -->
   <a href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.markup.html.link.Page1#link1">Link 1</a>
 </wicket:link>

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPage_4.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPage_4.html?view=diff&rev=537516&r1=537515&r2=537516
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPage_4.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/link/AutolinkPage_4.html Sat May 12 14:01:09 2007
@@ -5,7 +5,6 @@
   <a href="PageDoesNotExist.html">Home</a>
   <!-- Reference an internal target => Do not change href at all -->
   <a href="#link1">Link 1</a>
-  <!-- Not sure what it should do, but it is obviously valid => Do not change href at all -->
   <a href="">Link 1</a>
   <!-- Supported since 1.2 -->
   <a href="Page1.html#link1">Link 1</a>