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 2010/12/04 17:48:36 UTC
svn commit: r1042212 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket: MarkupContainer.java
markup/ComponentTag.java markup/TagUtils.java markup/html/border/Border.java
Author: jdonnerstag
Date: Sat Dec 4 16:48:35 2010
New Revision: 1042212
URL: http://svn.apache.org/viewvc?rev=1042212&view=rev
Log:
markup fragment related cleanup to Border
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/TagUtils.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=1042212&r1=1042211&r2=1042212&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java Sat Dec 4 16:48:35 2010
@@ -696,7 +696,7 @@ public abstract class MarkupContainer ex
*/
public final void renderAssociatedMarkup(final String openTagName, final String exceptionMessage)
{
- // Get markup associated with Border or Panel component
+ // Get associated markup file for the Border or Panel component
final MarkupStream associatedMarkupStream = new MarkupStream(getMarkup(null));
// Get open tag in associated markup of border component
@@ -722,7 +722,9 @@ public abstract class MarkupContainer ex
String className = null;
- if (getApplication().getDebugSettings().isOutputMarkupContainerClassName())
+ final boolean outputClassName = getApplication().getDebugSettings()
+ .isOutputMarkupContainerClassName();
+ if (outputClassName)
{
Class<?> klass = getClass();
while (klass.isAnonymousClass())
@@ -737,7 +739,7 @@ public abstract class MarkupContainer ex
renderComponentTagBody(associatedMarkupStream, associatedMarkupOpenTag);
- if (getApplication().getDebugSettings().isOutputMarkupContainerClassName())
+ if (outputClassName)
{
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(className);
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java?rev=1042212&r1=1042211&r2=1042212&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/ComponentTag.java Sat Dec 4 16:48:35 2010
@@ -747,7 +747,6 @@ public class ComponentTag extends Markup
this.modified = modified;
}
-
/**
*
* @return True, if the component tag has been marked modified
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/TagUtils.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/TagUtils.java?rev=1042212&r1=1042211&r2=1042212&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/TagUtils.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/TagUtils.java Sat Dec 4 16:48:35 2010
@@ -105,4 +105,40 @@ public class TagUtils
}
return false;
}
+
+ /**
+ *
+ * @param elem
+ * @return True if the current markup element is a <wicket:body> tag
+ */
+ public static final boolean isWicketBodyTag(final MarkupElement elem)
+ {
+ if (elem instanceof WicketTag)
+ {
+ WicketTag wtag = (WicketTag)elem;
+ if (wtag.isBodyTag())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param elem
+ * @return True if the current markup element is a <wicket:border> tag
+ */
+ public static final boolean isWicketBorderTag(final MarkupElement elem)
+ {
+ if (elem instanceof WicketTag)
+ {
+ WicketTag wtag = (WicketTag)elem;
+ if (wtag.isBorderTag())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}
\ 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=1042212&r1=1042211&r2=1042212&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 Sat Dec 4 16:48:35 2010
@@ -18,7 +18,6 @@ package org.apache.wicket.markup.html.bo
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
-import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
@@ -26,7 +25,7 @@ import org.apache.wicket.markup.MarkupEl
import org.apache.wicket.markup.MarkupException;
import org.apache.wicket.markup.MarkupFragment;
import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.WicketTag;
+import org.apache.wicket.markup.TagUtils;
import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
import org.apache.wicket.markup.parser.XmlTag.TagType;
@@ -151,18 +150,6 @@ public abstract class Border extends Web
private final BorderBodyContainer body;
/**
- * only required during render phase. The markup stream associated with <span
- * wicket:id="myBorder"
- */
- private transient MarkupStream originalMarkupStream;
-
- /** only required during render phase. The <span wicket:id="myBorder"> tag */
- private transient ComponentTag openTag;
-
- /** */
- private int beginOfBodyIndex;
-
- /**
* @see org.apache.wicket.Component#Component(String)
*/
public Border(final String id)
@@ -294,10 +281,6 @@ public abstract class Border extends Web
return getBodyContainer().get(path);
}
- /**
- * @see org.apache.wicket.markup.resolver.IComponentResolver#resolve(org.apache.wicket.MarkupContainer,
- * org.apache.wicket.markup.MarkupStream, org.apache.wicket.markup.ComponentTag)
- */
public Component resolve(final MarkupContainer container, final MarkupStream markupStream,
final ComponentTag tag)
{
@@ -306,49 +289,31 @@ public abstract class Border extends Web
{
// We are only interested in border body tags. The tag ID actually is irrelevant since
// always preset with the same default
- if (tag instanceof WicketTag)
+ if (TagUtils.isWicketBodyTag(tag))
{
- WicketTag wtag = (WicketTag)tag;
- if (wtag.isBodyTag())
- {
- return body;
- }
+ return body;
}
}
return null;
}
- /**
- * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
- */
@Override
protected void onComponentTag(final ComponentTag tag)
{
if (tag.isOpen() == false)
{
- throw new WicketRuntimeException(
+ throw new MarkupException(
"The border tag must be an open tag. Open-close is not allowed: " + tag.toString());
}
super.onComponentTag(tag);
}
- /**
- * @see org.apache.wicket.Component#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
- * org.apache.wicket.markup.ComponentTag)
- */
@Override
protected final void onComponentTagBody(final MarkupStream markupStream,
final ComponentTag openTag)
{
- // Remember the data for easy access by the Body component
- this.openTag = openTag;
- originalMarkupStream = markupStream;
-
- // Remember the current position (start of border-body) of the markupstream
- beginOfBodyIndex = originalMarkupStream.getCurrentIndex();
-
// Render the associated markup
renderAssociatedMarkup("border",
"Markup for a border component must begin a tag like '<wicket:border>'");
@@ -357,7 +322,8 @@ public abstract class Border extends Web
}
/**
- * @see org.apache.wicket.MarkupContainer#getMarkup(org.apache.wicket.Component)
+ * Search for the child markup in the file associated with the Border. The child markup must in
+ * between the <wicket:border> tags.
*/
@Override
public IMarkupFragment getMarkup(final Component child)
@@ -371,35 +337,39 @@ public abstract class Border extends Web
}
// Find <wicket:border>
- IMarkupFragment childMarkup = null;
+ IMarkupFragment borderMarkup = null;
for (int i = 0; i < markup.size(); i++)
{
MarkupElement elem = markup.get(i);
- if (elem instanceof WicketTag)
+ if (TagUtils.isWicketBorderTag(elem))
{
- WicketTag tag = (WicketTag)elem;
- if (tag.isBorderTag())
- {
- childMarkup = new MarkupFragment(markup, i);
- break;
- }
+ borderMarkup = new MarkupFragment(markup, i);
+ break;
}
}
+ if (borderMarkup == null)
+ {
+ throw new MarkupException(markup.getMarkupResourceStream(),
+ "Unable to find <wicket:border> tag in associated markup file for Border: " +
+ this.toString());
+ }
+
// If child == null, return the markup fragment starting with the <wicket:border> tag
if (child == null)
{
- return childMarkup;
+ return borderMarkup;
}
- // Since we created the body component instance, identifying that we found it is easy.
+ // Is child == BorderBody?
if (child == body)
{
+ // Get the <wicket:body> markup
return body.getMarkup();
}
// Find the markup for the child component
- childMarkup = childMarkup.find(child.getId());
+ IMarkupFragment childMarkup = borderMarkup.find(child.getId());
if (childMarkup != null)
{
return childMarkup;
@@ -415,9 +385,10 @@ public abstract class Border extends Web
{
private static final long serialVersionUID = 1L;
- /** remember the original status of the wicket:body tag */
- private transient boolean wasOpenCloseTag = false;
+ /** The markup */
+ private transient IMarkupFragment markup;
+ // properly resolve borders added to borders
protected boolean rendering;
/**
@@ -430,50 +401,40 @@ public abstract class Border extends Web
super(id);
}
- /**
- * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
- */
@Override
protected void onComponentTag(final ComponentTag tag)
{
// Convert open-close to open-body-close
- if (tag.getType() == TagType.OPEN_CLOSE)
+ if (tag.isOpenClose())
{
tag.setType(TagType.OPEN);
tag.setModified(true);
- wasOpenCloseTag = true;
}
super.onComponentTag(tag);
}
- /**
- * @see org.apache.wicket.MarkupContainer#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
- * org.apache.wicket.markup.ComponentTag)
- */
@Override
protected void onComponentTagBody(final MarkupStream markupStream,
final ComponentTag openTag)
{
- if (wasOpenCloseTag == false)
+ // skip the <wicket:body> body
+ if (markupStream.getPreviousTag().isOpen())
{
- // It is open-preview-close. Only RawMarkup is allowed within
- // the preview region, which gets stripped from output
+ // Only RawMarkup is allowed within the preview region,
+ // which gets stripped from output
markupStream.skipRawMarkup();
}
- // This check always results in false for normal requests.
- // In case of ajax requests, the markupstream is not reset after the first render, thus
- // the current index of the markup stream points to the element after the body.
- // As a result, no elements are detected and always omitted.
- originalMarkupStream.setCurrentIndex(beginOfBodyIndex);
+ // Get the <span wicket:id="myBorder"> markup and render that instead
+ IMarkupFragment markup = Border.this.getMarkup();
+ MarkupStream stream = new MarkupStream(markup);
+ ComponentTag tag = stream.getTag();
+ stream.next();
- super.onComponentTagBody(originalMarkupStream, Border.this.openTag);
+ super.onComponentTagBody(stream, tag);
}
- /**
- * @see org.apache.wicket.MarkupContainer#onRender()
- */
@Override
protected void onRender()
{
@@ -490,13 +451,15 @@ public abstract class Border extends Web
}
/**
- * @see org.apache.wicket.Component#getMarkup()
+ * Get the <wicket:body> markup from the body's parent container
*/
@Override
public IMarkupFragment getMarkup()
{
- IMarkupFragment markup = findByName(getParent().getMarkup(null), BODY);
- setMarkup(markup);
+ if (markup == null)
+ {
+ markup = findByName(getParent().getMarkup(null), BODY);
+ }
return markup;
}
@@ -525,13 +488,9 @@ public abstract class Border extends Web
ComponentTag tag = stream.getTag();
if (tag.isOpen() || tag.isOpenClose())
{
- if (tag instanceof WicketTag)
+ if (TagUtils.isWicketBodyTag(tag))
{
- WicketTag wtag = (WicketTag)tag;
- if (wtag.isBodyTag())
- {
- return stream.getMarkupFragment();
- }
+ return stream.getMarkupFragment();
}
}
@@ -542,7 +501,7 @@ public abstract class Border extends Web
}
/**
- * @see org.apache.wicket.MarkupContainer#getMarkup(org.apache.wicket.Component)
+ * Get the child markup which must be in between the <span wicktet:id="myBorder"> tags
*/
@Override
public IMarkupFragment getMarkup(final Component child)