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/04/01 02:39:11 UTC

svn commit: r524502 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket: Application.java Component.java markup/ComponentTag.java markup/parser/filter/WicketMessageTagHandler.java

Author: ivaynberg
Date: Sat Mar 31 17:39:10 2007
New Revision: 524502

URL: http://svn.apache.org/viewvc?view=rev&rev=524502
Log:
WICKET-440 fixes for wicket:message attribute

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketMessageTagHandler.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java?view=diff&rev=524502&r1=524501&r2=524502
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Application.java Sat Mar 31 17:39:10 2007
@@ -34,6 +34,7 @@
 import wicket.application.IComponentInstantiationListener;
 import wicket.markup.MarkupCache;
 import wicket.markup.html.image.resource.DefaultButtonImageResourceFactory;
+import wicket.markup.parser.filter.WicketMessageTagHandler;
 import wicket.markup.resolver.AutoComponentResolver;
 import wicket.markup.resolver.EnclosureResolver;
 import wicket.markup.resolver.FragmentResolver;
@@ -876,10 +877,11 @@
 		pageSettings.addComponentResolver(new HtmlHeaderResolver());
 		pageSettings.addComponentResolver(new WicketLinkResolver());
 		pageSettings.addComponentResolver(new WicketMessageResolver());
+		pageSettings.addComponentResolver(new WicketMessageTagHandler());
 		pageSettings.addComponentResolver(new FragmentResolver());
 		pageSettings.addComponentResolver(new EnclosureResolver());
 		pageSettings.addComponentResolver(new WicketContainerResolver());
-		
+
 		// Install button image resource factory
 		getResourceSettings().addResourceFactory("buttonFactory",
 				new DefaultButtonImageResourceFactory());

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java?view=diff&rev=524502&r1=524501&r2=524502
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java Sat Mar 31 17:39:10 2007
@@ -2899,6 +2899,17 @@
 				}
 			}
 
+			// apply behaviors that are attached to the component tag.
+			if (tag.hasBehaviors())
+			{
+				Iterator behaviors = tag.getBehaviors();
+				while (behaviors.hasNext())
+				{
+					final IBehavior behavior = (IBehavior)behaviors.next();
+					behavior.onComponentTag(this, tag);
+				}
+			}
+
 			// Write the tag
 			tag.writeOutput(getResponse(), stripWicketTags, this.findMarkupStream()
 					.getWicketNamespace());

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java?view=diff&rev=524502&r1=524501&r2=524502
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/ComponentTag.java Sat Mar 31 17:39:10 2007
@@ -16,6 +16,7 @@
  */
 package wicket.markup;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -90,6 +91,12 @@
 
 
 	/** added behaviors */
+	// FIXME these behaviors here are merely for wicket:message attributes on
+	// tags that are also wicket components. since this addition behavors have
+	// gained a significantly more sophisticated lifecycle and so managing
+	// behaviors attached to markup tags like this is much harder. this should
+	// be refactored into some interface that only has oncomponenttag method
+	// because a full behavior is not supported nor desired imho.
 	private Collection behaviors;
 
 	/**
@@ -390,6 +397,11 @@
 			tag.setMarkupClass(this.markupClass);
 			tag.setHasNoCloseTag(this.hasNoCloseTag);
 			tag.setPath(this.path);
+			if (behaviors != null)
+			{
+				tag.behaviors = new ArrayList(behaviors.size());
+				tag.behaviors.addAll(behaviors);
+			}
 			return tag;
 		}
 	}

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketMessageTagHandler.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketMessageTagHandler.java?view=diff&rev=524502&r1=524501&r2=524502
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketMessageTagHandler.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/parser/filter/WicketMessageTagHandler.java Sat Mar 31 17:39:10 2007
@@ -19,27 +19,41 @@
 import java.text.ParseException;
 
 import wicket.Component;
+import wicket.MarkupContainer;
 import wicket.WicketRuntimeException;
 import wicket.behavior.AbstractBehavior;
 import wicket.behavior.IBehavior;
 import wicket.markup.ComponentTag;
 import wicket.markup.MarkupElement;
+import wicket.markup.MarkupStream;
+import wicket.markup.html.WebComponent;
+import wicket.markup.html.WebMarkupContainer;
 import wicket.markup.parser.AbstractMarkupFilter;
+import wicket.markup.resolver.IComponentResolver;
 import wicket.util.string.Strings;
 
 /**
- * This is a markup inline filter. It identifies wicket:message attributes and
- * adds an attribute modifier to the component tag that can localize
+ * This is a markup inline filter and a component resolver. It identifies
+ * wicket:message attributes and adds an attribute modifier to the component tag
+ * that can localize
  * wicket:message="attr-name:i18n-key,attr-name-2:i18n-key-2,..." expressions,
  * replacing values of attributes specified by attr-name with a localizer lookup
  * with key i18n-key. If an attribute being localized has a set value that value
- * will be used as the default value for the localization lookup.
+ * will be used as the default value for the localization lookup. This handler
+ * also resolves and localizes raw markup with wicket:message attribute.
  * 
  * @author Juergen Donnerstag
  * @author Igor Vaynberg
  */
 public final class WicketMessageTagHandler extends AbstractMarkupFilter
+		implements
+			IComponentResolver
 {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
 	/** TODO Post 1.2: General: Namespace should not be a constant */
 	private final static String WICKET_MESSAGE_ATTRIBUTE_NAME = "wicket:message";
 
@@ -111,7 +125,7 @@
 	 * 
 	 * @author Igor Vaynberg (ivaynberg)
 	 */
-	private static class AttributeLocalizer extends AbstractBehavior
+	public static class AttributeLocalizer extends AbstractBehavior
 	{
 		private static final long serialVersionUID = 1L;
 
@@ -158,5 +172,29 @@
 				}
 			}
 		}
+	}
+
+	public boolean resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
+	{
+		// localize any raw markup that has wicket:message attrs
+
+		if (WICKET_MESSAGE_CONTAINER_ID.equals(tag.getId()))
+		{
+			Component wc = null;
+			if (tag.isOpenClose())
+			{
+				wc = new WebComponent(WICKET_MESSAGE_CONTAINER_ID
+						+ container.getPage().getAutoIndex());
+			}
+			else
+			{
+				wc = new WebMarkupContainer(WICKET_MESSAGE_CONTAINER_ID
+						+ container.getPage().getAutoIndex());
+			}
+			wc.add(new AttributeLocalizer());
+			container.autoAdd(wc);
+			return true;
+		}
+		return false;
 	}
 }