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 2008/04/09 13:34:40 UTC

svn commit: r646277 - in /wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/markup/resolver/ main/java/org/apache/wicket/util/string/interpolator/ test/java/org/apache/wicket/markup/resolver/

Author: jdonnerstag
Date: Wed Apr  9 04:34:38 2008
New Revision: 646277

URL: http://svn.apache.org/viewvc?rev=646277&view=rev
Log:
implemented new feature wicket-1486: Allow child components inside of wicket:message

Added:
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_1.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2a.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_3.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_4.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.properties
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.properties
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.properties
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.html
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/WicketMessageResolverTest.java
Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/IComponentResolver.java
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/MapVariableInterpolator.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/IComponentResolver.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/IComponentResolver.java?rev=646277&r1=646276&r2=646277&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/IComponentResolver.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/IComponentResolver.java Wed Apr  9 04:34:38 2008
@@ -40,6 +40,6 @@
 	 *            The current component tag while parsing the markup
 	 * @return True if component-id was handled by the resolver, false otherwise.
 	 */
-	public boolean resolve(final MarkupContainer container, final MarkupStream markupStream,
-			final ComponentTag tag);
+	public boolean resolve(final MarkupContainer< ? > container, final MarkupStream markupStream,
+		final ComponentTag tag);
 }

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java?rev=646277&r1=646276&r2=646277&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java Wed Apr  9 04:34:38 2008
@@ -16,33 +16,91 @@
  */
 package org.apache.wicket.markup.resolver;
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.Response;
+import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
 import org.apache.wicket.markup.MarkupException;
 import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.RawMarkup;
 import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.html.WebComponent;
 import org.apache.wicket.markup.parser.XmlTag;
 import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
 import org.apache.wicket.model.Model;
+import org.apache.wicket.response.StringResponse;
+import org.apache.wicket.util.lang.PropertyResolver;
+import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * This is a tag resolver which handles &lt;wicket:message key="myKey"&gt;Default
  * Text&lt;/wicket:message&gt;. The resolver will replace the whole tag with the message found in
  * the properties file associated with the Page. If no message is found, the default body text will
  * remain.
+ * <p>
+ * You can also nest child components inside a wicket:message and then reference them from the
+ * properties file. For example in the html
+ * 
+ * <pre>
+ *     &lt;wicket:message key=&quot;myKey&quot;&gt;
+ *        This text will be replaced with text from the properties file.
+ *        &lt;span wicket:id=&quot;amount&quot;&gt;[amount]&lt;/span&gt;.
+ *        &lt;a wicket:id=&quot;link&quot;&gt;
+ *            &lt;wicket:message key=&quot;linkText&quot;/&gt;
+ *        &lt;/a&gt;
+ *     &lt;/wicket:message&gt;
+ * </pre>
+ * 
+ * Then in the properties file have a variable with a name that matches the wicket:id for each child
+ * component. The variables can be in any order, they do NOT have to match the order in the HTML
+ * file.
+ * 
+ * <pre>
+ *     myKey=Your balance is ${amount}. Click ${link} to view the details.
+ *     linkText=here
+ * </pre>
+ * 
+ * And in the java
+ * 
+ * <pre>
+ * add(new Label(&quot;amount&quot;, new Model(&quot;$5.00&quot;)));
+ * add(new BookmarkablePageLink(&quot;link&quot;, DetailsPage.class));
+ * </pre>
+ * 
+ * This will output
+ * 
+ * <pre>
+ * Your balance is $5.00. Click &lt;a href=&quot;#&quot;&gt;here&lt;/a&gt; to view the details.
+ * </pre>
+ * 
+ * If variables are not found via child component, the search will continue with the parents
+ * container model object and if still not found with the parent container itself.
+ * 
+ * It is possible to switch between logging a warning and throwing an exception if either the
+ * property key/value or any of the variables can not be found.
  * 
  * @author Juergen Donnerstag
+ * @author John Ray
  */
 public class WicketMessageResolver implements IComponentResolver
 {
+	private static final long serialVersionUID = 1L;
+
 	private static final Logger log = LoggerFactory.getLogger(WicketMessageResolver.class);
 
+	static
+	{
+		// register "wicket:message"
+		WicketTagIdentifier.registerWellKnownTagName("message");
+	}
+
 	/**
 	 * If the key can't be resolved and the default is null, an exception will be thrown. Instead,
 	 * we default to a unique string and check against this later. Don't just use an empty string
@@ -50,14 +108,8 @@
 	 */
 	private static final String DEFAULT_VALUE = "DEFAULT_WICKET_MESSAGE_RESOLVER_VALUE";
 
-	static
-	{
-		// register "wicket:message"
-		WicketTagIdentifier.registerWellKnownTagName("message");
-	}
-
-
-	private static final long serialVersionUID = 1L;
+	/** If true, than throw an exception if the property key was not found */
+	private static boolean throwExceptionIfPropertyNotFound = false;
 
 	/**
 	 * Try to resolve the tag, then create a component, add it to the container and render it.
@@ -73,7 +125,7 @@
 	 *            The current component tag while parsing the markup
 	 * @return true, if componentId was handle by the resolver. False, otherwise
 	 */
-	public boolean resolve(final MarkupContainer container, final MarkupStream markupStream,
+	public boolean resolve(final MarkupContainer< ? > container, final MarkupStream markupStream,
 		final ComponentTag tag)
 	{
 		if (tag instanceof WicketTag)
@@ -89,10 +141,11 @@
 				}
 
 				final String id = "_message_" + container.getPage().getAutoIndex();
-				MessageLabel label = new MessageLabel(id, messageKey);
+				MessageContainer label = new MessageContainer(id, messageKey);
 				label.setRenderBodyOnly(container.getApplication()
 					.getMarkupSettings()
 					.getStripWicketTags());
+
 				container.autoAdd(label, markupStream);
 
 				// Yes, we handled the tag
@@ -105,9 +158,35 @@
 	}
 
 	/**
-	 * A Label which expands open-close tags to open-body-close if required
+	 * If true, than throw an exception if a property key is not found. If false, just a warning is
+	 * issued in the logged.
+	 * 
+	 * @return throwExceptionIfPropertyNotFound
 	 */
-	public static class MessageLabel extends WebComponent
+	public static boolean isThrowExceptionIfPropertyNotFound()
+	{
+		return throwExceptionIfPropertyNotFound;
+	}
+
+	/**
+	 * If true, than throw an exception if a property key is not found. If false, just a warning is
+	 * issued in the logged.
+	 * 
+	 * @param throwExceptionIfPropertyNotFound
+	 *            throwExceptionIfPropertyNotFound
+	 */
+	public static void setThrowExceptionIfPropertyNotFound(boolean throwExceptionIfPropertyNotFound)
+	{
+		WicketMessageResolver.throwExceptionIfPropertyNotFound = throwExceptionIfPropertyNotFound;
+	}
+
+	/**
+	 * A Container which expands open-close tags to open-body-close if required. It gets a
+	 * properties value and replaces variable such as ${myVar} with the rendered output of its child
+	 * tags.
+	 * 
+	 */
+	private static class MessageContainer extends MarkupContainer<String>
 	{
 		private static final long serialVersionUID = 1L;
 
@@ -117,47 +196,220 @@
 		 * @param id
 		 * @param messageKey
 		 */
-		public MessageLabel(final String id, final String messageKey)
+		public MessageContainer(final String id, final String messageKey)
 		{
-			super(id, new Model(messageKey));
+			// The message key becomes the model
+			super(id, new Model<String>(messageKey));
+
 			setEscapeModelStrings(false);
 		}
 
-		protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
+		/**
+		 * 
+		 * @see org.apache.wicket.MarkupContainer#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
+		 *      org.apache.wicket.markup.ComponentTag)
+		 */
+		@Override
+		protected void onComponentTagBody(final MarkupStream markupStream,
+			final ComponentTag openTag)
 		{
+			// Get the value from the properties file
 			final String key = getModelObjectAsString();
 			final String value = getLocalizer().getString(key, getParent(), DEFAULT_VALUE);
-			if (value != null && !DEFAULT_VALUE.equals(value))
+
+			// if found, than render it after replacing the variables
+			if ((value != null) && !DEFAULT_VALUE.equals(value))
 			{
-				replaceComponentTagBody(markupStream, openTag, value.trim());
+				renderMessage(markupStream, openTag, key, value);
 			}
 			else
 			{
-				log.debug("No value found for wicket:message tag with key: {}", key);
+				if (isThrowExceptionIfPropertyNotFound() == true)
+				{
+					throw new WicketRuntimeException("Property '" + key +
+						"' not found in property files. Markup: " + markupStream.toString());
+				}
+
+				log.warn("No value found for wicket:message tag with key: {}", key);
+				renderComponentTagBody(markupStream, openTag);
+			}
+		}
+
+		/**
+		 * A property key has been found. Now render the property value.
+		 * 
+		 * @param markupStream
+		 * @param openTag
+		 * @param key
+		 * @param value
+		 */
+		private void renderMessage(final MarkupStream markupStream, final ComponentTag openTag,
+			final String key, final String value)
+		{
+			// Find all direct child tags, render them separately into a String, and remember them
+			// in a hash map associated with the wicket id
+			final Map<String, CharSequence> childTags = findAndRenderChildWicketTags(markupStream,
+				openTag);
+
+			final Map<String, Object> variablesReplaced = new HashMap<String, Object>();
+
+			// Replace all ${var} within the property value with real values
+			String text = new MapVariableInterpolator(value, childTags)
+			{
+				/**
+				 * @see org.apache.wicket.util.string.interpolator.MapVariableInterpolator#getValue(java.lang.String)
+				 */
+				@Override
+				protected String getValue(final String variableName)
+				{
+					// First check if a child tag with the same id exists.
+					String value = super.getValue(variableName);
+
+					// Remember that we successfully used the tag
+					if (value != null)
+					{
+						variablesReplaced.put(variableName, null);
+					}
+
+					// If not, try to resolve the name with containers model data
+					if (value == null)
+					{
+						value = Strings.toString(PropertyResolver.getValue(variableName,
+							getParent().getModelObject()));
+					}
 
-				// get original tag from markup because we modified this one to always be open
-				markupStream.setCurrentIndex(markupStream.getCurrentIndex() - 1);
-				ComponentTag tag = markupStream.getTag();
-				markupStream.next();
-
-				// if the tag is of form <wicket:message>{foo}</wicket:message> use {foo} as
-				// default value for the message, otherwise do nothing
-				if (!tag.isOpenClose())
+					// If still not found, try the component itself
+					if (value == null)
+					{
+						value = Strings.toString(PropertyResolver.getValue(variableName,
+							getParent()));
+					}
+
+					// If still not found, don't know what to do
+					if (value == null)
+					{
+						String msg = "The localized text for <wicket:message key=\"" + key +
+							"\"> has a variable ${" + variableName +
+							"}. However the wicket:message element does not have a child " +
+							"element with a wicket:id=\"" + variableName + "\".";
+
+						if (isThrowExceptionIfPropertyNotFound() == true)
+						{
+							markupStream.throwMarkupException(msg);
+						}
+						else
+						{
+							log.warn(msg);
+							value = "### VARIABLE NOT FOUND: " + variableName + " ###";
+						}
+					}
+
+					return value;
+				}
+			}.toString();
+
+			getResponse().write(text);
+
+			// Make sure all of the children were rendered
+			Iterator<String> iter = childTags.keySet().iterator();
+			while (iter.hasNext())
+			{
+				String id = iter.next();
+				if (variablesReplaced.containsKey(id) == false)
 				{
-					MarkupElement body = markupStream.get();
-					if (body instanceof RawMarkup)
+					String msg = "The <wicket:message key=\"" + key +
+						"\"> has a child element with wicket:id=\"" + id +
+						"\". You must add the variable ${" + id +
+						"} to the localized text for the wicket:message.";
+
+					if (isThrowExceptionIfPropertyNotFound() == true)
 					{
-						replaceComponentTagBody(markupStream, openTag, body.toCharSequence());
+						markupStream.throwMarkupException(msg);
+					}
+					else
+					{
+						log.warn(msg);
 					}
 				}
 			}
 		}
 
 		/**
+		 * If the tag is of form <wicket:message>{foo}</wicket:message> then scan for any child
+		 * wicket component and save their tag index
 		 * 
+		 * @param markupStream
+		 * @param openTag
+		 * @return
+		 */
+		private Map<String, CharSequence> findAndRenderChildWicketTags(
+			final MarkupStream markupStream, final ComponentTag openTag)
+		{
+			Map<String, CharSequence> childTags = new HashMap<String, CharSequence>();
+
+			// get original tag from markup because we modified openTag to always be open
+			markupStream.setCurrentIndex(markupStream.getCurrentIndex() - 1);
+			ComponentTag tag = markupStream.getTag();
+			markupStream.next();
+
+			// if the tag is of form <wicket:message>{foo}</wicket:message> then scan for any
+			// child component and save their tag index
+			if (!tag.isOpenClose())
+			{
+				while (markupStream.hasMore() && !markupStream.get().closes(openTag))
+				{
+					MarkupElement element = markupStream.get();
+					// If it a tag like <wicket..> or <span wicket:id="..." >
+					if ((element instanceof ComponentTag) && !markupStream.atCloseTag())
+					{
+						String id = ((ComponentTag)element).getId();
+
+						// Temporarily replace the web response with a String response
+						final Response webResponse = getResponse();
+
+						try
+						{
+							final StringResponse response = new StringResponse();
+							getRequestCycle().setResponse(response);
+
+							Component< ? > component = getParent().get(id);
+							if (component != null)
+							{
+								component.render(markupStream);
+							}
+							childTags.put(id, response.getBuffer());
+						}
+						finally
+						{
+							// Restore the original response
+							getRequestCycle().setResponse(webResponse);
+						}
+					}
+					else
+					{
+						markupStream.next();
+					}
+				}
+			}
+
+			return childTags;
+		}
+
+		/**
+		 * 
+		 * @see org.apache.wicket.MarkupContainer#isTransparentResolver()
+		 */
+		@Override
+		public boolean isTransparentResolver()
+		{
+			return true;
+		}
+
+		/**
 		 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
 		 */
-		protected void onComponentTag(ComponentTag tag)
+		@Override
+		protected void onComponentTag(final ComponentTag tag)
 		{
 			// Convert <wicket:message /> into <wicket:message>...</wicket:message>
 			if (tag.isOpenClose())

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/MapVariableInterpolator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/MapVariableInterpolator.java?rev=646277&r1=646276&r2=646277&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/MapVariableInterpolator.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/MapVariableInterpolator.java Wed Apr  9 04:34:38 2008
@@ -60,7 +60,7 @@
 	 *            multiple interpolators can be chained
 	 */
 	public MapVariableInterpolator(String string, final Map variables,
-			boolean exceptionOnNullVarValue)
+		boolean exceptionOnNullVarValue)
 	{
 		super(string, exceptionOnNullVarValue);
 		this.variables = variables;
@@ -84,7 +84,7 @@
 	 *            the variable name
 	 * @return the value
 	 */
-	protected final String getValue(final String variableName)
+	protected String getValue(final String variableName)
 	{
 		return Strings.toString(variables.get(variableName));
 	}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_1.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_1.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_1.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,14 @@
+<html xmlns:wicket>
+<body>
+  <wicket:message key="myKeyNotExsts">Default Text</wicket:message>
+  <wicket:message key="myKey">myValue</wicket:message>
+  <wicket:message key="myKeyNotExsts"></wicket:message>
+  <wicket:message key="myKey">myValue</wicket:message>
+  <span wicket:id="message">here it goes</span>
+  <span attr-name="my i18n key" wicket:message="attr-name:i18n-key">test 2</span>
+  <span wicket:id="message2" attr-name="my i18n key" wicket:message="attr-name:i18n-key">here it goes</span>
+  
+  <input type="image" src="../test.gif">test 2</input>
+  <input type="image" src="../test.gif" attr-name="my i18n key" wicket:message="attr-name:i18n-key">test 2</input>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,7 @@
+<html xmlns:wicket>
+<body>
+<wicket:message key="myKey">Your balance is $5.00. Click <a href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.markup.resolver.SimplePage_1" wicket:id="link">
+    <wicket:message key="linkText">here</wicket:message>
+  </a> to view the details.</wicket:message>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2a.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2a.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2a.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_2a.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,7 @@
+<html>
+<body>
+Your balance is $5.00. Click <a href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.markup.resolver.SimplePage_1">
+    here
+  </a> to view the details.
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_3.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_3.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_3.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_3.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,6 @@
+<html xmlns:wicket>
+<body>
+<wicket:message key="myKey1">sucessfully called SimplePage_3.getMyValue().</wicket:message>
+<wicket:message key="myKey2">sucessfully called 123456.</wicket:message>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_4.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_4.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_4.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePageExpectedResult_4.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1 @@
+not relevant
\ No newline at end of file

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,14 @@
+<html xmlns:wicket>
+<body>
+  <wicket:message key="myKeyNotExsts">Default Text</wicket:message>
+  <wicket:message key="myKey">Default Text</wicket:message>
+  <wicket:message key="myKeyNotExsts"/>
+  <wicket:message key="myKey"/>
+  <span wicket:id="message">test</span>
+  <span wicket:message="attr-name:i18n-key">test 2</span>
+  <span wicket:id="message2" wicket:message="attr-name:i18n-key">test 2</span>
+  
+  <input type="image" src="test.gif">test 2</input>
+  <input type="image" src="test.gif" wicket:message="attr-name:i18n-key">test 2</input>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.java?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.java Wed Apr  9 04:34:38 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.markup.resolver;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ * 
+ * @author Chris Turner
+ */
+public class SimplePage_1 extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 */
+	public SimplePage_1()
+	{
+		add(new Label("message", "here it goes"));
+		add(new Label("message2", "here it goes"));
+	}
+}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.properties
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.properties?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.properties (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_1.properties Wed Apr  9 04:34:38 2008
@@ -0,0 +1,3 @@
+
+myKey = myValue
+i18n-key = my i18n key
\ No newline at end of file

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,11 @@
+<html xmlns:wicket>
+<body>
+<wicket:message key="myKey">
+  This text will be replaced with text from the properties file.
+  <span wicket:id="amount">[amount]</span>
+  <a wicket:id="link">
+    <wicket:message key="linkText"/>
+  </a>
+</wicket:message>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.java?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.java Wed Apr  9 04:34:38 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.markup.resolver;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.model.Model;
+
+
+/**
+ * Mock page for testing.
+ * 
+ * @author Chris Turner
+ */
+public class SimplePage_2 extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 */
+	public SimplePage_2()
+	{
+		add(new Label("amount", new Model("$5.00")).setRenderBodyOnly(true));
+		add(new BookmarkablePageLink("link", SimplePage_1.class));
+	}
+}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.properties
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.properties?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.properties (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_2.properties Wed Apr  9 04:34:38 2008
@@ -0,0 +1,3 @@
+
+myKey=Your balance is ${amount}. Click ${link} to view the details.
+linkText=here

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,6 @@
+<html xmlns:wicket>
+<body>
+<wicket:message key="myKey1"/>
+<wicket:message key="myKey2"/>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.java?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.java Wed Apr  9 04:34:38 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.markup.resolver;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.value.ValueMap;
+
+
+/**
+ * Mock page for testing.
+ * 
+ * @author Chris Turner
+ */
+public class SimplePage_3 extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 */
+	public SimplePage_3()
+	{
+		ValueMap modelData = new ValueMap();
+		modelData.put("testData", "123456");
+		setModel(new Model(modelData));
+	}
+
+	/**
+	 * 
+	 * @return
+	 */
+	public String getMyValue()
+	{
+		return "SimplePage_3.getMyValue()";
+	}
+}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.properties
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.properties?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.properties (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_3.properties Wed Apr  9 04:34:38 2008
@@ -0,0 +1,3 @@
+
+myKey1 = sucessfully called ${myValue}.
+myKey2 = sucessfully called ${testData}.

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.html?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.html (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.html Wed Apr  9 04:34:38 2008
@@ -0,0 +1,5 @@
+<html xmlns:wicket>
+<body>
+<wicket:message key="myKey"/>
+</body>
+</html>

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.java?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/SimplePage_4.java Wed Apr  9 04:34:38 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.markup.resolver;
+
+import org.apache.wicket.markup.html.WebPage;
+
+
+/**
+ * Mock page for testing.
+ * 
+ * @author Chris Turner
+ */
+public class SimplePage_4 extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 */
+	public SimplePage_4()
+	{
+	}
+}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/WicketMessageResolverTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/WicketMessageResolverTest.java?rev=646277&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/WicketMessageResolverTest.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/resolver/WicketMessageResolverTest.java Wed Apr  9 04:34:38 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.markup.resolver;
+
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.WicketTestCase;
+
+/**
+ * 
+ */
+public class WicketMessageResolverTest extends WicketTestCase
+{
+	/**
+	 * Construct.
+	 * 
+	 * @param name
+	 */
+	public WicketMessageResolverTest(String name)
+	{
+		super(name);
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void test_1() throws Exception
+	{
+		executeTest(SimplePage_1.class, "SimplePageExpectedResult_1.html");
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void test_2() throws Exception
+	{
+		executeTest(SimplePage_2.class, "SimplePageExpectedResult_2.html");
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void test_2a() throws Exception
+	{
+		tester.getApplication().getMarkupSettings().setStripWicketTags(true);
+		executeTest(SimplePage_2.class, "SimplePageExpectedResult_2a.html");
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void test_3() throws Exception
+	{
+		executeTest(SimplePage_3.class, "SimplePageExpectedResult_3.html");
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void test_4() throws Exception
+	{
+		try
+		{
+			WicketMessageResolver.setThrowExceptionIfPropertyNotFound(true);
+			executeTest(SimplePage_4.class, "SimplePageExpectedResult_4.html");
+		}
+		catch (WicketRuntimeException ex)
+		{
+			String text = "Property 'myKey' not found";
+			assertEquals(text, ex.getMessage().substring(0, text.length()));
+			return;
+		}
+		assertTrue("Expected a WicketRuntimeException to happen", false);
+	}
+}