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 2010/10/14 17:55:52 UTC

svn commit: r1022589 - in /wicket/trunk/wicket/src: main/java/org/apache/wicket/markup/html/panel/ test/java/org/apache/wicket/markup/html/border/ test/java/org/apache/wicket/markup/html/panel/

Author: ivaynberg
Date: Thu Oct 14 15:55:51 2010
New Revision: 1022589

URL: http://svn.apache.org/viewvc?rev=1022589&view=rev
Log:

Issue: WICKET-3079

Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_8.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_9.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java?rev=1022589&r1=1022588&r2=1022589&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java Thu Oct 14 15:55:51 2010
@@ -20,18 +20,17 @@ import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.IMarkupFragment;
-import org.apache.wicket.markup.MarkupElement;
 import org.apache.wicket.markup.MarkupException;
 import org.apache.wicket.markup.MarkupNotFoundException;
 import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.parser.XmlTag;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.util.lang.Objects;
 
 /**
  * Usually you either have a markup file or a xml tag with wicket:id="myComponent" to associate
- * markup with a component. However in some rare cases, especially when working with small panels it
+ * markup with a component. However in some use cases, especially when working with small panels it
  * is a bit awkward to maintain tiny pieces of markup in plenty of panel markup files. Use cases are
  * for example list views where list items are different depending on a state.
  * <p>
@@ -52,7 +51,7 @@ import org.apache.wicket.util.lang.Objec
  * 
  * @author Juergen Donnerstag
  */
-public class Fragment extends WebMarkupContainerWithAssociatedMarkup
+public class Fragment extends WebMarkupContainer
 {
 	private static final long serialVersionUID = 1L;
 
@@ -154,44 +153,7 @@ public class Fragment extends WebMarkupC
 			markupStream.skipRawMarkup();
 		}
 
-		final MarkupStream providerMarkupStream = chooseMarkupStream(markupStream);
-		if (providerMarkupStream == null)
-		{
-			throw new MarkupNotFoundException(
-				"Fragment: No markup stream found for providing markup container " +
-					markupProvider.toString() + ". Fragment: " + toString());
-		}
-
-		renderFragment(providerMarkupStream, openTag);
-	}
-
-	/**
-	 * Get the markup stream which shall be used to search for the fragment
-	 * 
-	 * @param markupStream
-	 *            The markup stream is associated with the component (not the fragment)
-	 * @return The markup stream to be used to find the fragment markup
-	 */
-	protected MarkupStream chooseMarkupStream(final MarkupStream markupStream)
-	{
-		MarkupStream stream = null;
-
-		// TODO Post 1.3: Cleanup this after deprecated constructors are removed
-		if (markupProvider == null)
-		{
-			stream = markupStream;
-		}
-		else
-		{
-			stream = markupProvider.getAssociatedMarkupStream(false);
-			if (stream == null)
-			{
-				// The following statement assumes that the markup provider is a
-				// parent along the line up to the Page
-				stream = new MarkupStream(markupProvider.getMarkup(null));
-			}
-		}
-		return stream;
+		renderFragment(openTag);
 	}
 
 	/**
@@ -199,134 +161,48 @@ public class Fragment extends WebMarkupC
 	 * 
 	 * @see #onComponentTagBody(MarkupStream, ComponentTag)
 	 * 
-	 * @param providerMarkupStream
 	 * @param openTag
 	 */
-	private void renderFragment(final MarkupStream providerMarkupStream, final ComponentTag openTag)
+	private void renderFragment(final ComponentTag openTag)
 	{
-		// remember the current position in the markup. Will have to come back to it.
-		int currentIndex = providerMarkupStream.getCurrentIndex();
+		MarkupStream stream = new MarkupStream(getMarkup(null));
+		setMarkupStream(stream);
 
-		// Find the markup fragment
-		while (providerMarkupStream.hasMore())
-		{
-			MarkupElement elem = providerMarkupStream.get();
-			if (elem instanceof ComponentTag)
-			{
-				ComponentTag tag = providerMarkupStream.getTag();
-				if (tag.isOpen() || tag.isOpenClose())
-				{
-					if (tag.getId().equals(markupId))
-					{
-						break;
-					}
-				}
-			}
-
-			providerMarkupStream.nextOpenTag();
-		}
+		// Get the fragments open tag
+		ComponentTag fragmentOpenTag = stream.getTag();
 
-		if (providerMarkupStream.hasMore() == false)
+		// if it is an open close tag, skip this fragment.
+		if (!fragmentOpenTag.isOpenClose())
 		{
-			throw new MarkupException("Markup of component class `" +
-				providerMarkupStream.getContainerClass().getName() +
-				"` does not contain a fragment with wicket:id `" + markupId + "`. Context: " +
-				toString());
-		}
-
-		try
-		{
-			// Get the fragments open tag
-			ComponentTag fragmentOpenTag = providerMarkupStream.getTag();
-
-			// if it is an open close tag, skip this fragment.
-			if (!fragmentOpenTag.isOpenClose())
-			{
-				// We'll completely ignore the fragments open tag. It'll not be
-				// rendered
-				providerMarkupStream.next();
+			// We'll completely ignore the fragments open tag. It'll not be
+			// rendered
+			stream.next();
 
-				// Render the body of the fragment
-				super.onComponentTagBody(providerMarkupStream, fragmentOpenTag);
-			}
+			// Render the body of the fragment
+			super.onComponentTagBody(stream, fragmentOpenTag);
 		}
-		finally
-		{
-			// Make sure the markup stream is positioned where we started back
-			// at the original component
-			providerMarkupStream.setCurrentIndex(currentIndex);
-		}
-	}
-
-	/**
-	 * @see org.apache.wicket.MarkupContainer#hasAssociatedMarkup()
-	 */
-	@Override
-	public boolean hasAssociatedMarkup()
-	{
-		return true;
 	}
 
 	/**
-	 * @see org.apache.wicket.MarkupContainer#getAssociatedMarkupStream(boolean)
+	 * Returns markup provider associated with this fragment
+	 * 
+	 * @return markup provider
 	 */
-	@Override
-	public MarkupStream getAssociatedMarkupStream(boolean throwException)
+	protected final MarkupContainer getMarkupProvider()
 	{
-		MarkupStream stream = null;
-
-		// TODO Post 1.3: Cleanup this after deprecated constructors are removed
-		if (markupProvider != null)
-		{
-			stream = markupProvider.getAssociatedMarkupStream(false);
-			if (stream == null)
-			{
-				// The following statement assumes that the markup provider is a
-				// parent along the line up to the Page
-				stream = markupProvider.getMarkupStream();
-			}
-		}
-
-		// try self's markup stream
-		if (stream == null)
-		{
-			stream = super.getAssociatedMarkupStream(false);
-		}
-
-		// if self doesn't have markup stream try the parent's
-		if (stream == null)
-		{
-			MarkupContainer container = getParent();
-			while (container != null)
-			{
-				if (container.hasAssociatedMarkup())
-				{
-					stream = container.getAssociatedMarkupStream(false);
-					break;
-				}
-				container = container.getParent();
-			}
-		}
-
-		// if we cant find any markup stream
-		if ((stream == null) && throwException)
-		{
-			// fail, but fail with an error message that will point to this
-			// component
-			super.getAssociatedMarkupStream(true);
-		}
-
-		return stream;
+		return (markupProvider != null ? markupProvider : getParent());
 	}
 
 	/**
-	 * Returns markup provider associated with this fragment
+	 * Get the markup stream which shall be used to search for the fragment
 	 * 
-	 * @return markup provider
+	 * @param markupStream
+	 *            The markup stream is associated with the component (not the fragment)
+	 * @return The markup stream to be used to find the fragment markup
 	 */
-	public final MarkupContainer getMarkupProvider()
+	protected IMarkupFragment chooseMarkup()
 	{
-		return markupProvider;
+		return getMarkupProvider().getMarkup(null);
 	}
 
 	/**
@@ -335,36 +211,43 @@ public class Fragment extends WebMarkupC
 	@Override
 	public IMarkupFragment getMarkup(final Component child)
 	{
-		IMarkupFragment markup = null;
-
-		// Get the markup provider
-		MarkupContainer provider = getMarkupProvider();
-		if (provider == null)
+		// Get the markup to search for the fragment markup
+		IMarkupFragment markup = chooseMarkup();
+		if (markup == null)
 		{
-			provider = getParent();
+			throw new MarkupException(
+				"chooseMarkup() returned null. No markup to search for fragment markup with id: " +
+					markupId);
 		}
 
-		if (provider.hasAssociatedMarkup())
-		{
-			markup = provider.getAssociatedMarkup();
-		}
-		else
-		{
-			markup = getParent().getMarkup();
+		// Search for the fragment markup
+		IMarkupFragment childMarkup = markup.find(markupId);
+		if (childMarkup == null)
+		{
+			// There is one more option if the markup provider has associated markup
+			MarkupContainer markupProvider = getMarkupProvider();
+			if (markupProvider.hasAssociatedMarkup())
+			{
+				markup = markupProvider.getAssociatedMarkup();
+				if (markup != null)
+				{
+					childMarkup = markup.find(markupId);
+				}
+			}
 		}
 
-		if (markup == null)
+		if (childMarkup == null)
 		{
-			return null;
+			throw new MarkupNotFoundException("No Markup found for Fragment " + markupId +
+				" in providing markup container " + markupProvider.toString());
 		}
 
-		markup = markup.find(markupId);
-
 		if (child == null)
 		{
-			return markup;
+			return childMarkup;
 		}
 
-		return markup.find(child.getId());
+		// search for the child insight the fragment markup
+		return childMarkup.find(child.getId());
 	}
 }

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_8.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_8.java?rev=1022589&r1=1022588&r2=1022589&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_8.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_8.java Thu Oct 14 15:55:51 2010
@@ -35,7 +35,7 @@ public class BoxBorderTestPage_8 extends
 		Border border1 = new BorderComponent1("border1");
 		add(border1);
 
-		Fragment panel1 = new Fragment("panel1", "frag1", this);
+		Fragment panel1 = new Fragment("panel1", "frag1", border1.getBodyContainer());
 		border1.addToBorderBody(panel1);
 
 		Fragment panel2 = new Fragment("panel2", "frag2", this);

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_9.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_9.java?rev=1022589&r1=1022588&r2=1022589&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_9.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_9.java Thu Oct 14 15:55:51 2010
@@ -37,7 +37,8 @@ public class BoxBorderTestPage_9 extends
 		Border myBorder = new BorderComponent1("myBorder");
 		add(myBorder);
 
-		Fragment panel1 = new Fragment("fragmentsWillBeRenderedHere", "fragmentSource", this);
+		Fragment panel1 = new Fragment("fragmentsWillBeRenderedHere", "fragmentSource",
+			myBorder.getBodyContainer());
 		myBorder.addToBorderBody(panel1);
 	}
 }

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java?rev=1022589&r1=1022588&r2=1022589&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java Thu Oct 14 15:55:51 2010
@@ -16,10 +16,8 @@
  */
 package org.apache.wicket.markup.html.panel;
 
-import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.markup.IMarkupFragment;
-import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.html.WebPage;
 
 
@@ -61,26 +59,9 @@ public class InlinePanelPage_5 extends W
 		}
 
 		@Override
-		protected MarkupStream chooseMarkupStream(MarkupStream markupStream)
+		protected IMarkupFragment chooseMarkup()
 		{
-			return getAssociatedMarkupStream(false);
-		}
-
-		@Override
-		public IMarkupFragment getMarkup(Component child)
-		{
-			IMarkupFragment markup = getAssociatedMarkup();
-			if (markup == null)
-			{
-				return null;
-			}
-
-			if (child == null)
-			{
-				return markup;
-			}
-
-			return markup.find(child.getId());
+			return getAssociatedMarkup();
 		}
 	}
 }