Author: jdonnerstag
Date: Sun Oct 11 13:56:16 2009
New Revision: 824076
URL: http://svn.apache.org/viewvc?rev=824076&view=rev
Log:
First step towards using MarkupFragment for the render process
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/HeaderPartContainer.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/lang/Checks.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/CommonModelPage.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPage_5.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markupFragments/MarkupFragmentTest.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java Sun Oct
11 13:56:16 2009
@@ -2363,15 +2363,29 @@
*
* @param markupStream
*/
- public final void render(final MarkupStream markupStream)
+ public final void render(MarkupStream markupStream)
{
if (getApplication().getMarkupFragmentEnabled())
{
+ // Step 1: Make sure there is a markup available for
the Component
IMarkupFragment markup = getMarkup();
if (!(this instanceof Page) && (markup == null))
{
throw new IllegalArgumentException("jdo: Markup
not found: " + toString());
}
+
+ // Step 2: A markup stream based on the markup should
yield the same result.
+ if (markupStream != null)
+ {
+ MarkupStream ms = new MarkupStream(markup);
+
+ // We need to skip the component in the
original markup stream to avoid
+ // exceptions later on.
+ markupStream.skipComponent();
+
+ // We want to use the new markup stream
+ markupStream = ms;
+ }
}
// We need to know the index before we do the visibility check.
@@ -3722,6 +3736,10 @@
*/
protected MarkupStream locateMarkupStream()
{
+ if (getApplication().getMarkupFragmentEnabled())
+ {
+ return new MarkupStream(getMarkup());
+ }
return new MarkupFragmentFinder().find(this);
}
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/HeaderPartContainer.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/HeaderPartContainer.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/HeaderPartContainer.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/HeaderPartContainer.java
Sun Oct 11 13:56:16 2009
@@ -98,6 +98,13 @@
@Override
public IMarkupFragment getMarkup()
{
- return container.getAssociatedMarkup().find(null, "_head", 0);
+ return getMarkupStream().getMarkupFragment();
+// IMarkupFragment markup = container.getAssociatedMarkup();
+// if (markup == null)
+// {
+// return null;
+// }
+//
+// return markup.find(null, "_head", 0);
}
}
\ No newline at end of file
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
Sun Oct 11 13:56:16 2009
@@ -27,6 +27,7 @@
import org.apache.wicket.markup.MarkupFragment;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
+import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
@@ -508,24 +509,32 @@
}
/**
- * The implementation is against the rule that getMarkup()
returns the components markup
- * which in this case would be something like
<code><wicket:body/></code>. But that
- * doesn't work if the body container has been added to some
kind of wrapper (e.g. Form,
- * another Border, etc.). Such a parent would not be able to
find the body. The reason is
- * that the body container's id and the tag id are different.
The tag's id is always "_body"
- * where as the body's id must be unique per parent and thus is
something like border.id +
- * "_body". Since the Page object is not yet available in the
constructor,
- * Page#getAutoIndex() can not be used. So
Border.BorderBodyContainer is an exception in
- * that it returns what you would expect from getMarkup(null).
Via
- * <code>getBodyContainer().getParent().getMarkup(new
WebComponent("_body"));</code> you can
- * still access the <code><wicket:body/></code> markup if
really needed.
- *
* @see org.apache.wicket.Component#getMarkup()
*/
@Override
public IMarkupFragment getMarkup()
{
- return Border.this.getMarkup();
+ return getParent().getMarkup(new WebComponent(BODY_ID));
+ }
+
+ /**
+ * @see
org.apache.wicket.MarkupContainer#getMarkup(org.apache.wicket.Component)
+ */
+ @Override
+ public IMarkupFragment getMarkup(final Component child)
+ {
+ IMarkupFragment markup = Border.this.getMarkup();
+ if (markup == null)
+ {
+ return null;
+ }
+
+ if (child == null)
+ {
+ return markup;
+ }
+
+ return markup.find(null, child.getId(), 0);
}
}
}
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
Sun Oct 11 13:56:16 2009
@@ -1643,6 +1643,10 @@
}
}
+ /**
+ * @see
org.apache.wicket.Component#renderPlaceholderTag(org.apache.wicket.markup.ComponentTag,
+ * org.apache.wicket.Response)
+ */
@Override
protected void renderPlaceholderTag(ComponentTag tag, Response response)
{
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/RelativePathPrefixHandler.java
Sun Oct 11 13:56:16 2009
@@ -28,7 +28,6 @@
import org.apache.wicket.markup.MarkupElement;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.resolver.IComponentResolver;
import org.apache.wicket.request.IRequestCodingStrategy;
@@ -151,15 +150,15 @@
{
if ((tag != null) &&
(tag.getId().startsWith(WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID)))
{
- final Component wc;
-
String id = WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID +
container.getPage().getAutoIndex();
+ final IMarkupFragment markup =
markupStream.getMarkupFragment();
+
// we do not want to mess with the hierarchy, so the
container has to be
// transparent as it may have wicket components inside.
for example a raw anchor tag
// that contains a label.
- wc = new WebMarkupContainer(id)
+ final Component wc = new WebMarkupContainer(id)
{
private static final long serialVersionUID = 1L;
@@ -169,11 +168,7 @@
@Override
public IMarkupFragment getMarkup()
{
- // This is a small trick. We can not
find markup fragments by ID, only by
- // Component. To search for an ID we
simply need to create a dummy component
- // with that ID.
- return getParent().getMarkup(
- new
WebComponent(WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID));
+ return markup;
}
@Override
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
Sun Oct 11 13:56:16 2009
@@ -214,6 +214,8 @@
final String id = tag.getId() +
container.getPage().getAutoIndex();
tag.setId(id);
+ final IMarkupFragment markup =
markupStream.getMarkupFragment();
+
final Component component = new
WebMarkupContainer(id)
{
private static final long
serialVersionUID = 1L;
@@ -233,7 +235,7 @@
@Override
public IMarkupFragment getMarkup()
{
- return
markupStream.getMarkupFragment();
+ return markup;
}
};
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java
Sun Oct 11 13:56:16 2009
@@ -20,6 +20,7 @@
import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.IMarkupFragment;
import org.apache.wicket.markup.MarkupException;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
@@ -89,6 +90,8 @@
// head first.
if (container instanceof WebPage)
{
+ final IMarkupFragment markup =
markupStream.getMarkupFragment();
+
// Create a special header component which will
gather
// additional input the <head> from
'contributors'.
final MarkupContainer header =
newHtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID +
@@ -108,6 +111,12 @@
{
return true;
}
+
+ @Override
+ public IMarkupFragment getMarkup()
+ {
+ return markup;
+ }
};
header2.setRenderBodyOnly(true);
@@ -118,6 +127,8 @@
}
else if (container instanceof HtmlHeaderContainer)
{
+ final IMarkupFragment markup =
markupStream.getMarkupFragment();
+
// It is <wicket:head>. Because they do not
provide any
// additional functionality there are merely a
means of surrounding
// relevant markup. Thus we simply create a
WebMarkupContainer to handle
@@ -132,6 +143,12 @@
{
return true;
}
+
+ @Override
+ public IMarkupFragment getMarkup()
+ {
+ return markup;
+ }
};
header.setRenderBodyOnly(true);
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
Sun Oct 11 13:56:16 2009
@@ -31,7 +31,6 @@
import org.apache.wicket.markup.MarkupException;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.html.internal.MarkupTagIterator;
import org.apache.wicket.markup.parser.XmlTag;
import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
import org.apache.wicket.model.Model;
@@ -141,7 +140,9 @@
}
final String id = "_message_" +
container.getPage().getAutoIndex();
- MessageContainer label = new
MessageContainer(id, messageKey);
+ MessageContainer label = new
MessageContainer(id, messageKey,
+ markupStream.getMarkupFragment());
+
label.setRenderBodyOnly(container.getApplication()
.getMarkupSettings()
.getStripWicketTags());
@@ -178,17 +179,23 @@
{
private static final long serialVersionUID = 1L;
+ private final IMarkupFragment markupFragment;
+
/**
* Construct.
*
* @param id
* @param messageKey
+ * @param markupFragment
*/
- public MessageContainer(final String id, final String
messageKey)
+ public MessageContainer(final String id, final String
messageKey,
+ final IMarkupFragment markupFragment)
{
// The message key becomes the model
super(id, new Model<String>(messageKey));
+ this.markupFragment = markupFragment;
+
setEscapeModelStrings(false);
}
@@ -414,28 +421,7 @@
@Override
public IMarkupFragment getMarkup()
{
- String key = getDefaultModelObjectAsString();
- if (Strings.isEmpty(key))
- {
- throw new WicketRuntimeException(
- "Expected the model object to contain
the message key. But the model object was null");
- }
-
- // Get the parent markup. Make sure that in case of
Border and Panel you get the
- // associated markup
- IMarkupFragment markup = getParent().getMarkup(null);
- MarkupTagIterator iter = new
MarkupTagIterator(markup).setWicketTagsOnly(true)
- .setOpenTagOnly(true);
- while (iter.hasNext())
- {
- WicketTag tag = iter.nextWicketTag();
- if (tag.isMessageTag() &&
key.equals(tag.getAttribute("key")))
- {
- return iter.getMarkupFragment();
- }
- }
-
- return null;
+ return markupFragment;
}
}
}
\ No newline at end of file
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/lang/Checks.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/lang/Checks.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/lang/Checks.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/lang/Checks.java
Sun Oct 11 13:56:16 2009
@@ -1,45 +1,62 @@
+/*
+ * 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.util.lang;
import org.apache.wicket.util.string.Strings;
public class Checks
{
- public static void argumentNotNull(Object argument, String name)
- {
- if (argument == null)
- {
- throw new IllegalArgumentException("Argument '" + name + "' may
not be null.");
- }
- }
+ public static void argumentNotNull(Object argument, String name)
+ {
+ if (argument == null)
+ {
+ throw new IllegalArgumentException("Argument '" + name
+ "' may not be null.");
+ }
+ }
- public static void argumentNotEmpty(String argument, String name)
- {
- if (Strings.isEmpty(argument))
- {
- throw new IllegalArgumentException("Argument '" + name +
- "' may not be null or empty string.");
- }
- }
+ public static void argumentNotEmpty(String argument, String name)
+ {
+ if (Strings.isEmpty(argument))
+ {
+ throw new IllegalArgumentException("Argument '" + name +
+ "' may not be null or empty string.");
+ }
+ }
- /**
- * TODO javadoc and unit test
- * @param <T>
- * @param min
- * @param max
- * @param value
- * @param name
- */
- public static <T extends Comparable<T>> void argumentWithinRange(T min, T
max, T value,
- String name)
- {
- // TODO nullchecks
- if (value.compareTo(min) < 0 || value.compareTo(max) > 0)
- {
- throw new IllegalArgumentException(String.format(
- "Argument '%s' must have a value within [%s,%s], but was
%s", name, min, max,
- value));
- }
+ /**
+ * TODO javadoc and unit test
+ *
+ * @param <T>
+ * @param min
+ * @param max
+ * @param value
+ * @param name
+ */
+ public static <T extends Comparable<T>> void argumentWithinRange(T min,
T max, T value,
+ String name)
+ {
+ // TODO nullchecks
+ if (value.compareTo(min) < 0 || value.compareTo(max) > 0)
+ {
+ throw new IllegalArgumentException(
+ String.format("Argument '%s' must have a value
within [%s,%s], but was %s", name,
+ min, max, value));
+ }
- return;
- }
+ return;
+ }
}
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/CommonModelPage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/CommonModelPage.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/CommonModelPage.java
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/CommonModelPage.java
Sun Oct 11 13:56:16 2009
@@ -40,12 +40,12 @@
add(border);
Form form1 = new Form("form1");
- border.addToBorderBody(form1);
+ border.add(form1);
form1.add(new TextField("quantity1", new PropertyModel(this,
"quantity1")));
Form form2 = new Form("form2");
- border.addToBorderBody(form2);
+ border.add(form2);
form2.add(new TextField("quantity2", new PropertyModel(this,
"quantity2")));
}
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=824076&r1=824075&r2=824076&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
Sun Oct 11 13:56:16 2009
@@ -16,6 +16,7 @@
*/
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;
@@ -65,13 +66,21 @@
return getAssociatedMarkupStream(false);
}
- /**
- * @see org.apache.wicket.markup.html.panel.Fragment#getMarkup()
- */
@Override
- public IMarkupFragment getMarkup()
+ public IMarkupFragment getMarkup(Component child)
{
- return getAssociatedMarkup();
+ IMarkupFragment markup = getAssociatedMarkup();
+ if (markup == null)
+ {
+ return null;
+ }
+
+ if (child == null)
+ {
+ return markup;
+ }
+
+ return markup.find(null, child.getId(), 0);
}
}
}
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markupFragments/MarkupFragmentTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markupFragments/MarkupFragmentTest.java?rev=824076&r1=824075&r2=824076&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markupFragments/MarkupFragmentTest.java
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markupFragments/MarkupFragmentTest.java
Sun Oct 11 13:56:16 2009
@@ -158,6 +158,9 @@
assertNull(border.getBodyContainer().getAssociatedMarkup());
markup = border.getBodyContainer().getMarkup();
+ compare(markup, "<wicket:body/>");
+
+ markup = border.getBodyContainer().getMarkup(null);
compare(markup, "<span wicket:id=\"border\">test</span>");
markup = border.getBodyContainer().getParent().getMarkup(new
WebComponent("_body"));
@@ -196,6 +199,9 @@
compare(markup, "<wicket:body>333</wicket:body>");
markup = border.getBodyContainer().getMarkup();
+ compare(markup, "<wicket:body>333</wicket:body>");
+
+ markup = border.getBodyContainer().getMarkup(null);
compare(markup, "<span wicket:id=\"border2\">test</span>");
// getMarkup(null) returns the markup which is used to find a
child component