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 2006/10/19 23:14:46 UTC

svn commit: r465891 - in /incubator/wicket/trunk/wicket/src/main/java/wicket: MarkupContainer.java markup/html/WebPage.java

Author: jdonnerstag
Date: Thu Oct 19 14:14:46 2006
New Revision: 465891

URL: http://svn.apache.org/viewvc?view=rev&rev=465891
Log:
MarkupContainer: cache the associate markup in a transient variable and allow subclasses to react on that event
by subclassing MarkupContainer.onAssociatedMarkupLoaded(). Page is the first Container which makes use of it
to register the body and the header container. Modified Component() constructor which is only used by Page
to call getMarkupFragment() as well.

Modified:
    incubator/wicket/trunk/wicket/src/main/java/wicket/MarkupContainer.java
    incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/MarkupContainer.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/MarkupContainer.java?view=diff&rev=465891&r1=465890&r2=465891
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/MarkupContainer.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/MarkupContainer.java Thu Oct 19 14:14:46 2006
@@ -107,6 +107,9 @@
 	 */
 	private transient MarkupStream markupStream;
 
+	/** The markup fragments from the associated file */
+	private transient MarkupFragment associatedMarkup;
+	
 	/**
 	 * Package scope constructor, only used by pages.
 	 * 
@@ -805,30 +808,50 @@
 	 */
 	public final MarkupFragment getAssociatedMarkup(final boolean throwException)
 	{
-		try
-		{
-			return getApplication().getMarkupCache().getMarkup(this, throwException);
-		}
-		catch (MarkupException ex)
+		if (this.associatedMarkup == null)
 		{
-			// re-throw it. The exception contains already all the information
-			// required.
-			throw ex;
-		}
-		catch (WicketRuntimeException ex)
-		{
-			// throw exception since there is no associated markup
-			throw new MarkupNotFoundException(
-					exceptionMessage("Markup of type '"
-							+ getMarkupType()
-							+ "' for component '"
-							+ getClass().getName()
-							+ "' not found."
-							+ " Enable debug messages for wicket.util.resource to get a list of all filenames tried"),
-					ex);
+			try
+			{
+				this.associatedMarkup = getApplication().getMarkupCache().getMarkup(this, throwException);
+			}
+			catch (MarkupException ex)
+			{
+				// re-throw it. The exception contains already all the information
+				// required.
+				throw ex;
+			}
+			catch (WicketRuntimeException ex)
+			{
+				// throw exception since there is no associated markup
+				throw new MarkupNotFoundException(
+						exceptionMessage("Markup of type '"
+								+ getMarkupType()
+								+ "' for component '"
+								+ getClass().getName()
+								+ "' not found."
+								+ " Enable debug messages for wicket.util.resource to get a list of all filenames tried"),
+						ex);
+			}
+			
+			onAssociatedMarkupLoaded(this.associatedMarkup);
 		}
+		
+		return this.associatedMarkup;
 	}
 
+	/**
+	 * Components which whish to analyze the markup and automatically add Components
+	 * to the MarkupConainer may sublcass this method.
+	 * <p>
+	 * As the associated markup gets cached with the MarkupContainer, this method
+	 * is guaranteed to be called just once.
+	 * 
+	 * @param markup The associated markup just loaded.
+	 */
+	protected void onAssociatedMarkupLoaded(final MarkupFragment markup)
+	{
+	}
+	
 	/**
 	 * Get the markup stream set on this container.
 	 * 

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java?view=diff&rev=465891&r1=465890&r2=465891
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java Thu Oct 19 14:14:46 2006
@@ -36,7 +36,6 @@
 import wicket.behavior.AbstractBehavior;
 import wicket.markup.ComponentTag;
 import wicket.markup.MarkupFragment;
-import wicket.markup.MarkupNotFoundException;
 import wicket.markup.MarkupStream;
 import wicket.markup.html.internal.HtmlBodyContainer;
 import wicket.markup.html.internal.HtmlHeaderContainer;
@@ -123,7 +122,6 @@
 	 */
 	protected WebPage()
 	{
-		commonInit();
 	}
 
 	/**
@@ -132,7 +130,6 @@
 	protected WebPage(final IModel<T> model)
 	{
 		super(model);
-		commonInit();
 	}
 
 	/**
@@ -141,7 +138,6 @@
 	protected WebPage(final PageMap pageMap)
 	{
 		super(pageMap);
-		commonInit();
 	}
 
 	/**
@@ -150,7 +146,6 @@
 	protected WebPage(final PageMap pageMap, final IModel<T> model)
 	{
 		super(pageMap, model);
-		commonInit();
 	}
 
 	/**
@@ -267,18 +262,11 @@
 	/**
 	 * Common code executed by constructors.
 	 */
-	private void commonInit()
+	protected void onAssociatedMarkupLoaded(final MarkupFragment markup)
 	{
 		// Add a Body container if the associated markup contains a <body> tag
 		// get markup stream gracefully
-		MarkupFragment fragment = getAssociatedMarkup(false);
-		if (fragment == null)
-		{
-			throw new MarkupNotFoundException(
-					"Each Page must have associated markup. Unable to find the markup file for Page: "
-							+ this.toString());
-		}
-		MarkupStream markupStream = new MarkupStream(fragment);
+		MarkupStream markupStream = new MarkupStream(markup);
 		
 		// The <body> container. It can be accessed, replaced
 		// and attribute modifiers can be attached. <body> tags without