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 2007/05/12 11:58:19 UTC

svn commit: r537371 - in /incubator/wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/ main/java/org/apache/wicket/markup/ main/java/org/apache/wicket/markup/html/internal/ main/java/org/apache/wicket/markup/resolver/ test/java/org/apache/wi...

Author: jdonnerstag
Date: Sat May 12 02:58:18 2007
New Revision: 537371

URL: http://svn.apache.org/viewvc?view=rev&rev=537371
Log:
wicket-549: allow to attach components to the <html> tag.

It is now possible to attach a wicket component to <html> for example to modify the xmlns:lang or lang attribute. A test has been added as well.

Fixed OnChangeAjaxBehaviorTest who's test output was based on  English locale.

Added:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java   (with props)
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html   (with props)
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html   (with props)
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java   (with props)
Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/WicketTag.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/form/OnChangeAjaxBehaviorTest.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java Sat May 12 02:58:18 2007
@@ -34,6 +34,7 @@
 import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
 import org.apache.wicket.markup.parser.filter.WicketMessageTagHandler;
 import org.apache.wicket.markup.resolver.AutoComponentResolver;
+import org.apache.wicket.markup.resolver.BodyContainerResolver;
 import org.apache.wicket.markup.resolver.EnclosureResolver;
 import org.apache.wicket.markup.resolver.FragmentResolver;
 import org.apache.wicket.markup.resolver.HtmlHeaderResolver;
@@ -856,6 +857,7 @@
 	{
 		settingsAccessible = true;
 		IPageSettings pageSettings = getPageSettings();
+		
 		// Install default component resolvers
 		pageSettings.addComponentResolver(new ParentResolver());
 		pageSettings.addComponentResolver(new AutoComponentResolver());
@@ -868,6 +870,7 @@
 		pageSettings.addComponentResolver(new RelativePathPrefixHandler());
 		pageSettings.addComponentResolver(new EnclosureResolver());
 		pageSettings.addComponentResolver(new WicketContainerResolver());
+		pageSettings.addComponentResolver(new BodyContainerResolver());
 
 		// Install button image resource factory
 		getResourceSettings().addResourceFactory("buttonFactory",

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java Sat May 12 02:58:18 2007
@@ -93,7 +93,6 @@
 	 */
 	private boolean hasNoCloseTag = false;
 
-
 	/** added behaviors */
 	// FIXME these behaviors here are merely for wicket:message attributes on
 	// tags that are also wicket components. since this addition behavors have

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/WicketTag.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/WicketTag.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/WicketTag.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/WicketTag.java Sat May 12 02:58:18 2007
@@ -100,14 +100,6 @@
 	}
 
 	/**
-	 * @return True, if tag name equals 'wicket:container'
-	 */
-	public final boolean isContainerTag()
-	{
-		return "container".equalsIgnoreCase(getName());
-	}
-
-	/**
 	 * @return True, if tag name equals 'wicket:child'
 	 */
 	public final boolean isChildTag()
@@ -124,7 +116,7 @@
 	}
 
 	/**
-	 * @return True, if tag name equals 'wicket:extend'
+	 * @return True, if tag name equals 'wicket:head'
 	 */
 	public final boolean isHeadTag()
 	{

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java Sat May 12 02:58:18 2007
@@ -24,12 +24,10 @@
 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.MarkupStream;
 import org.apache.wicket.markup.html.IHeaderResponse;
 import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.border.Border;
 import org.apache.wicket.response.StringResponse;
 
@@ -145,15 +143,7 @@
 			}
 
 			// must be a Page
-			if (parent instanceof WebPage)
-			{
-				renderHeaderSections((WebPage)parent, this);
-			}
-			else
-			{
-				throw new WicketRuntimeException(
-						"Programming error: 'parent' should be a Page or a Border.");
-			}
+			renderHeaderSections(parent, this);
 
 			// Automatically add <head> if necessary
 			CharSequence output = response.getBuffer();
@@ -210,11 +200,11 @@
 	 * added to the header.
 	 * 
 	 * @param page
-	 *            The page object
+	 *            Usually it is the page object, but there might also be that a WebMarkupContainer has been attached to the &lt;html&gt; tag 
 	 * @param container
 	 *            The header component container
 	 */
-	private final void renderHeaderSections(final WebPage page, final HtmlHeaderContainer container)
+	private final void renderHeaderSections(final MarkupContainer page, final HtmlHeaderContainer container)
 	{
 		page.renderHead(container);
 		// Make sure all Components interested in contributing to the header

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java?view=auto&rev=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java Sat May 12 02:58:18 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupStream;
+
+/**
+ * The &lt;body&gt; tag has always a HtmlBodyContainer associated which is
+ * always added to the Page. But it might be that a container has been added to
+ * &lt;html&gt; which means that when trying to find the component associated
+ * with the BODY_ID, it can not be found.
+ * <p>
+ * Someone might want to attach a component to the html tag for example to
+ * change the xmlns:lang or lang attribute.
+ * 
+ * @author Juergen Donnerstag
+ */
+public class BodyContainerResolver implements IComponentResolver
+{
+	private static final long serialVersionUID = 1L;
+	
+	/**
+	 * @see org.apache.wicket.markup.resolver.IComponentResolver#resolve(MarkupContainer,
+	 *      MarkupStream, ComponentTag)
+	 * 
+	 * @param container
+	 *            The container parsing its markup
+	 * @param markupStream
+	 *            The current markupStream
+	 * @param tag
+	 *            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,
+			final ComponentTag tag)
+	{
+		if (tag.isOpen() && tag.getName().equals("body") && (tag.getNamespace() == null))
+		{
+			String id = tag.getId();
+			Component body = container.getPage().get(id);
+			if (body != null)
+			{
+				body.render(markupStream);
+				return true;
+			}
+		}
+		
+		// We were not able to handle the tag
+		return false;
+	}
+}
\ No newline at end of file

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/resolver/BodyContainerResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/form/OnChangeAjaxBehaviorTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/form/OnChangeAjaxBehaviorTest.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/form/OnChangeAjaxBehaviorTest.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/form/OnChangeAjaxBehaviorTest.java Sat May 12 02:58:18 2007
@@ -16,7 +16,15 @@
  */
 package org.apache.wicket.ajax.form;
 
+import java.util.Locale;
+
+import org.apache.wicket.Request;
+import org.apache.wicket.Response;
+import org.apache.wicket.Session;
 import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.WicketTester;
+import org.apache.wicket.util.tester.WicketTester.DummyWebApplication;
 
 /**
  * @author Janne Hietam&auml;ki (janne)
@@ -28,6 +36,21 @@
 	 */
 	public void testRendering() throws Exception
 	{
+		WebApplication myApplication = new DummyWebApplication()
+		{
+			/**
+			 * @see org.apache.wicket.protocol.http.WebApplication#newSession(org.apache.wicket.Request, org.apache.wicket.Response)
+			 */
+			public Session newSession(Request request, Response response)
+			{
+				Session session = super.newSession(request, response);
+				session.setLocale(Locale.ENGLISH);
+				return session;
+			}
+		};
+		
+		tester = new WicketTester(myApplication);
+		
 		executeTest(OnChangeAjaxBehaviorTestPage.class,
 				"OnChangeAjaxBehaviorTestPage_expected.html");
 	}

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html?view=auto&rev=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html Sat May 12 02:58:18 2007
@@ -0,0 +1,7 @@
+<? xml version= "1.0" encoding ="UTF-8" ?>
+<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html lang="de" wicket:id="html" xmlns:wicket="" xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="[current language]">
+  <body>
+  </body>
+</html> 
\ No newline at end of file

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java?view=diff&rev=537371&r1=537370&r2=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java Sat May 12 02:58:18 2007
@@ -392,4 +392,12 @@
 	{
 		executeTest(SimplePage_12.class, "SimplePageExpectedResult_12.html");
 	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void testRenderHomePage_13() throws Exception
+	{
+		executeTest(SimplePage_13.class, "SimplePageExpectedResult_13.html");
+	}
 }

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html?view=auto&rev=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html Sat May 12 02:58:18 2007
@@ -0,0 +1,7 @@
+<? xml version= "1.0" encoding ="UTF-8" ?>
+<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html wicket:id="html" xmlns:wicket xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="[current language]" lang="[current language]">
+  <body>
+  </body>
+</html> 
\ No newline at end of file

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java?view=auto&rev=537371
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java Sat May 12 02:58:18 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.html.basic;
+
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.model.Model;
+
+
+/**
+ * Wicket component attached to &lt;html&gt; tag
+ * 
+ * @author Juergen Donnerstag
+ */
+public class SimplePage_13 extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 */
+	public SimplePage_13()
+	{
+		add(new WebMarkupContainer("html").add(new AttributeModifier("lang", new Model("de"))));
+	}
+}

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_13.java
------------------------------------------------------------------------------
    svn:eol-style = native