You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/09/15 23:09:08 UTC

svn commit: r575980 - in /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image: Image.java resource/LocalizedImageResource.java

Author: ivaynberg
Date: Sat Sep 15 14:09:08 2007
New Revision: 575980

URL: http://svn.apache.org/viewvc?rev=575980&view=rev
Log:
WICKET-974: Image#getResource always returns null even if there is a resource http://issues.apache.org/jira/browse/WICKET-974

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/Image.java
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/Image.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/Image.java?rev=575980&r1=575979&r2=575980&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/Image.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/Image.java Sat Sep 15 14:09:08 2007
@@ -31,8 +31,7 @@
 /**
  * An Image component displays a localizable image resource.
  * <p>
- * For details of how Images load, generate and manage images, see
- * {@link LocalizedImageResource}.
+ * For details of how Images load, generate and manage images, see {@link LocalizedImageResource}.
  * 
  * @author Jonathan Locke
  */
@@ -44,10 +43,9 @@
 	private final LocalizedImageResource localizedImageResource = new LocalizedImageResource(this);
 
 	/**
-	 * This constructor can be used if you have a img tag that has a src that
-	 * points to a PackageResource (which will be created and bind to the shared
-	 * resources) Or if you have a value attribute in your tag for which the
-	 * image factory can make an image.
+	 * This constructor can be used if you have a img tag that has a src that points to a
+	 * PackageResource (which will be created and bind to the shared resources) Or if you have a
+	 * value attribute in your tag for which the image factory can make an image.
 	 * 
 	 * @see org.apache.wicket.Component#Component(String)
 	 */
@@ -57,15 +55,14 @@
 	}
 
 	/**
-	 * Constructs an image from an image resourcereference. That resource
-	 * reference will bind its resource to the current SharedResources.
+	 * Constructs an image from an image resourcereference. That resource reference will bind its
+	 * resource to the current SharedResources.
 	 * 
-	 * If you are using non sticky session clustering and the resource reference
-	 * is pointing to a Resource that isn't guaranteed to be on every server,
-	 * for example a dynamic image or resources that aren't added with a
-	 * IInitializer at application startup. Then if only that resource is
-	 * requested from another server, without the rendering of the page, the
-	 * image won't be there and will result in a broken link.
+	 * If you are using non sticky session clustering and the resource reference is pointing to a
+	 * Resource that isn't guaranteed to be on every server, for example a dynamic image or
+	 * resources that aren't added with a IInitializer at application startup. Then if only that
+	 * resource is requested from another server, without the rendering of the page, the image won't
+	 * be there and will result in a broken link.
 	 * 
 	 * @param id
 	 *            See Component
@@ -78,15 +75,14 @@
 	}
 
 	/**
-	 * Constructs an image from an image resourcereference. That resource
-	 * reference will bind its resource to the current SharedResources.
+	 * Constructs an image from an image resourcereference. That resource reference will bind its
+	 * resource to the current SharedResources.
 	 * 
-	 * If you are using non sticky session clustering and the resource reference
-	 * is pointing to a Resource that isn't guaranteed to be on every server,
-	 * for example a dynamic image or resources that aren't added with a
-	 * IInitializer at application startup. Then if only that resource is
-	 * requested from another server, without the rendering of the page, the
-	 * image won't be there and will result in a broken link.
+	 * If you are using non sticky session clustering and the resource reference is pointing to a
+	 * Resource that isn't guaranteed to be on every server, for example a dynamic image or
+	 * resources that aren't added with a IInitializer at application startup. Then if only that
+	 * resource is requested from another server, without the rendering of the page, the image won't
+	 * be there and will result in a broken link.
 	 * 
 	 * @param id
 	 *            See Component
@@ -105,9 +101,9 @@
 	/**
 	 * Constructs an image directly from an image resource.
 	 * 
-	 * This one doesn't have the 'non sticky session clustering' problem that
-	 * the ResourceReference constructor has. But this will result in a non
-	 * 'stable' url and the url will have request parameters.
+	 * This one doesn't have the 'non sticky session clustering' problem that the ResourceReference
+	 * constructor has. But this will result in a non 'stable' url and the url will have request
+	 * parameters.
 	 * 
 	 * @param id
 	 *            See Component
@@ -196,7 +192,7 @@
 	 */
 	protected Resource getImageResource()
 	{
-		return null;
+		return localizedImageResource.getResource();
 	}
 
 	/**
@@ -204,7 +200,7 @@
 	 */
 	protected ResourceReference getImageResourceReference()
 	{
-		return null;
+		return localizedImageResource.getResourceReference();
 	}
 
 	/**
@@ -247,8 +243,7 @@
 	}
 
 	/**
-	 * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream,
-	 *      ComponentTag)
+	 * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
 	 */
 	protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
 	{

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java?rev=575980&r1=575979&r2=575980&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/image/resource/LocalizedImageResource.java Sat Sep 15 14:09:08 2007
@@ -41,34 +41,30 @@
 
 
 /**
- * THIS CLASS IS INTENDED FOR INTERNAL USE IN IMPLEMENTING LOCALE SENSITIVE
- * COMPONENTS THAT USE IMAGE RESOURCES AND SHOULD NOT BE USED DIRECTLY BY
- * END-USERS.
+ * THIS CLASS IS INTENDED FOR INTERNAL USE IN IMPLEMENTING LOCALE SENSITIVE COMPONENTS THAT USE
+ * IMAGE RESOURCES AND SHOULD NOT BE USED DIRECTLY BY END-USERS.
  * <p>
- * This class contains the logic for extracting static image resources
- * referenced by the SRC attribute of component tags and keeping these static
- * image resources in sync with the component locale.
+ * This class contains the logic for extracting static image resources referenced by the SRC
+ * attribute of component tags and keeping these static image resources in sync with the component
+ * locale.
  * <p>
- * If no image is specified by the SRC attribute of an IMG tag, then any VALUE
- * attribute is inspected. If there is a VALUE attribute, it must be of the form
- * "[factoryName]:[sharedImageName]?:[specification]". [factoryName] is the name
- * of a resource factory that has been added to Application (for example,
- * DefaultButtonImageResourceFactory is installed by default under the name
- * "buttonFactory"). The [sharedImageName] value is optional and gives a name
- * under which a given generated image is shared. For example, a cancel button
- * image generated by the VALUE attribute "buttonFactory:cancelButton:Cancel" is
- * shared under the name "cancelButton" and this specification will cause a
- * component to reference the same image resource no matter what page it appears
- * on, which is a very convenient and efficient way to create and share images.
- * The [specification] string which follows the second colon is passed directly
- * to the image factory and its format is dependent on the specific image
- * factory. For details on the default buttonFactory, see
+ * If no image is specified by the SRC attribute of an IMG tag, then any VALUE attribute is
+ * inspected. If there is a VALUE attribute, it must be of the form
+ * "[factoryName]:[sharedImageName]?:[specification]". [factoryName] is the name of a resource
+ * factory that has been added to Application (for example, DefaultButtonImageResourceFactory is
+ * installed by default under the name "buttonFactory"). The [sharedImageName] value is optional and
+ * gives a name under which a given generated image is shared. For example, a cancel button image
+ * generated by the VALUE attribute "buttonFactory:cancelButton:Cancel" is shared under the name
+ * "cancelButton" and this specification will cause a component to reference the same image resource
+ * no matter what page it appears on, which is a very convenient and efficient way to create and
+ * share images. The [specification] string which follows the second colon is passed directly to the
+ * image factory and its format is dependent on the specific image factory. For details on the
+ * default buttonFactory, see
  * {@link org.apache.wicket.markup.html.image.resource.DefaultButtonImageResourceFactory}.
  * <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.
+ * 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.
  * 
  * @author Jonathan Locke
  */
@@ -77,8 +73,8 @@
 	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;
 
@@ -168,8 +164,8 @@
 	public LocalizedImageResource(final Component component)
 	{
 		this.component = component;
-		this.locale = component.getLocale();
-		this.style = component.getStyle();
+		locale = component.getLocale();
+		style = component.getStyle();
 	}
 
 	/**
@@ -221,7 +217,7 @@
 	 */
 	public final boolean isStateless()
 	{
-		return this.resource == null;
+		return resource == null;
 	}
 
 	/**
@@ -241,11 +237,9 @@
 
 	/**
 	 * @param tag
-	 *            The tag to inspect for an optional src attribute that might
-	 *            reference an image.
+	 *            The tag to inspect for an optional src attribute that might reference an image.
 	 * @throws WicketRuntimeException
-	 *             Thrown if an image is required by the caller, but none can be
-	 *             found.
+	 *             Thrown if an image is required by the caller, but none can be found.
 	 */
 	public final void setSrcAttribute(final ComponentTag tag)
 	{
@@ -258,12 +252,12 @@
 						.getStyle())))
 		{
 			// Get new component locale and style
-			this.locale = component.getLocale();
-			this.style = component.getStyle();
+			locale = component.getLocale();
+			style = component.getStyle();
 
 			// Invalidate current resource so it will be reloaded/recomputed
-			this.resourceReference = null;
-			this.resource = null;
+			resourceReference = null;
+			resource = null;
 		}
 		else
 		{
@@ -316,7 +310,7 @@
 
 		// Get URL for resource
 		final CharSequence url;
-		if (this.resourceReference != null)
+		if (resourceReference != null)
 		{
 			// Create URL to shared resource
 			url = RequestCycle.get().urlFor(resourceReference, resourceParameters);
@@ -356,8 +350,8 @@
 	}
 
 	/**
-	 * Tries to load static image at the given path and throws an exception if
-	 * the image cannot be located.
+	 * Tries to load static image at the given path and throws an exception if the image cannot be
+	 * located.
 	 * 
 	 * @param path
 	 *            The path to the image
@@ -379,7 +373,7 @@
 			parent = parent.getParent();
 		}
 		final Class scope = parent.getClass();
-		this.resourceReference = new ResourceReference(scope, path)
+		resourceReference = new ResourceReference(scope, path)
 		{
 			private static final long serialVersionUID = 1L;
 
@@ -435,15 +429,14 @@
 				}
 
 				// Create resource reference
-				this.resourceReference = new ResourceReference(Application.class,
-						imageReferenceName);
+				resourceReference = new ResourceReference(Application.class, imageReferenceName);
 				resourceReference.setLocale(locale);
 				resourceReference.setStyle(style);
 			}
 			else
 			{
-				this.resource = getResourceFactory(application, factoryName).newResource(
-						specification, locale, style);
+				resource = getResourceFactory(application, factoryName).newResource(specification,
+						locale, style);
 			}
 		}
 		else
@@ -453,5 +446,25 @@
 							value +
 							"'.  Was expecting a value attribute of the form \"[resourceFactoryName]:[resourceReferenceName]?:[factorySpecification]\".");
 		}
+	}
+
+	/**
+	 * return the resource
+	 * 
+	 * @return resource or <code>null</code> if there is none
+	 */
+	public final Resource getResource()
+	{
+		return resource;
+	}
+
+	/**
+	 * return the resource
+	 * 
+	 * @return resource or <code>null</code> if there is none
+	 */
+	public final ResourceReference getResourceReference()
+	{
+		return resourceReference;
 	}
 }