Author: jdonnerstag
Date: Sun Jan  3 22:54:38 2010
New Revision: 895503

URL: http://svn.apache.org/viewvc?rev=895503&view=rev
Log:
wip on onMarkupAttached

Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.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/panel/Fragment.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html

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=895503&r1=895502&r2=895503&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 Jan  
3 22:54:38 2010
@@ -2533,9 +2533,10 @@
                try
                {
                        // Render open tag
+                       boolean tagRendered = false;
                        if (getRenderBodyOnly() == false)
                        {
-                               renderComponentTag(tag);
+                               tagRendered = renderComponentTag(tag);
                        }
                        markupStream.next();
 
@@ -2544,25 +2545,17 @@
                        {
                                // Render the body
                                onComponentTagBody(markupStream, tag);
-                       }
 
-                       // Render close tag
-                       if (tag.isOpen())
-                       {
-                               if (openTag.isOpen())
+                               // Render close tag
+                               if ((tag.hasNoCloseTag() == false) && 
tagRendered)
                                {
-                                       renderClosingComponentTag(markupStream, 
tag, getRenderBodyOnly());
-                               }
-                               else if (getRenderBodyOnly() == false)
-                               {
-                                       if (needToRenderTag(openTag))
-                                       {
-                                               // Close the manually opened 
tag. And since the user might have changed the
-                                               // tag name ...
-                                               
getResponse().write(tag.syntheticCloseTagString());
-                                       }
+                                       // Close the tag.
+                                       
getResponse().write(tag.syntheticCloseTagString());
                                }
                        }
+
+                       // make sure we moved the cursor to the end.
+                       markupStream.next();
                }
                catch (RuntimeException re)
                {
@@ -3821,8 +3814,9 @@
         * 
         * @param tag
         *            The tag to write
+        * @return true, if tag was rendered
         */
-       protected final void renderComponentTag(ComponentTag tag)
+       protected final boolean renderComponentTag(ComponentTag tag)
        {
                if (needToRenderTag(tag))
                {
@@ -3861,7 +3855,11 @@
                        // Write the tag
                        tag.writeOutput(getResponse(), !needToRenderTag(null),
                                
getMarkup().getMarkupResourceStream().getWicketNamespace());
+
+                       return true;
                }
+
+               return false;
        }
 
        /**

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=895503&r1=895502&r2=895503&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 
Sun Jan  3 22:54:38 2010
@@ -33,7 +33,6 @@
 import org.apache.wicket.markup.MarkupType;
 import org.apache.wicket.markup.RawMarkup;
 import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.html.HeaderPartContainer;
 import org.apache.wicket.markup.resolver.ComponentResolvers;
 import org.apache.wicket.model.IComponentInheritedModel;
 import org.apache.wicket.model.IModel;
@@ -319,7 +318,7 @@
         * @return The component at the path
         */
        @Override
-       public Component get(final String path)
+       public final Component get(final String path)
        {
                // Reference to this container
                if (path == null || path.trim().equals(""))

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
 Sun Jan  3 22:54:38 2010
@@ -19,18 +19,21 @@
 import org.apache.wicket.Component;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.MarkupNotFoundException;
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.TagUtils;
 import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.lang.Checks;
 
 /**
  * WebMarkupContainer with it's own markup and possibly <wicket:head> tag.
  * 
  * @author Juergen Donnerstag
  */
-public class WebMarkupContainerWithAssociatedMarkup extends WebMarkupContainer
+public abstract class WebMarkupContainerWithAssociatedMarkup extends 
WebMarkupContainer
 {
        private static final long serialVersionUID = 1L;
 
@@ -125,4 +128,81 @@
 
                return childMarkup;
        }
+
+       /**
+        * Convenience method for subclasses to call. It is exactly like you 
would implement
+        * getMarkup(child) in your subclass. The only difference is, you need 
to provide the name of
+        * tag, such as 'panel' in &lt;wicket:panel&gt;
+        * 
+        * @param tagName
+        * @param child
+        * @return the markup fragment for the child
+        */
+       public final IMarkupFragment getMarkup(final String tagName, final 
Component child)
+       {
+               Checks.argumentNotEmpty(tagName, "tagName");
+
+               // get the associated markup resource file
+               IMarkupFragment markup = getAssociatedMarkup();
+               if (markup == null)
+               {
+                       throw new MarkupException("Unable to find associated 
markup file for: " +
+                               this.toString());
+               }
+
+               // Find <wicket:'name'>
+               IMarkupFragment panelMarkup = findTag(markup, tagName);
+               if (panelMarkup == null)
+               {
+                       throw new MarkupNotFoundException("Expected to find 
<wicket:" + tagName +
+                               "> in associated markup file. Markup: " + 
markup.toString());
+               }
+
+               // If child == null, return the markup fragment starting with 
the <wicket:border> tag
+               if (child == null)
+               {
+                       return panelMarkup;
+               }
+
+               // Find the markup for the child component
+               panelMarkup = panelMarkup.find(child.getId());
+               if (panelMarkup != null)
+               {
+                       return panelMarkup;
+               }
+
+               return findMarkupInAssociatedFileHeader(markup, child);
+       }
+
+       /**
+        * Search for &lt;wicket:panel ...&gt; on the same level.
+        * 
+        * @param markup
+        * @param name
+        * @return null, if not found
+        */
+       private final IMarkupFragment findTag(final IMarkupFragment markup, 
final String name)
+       {
+               MarkupStream stream = new MarkupStream(markup);
+
+               while (stream.skipUntil(ComponentTag.class))
+               {
+                       ComponentTag tag = stream.getTag();
+                       if (tag.isOpen() || tag.isOpenClose())
+                       {
+                               if (tag instanceof WicketTag)
+                               {
+                                       if 
(tag.getName().equalsIgnoreCase(name))
+                                       {
+                                               return 
stream.getMarkupFragment();
+                                       }
+                               }
+                               stream.skipToMatchingCloseTag(tag);
+                       }
+
+                       stream.next();
+               }
+
+               return null;
+       }
 }
\ 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=895503&r1=895502&r2=895503&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 Jan  3 22:54:38 2010
@@ -22,9 +22,6 @@
 import org.apache.wicket.behavior.IBehavior;
 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.MarkupFragment;
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
@@ -362,50 +359,13 @@
        @Override
        public IMarkupFragment getMarkup(final Component child)
        {
-               // Border require an associated markup resource file
-               IMarkupFragment markup = getAssociatedMarkup();
-               if (markup == null)
-               {
-                       throw new MarkupException("Unable to find associated 
markup file for Border: " +
-                               this.toString());
-               }
-
-               // Find <wicket:border>
-               IMarkupFragment childMarkup = null;
-               for (int i = 0; i < markup.size(); i++)
-               {
-                       MarkupElement elem = markup.get(i);
-                       if (elem instanceof WicketTag)
-                       {
-                               WicketTag tag = (WicketTag)elem;
-                               if (tag.isBorderTag())
-                               {
-                                       childMarkup = new 
MarkupFragment(markup, i);
-                                       break;
-                               }
-                       }
-               }
-
-               // If child == null, return the markup fragment starting with 
the <wicket:border> tag
-               if (child == null)
-               {
-                       return childMarkup;
-               }
-
                // Since we created the body component instance, identifying 
that we found it is easy.
-               if (child == body)
+               if ((child != null) && (child == body))
                {
                        return body.getMarkup();
                }
 
-               // Find the markup for the child component
-               childMarkup = childMarkup.find(child.getId());
-               if (childMarkup != null)
-               {
-                       return childMarkup;
-               }
-
-               return findMarkupInAssociatedFileHeader(markup, child);
+               return getMarkup(BORDER, child);
        }
 
        /**

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=895503&r1=895502&r2=895503&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
 Sun Jan  3 22:54:38 2010
@@ -24,7 +24,7 @@
 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;
@@ -52,7 +52,7 @@
  * 
  * @author Juergen Donnerstag
  */
-public class Fragment extends WebMarkupContainerWithAssociatedMarkup
+public class Fragment extends WebMarkupContainer
 {
        private static final long serialVersionUID = 1L;
 
@@ -148,12 +148,6 @@
        @Override
        protected void onComponentTagBody(final MarkupStream markupStream, 
final ComponentTag openTag)
        {
-               // Skip the components body. It will be replaced by the fragment
-               if 
(((ComponentTag)markupStream.get(markupStream.getCurrentIndex() - 1)).isOpen())
-               {
-                       markupStream.skipRawMarkup();
-               }
-
                final MarkupStream providerMarkupStream = 
chooseMarkupStream(markupStream);
                if (providerMarkupStream == null)
                {

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
 Sun Jan  3 22:54:38 2010
@@ -19,10 +19,7 @@
 import org.apache.wicket.Component;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.IMarkupFragment;
-import org.apache.wicket.markup.MarkupException;
-import org.apache.wicket.markup.MarkupNotFoundException;
 import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
 import org.apache.wicket.markup.parser.XmlTag;
 import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
@@ -119,17 +116,6 @@
                // Render the associated markup
                renderAssociatedMarkup(PANEL,
                        "Markup for a panel component has to contain part 
'<wicket:panel>'");
-
-               if (wasOpenCloseTag == false)
-               {
-                       // Skip any raw markup in the body
-                       markupStream.skipRawMarkup();
-                       if (markupStream.get().closes(openTag) == false)
-                       {
-                               throw new MarkupException("close tag not found 
for tag: " + openTag.toString() +
-                                       ". Component: " + this.toString());
-                       }
-               }
        }
 
        /**
@@ -138,68 +124,6 @@
        @Override
        public IMarkupFragment getMarkup(final Component child)
        {
-               IMarkupFragment markup = getAssociatedMarkup();
-               if (markup == null)
-               {
-                       throw new MarkupNotFoundException(
-                               "Failed to find markup file associated with 
panel. Panel: " + this.toString());
-               }
-
-               // Find <wicket:panel>
-               IMarkupFragment panelMarkup = findPanelTag(markup);
-               if (panelMarkup == null)
-               {
-                       throw new MarkupNotFoundException(
-                               "Expected to find <wicket:panel> in associated 
markup file. Markup: " +
-                                       markup.toString());
-               }
-
-               // If child == null, than return the markup fragment starting 
with <wicket:panel>
-               if (child == null)
-               {
-                       return panelMarkup;
-               }
-
-               // Find the markup for the child component
-               IMarkupFragment childMarkup = panelMarkup.find(child.getId());
-               if (childMarkup != null)
-               {
-                       return childMarkup;
-               }
-
-               return findMarkupInAssociatedFileHeader(markup, child);
-       }
-
-       /**
-        * Search for &lt;wicket:panel ...&gt; on the same level.
-        * 
-        * @param markup
-        * @param name
-        * @return null, if not found
-        */
-       private final IMarkupFragment findPanelTag(final IMarkupFragment markup)
-       {
-               MarkupStream stream = new MarkupStream(markup);
-
-               while (stream.skipUntil(ComponentTag.class))
-               {
-                       ComponentTag tag = stream.getTag();
-                       if (tag.isOpen() || tag.isOpenClose())
-                       {
-                               if (tag instanceof WicketTag)
-                               {
-                                       WicketTag wtag = (WicketTag)tag;
-                                       if (wtag.isPanelTag())
-                                       {
-                                               return 
stream.getMarkupFragment();
-                                       }
-                               }
-                               stream.skipToMatchingCloseTag(tag);
-                       }
-
-                       stream.next();
-               }
-
-               return null;
+               return getMarkup(PANEL, child);
        }
 }

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
 Sun Jan  3 22:54:38 2010
@@ -4,7 +4,7 @@
     <!--  In addition test that chars are not converted from upper to lower 
and vice versa -->
        <FORM wicket:id="form">
                <span wicket:id="group">
-                       <Input type="checkbox" wicket:id="check1">check1</input>
+                       <input type="checkbox" wicket:id="check1">check1</input>
                        <span wicket:id="container">
                                <input type="checkbox" 
wicket:id="check2">check2</input>
                        </span>

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
 Sun Jan  3 22:54:38 2010
@@ -4,7 +4,7 @@
     <!--  In addition test that chars are not converted from upper to lower 
and vice versa -->
        <FORM wicket:id="form" id="form4" method="post" 
action="?wicket:interface=:0:form::IFormSubmitListener::"><div 
style="display:none"><input type="hidden" name="form4_hf_0" id="form4_hf_0" 
/></div>
                <span wicket:id="group">
-                       <Input type="checkbox" wicket:id="check1" 
id="group1-check12" name="group" value="check1" checked="checked" 
disabled="disabled">check1</input>
+                       <input type="checkbox" wicket:id="check1" 
id="group1-check12" name="group" value="check1" checked="checked" 
disabled="disabled">check1</input>
                        <span wicket:id="container">
                                <input type="checkbox" wicket:id="check2" 
id="group1-check23" name="group" value="check2" checked="checked" 
disabled="disabled">check2</input>
                        </span>

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
 Sun Jan  3 22:54:38 2010
@@ -4,7 +4,7 @@
     <!--  In addition test that chars are not converted from upper to lower 
and vice versa -->
        <FORM wicket:id="form">
                <span wicket:id="group">
-                       <Input type="checkbox" wicket:id="check1">check1</input>
+                       <input type="checkbox" wicket:id="check1">check1</input>
                        <span wicket:id="container">
                                <input type="checkbox" 
wicket:id="check2">check2</input>
                        </span>

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html?rev=895503&r1=895502&r2=895503&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
 Sun Jan  3 22:54:38 2010
@@ -4,7 +4,7 @@
     <!--  In addition test that chars are not converted from upper to lower 
and vice versa -->
        <FORM wicket:id="form" id="form4" method="post" 
action="?wicket:interface=:0:form::IFormSubmitListener::"><div 
style="display:none"><input type="hidden" name="form4_hf_0" id="form4_hf_0" 
/></div>
                
-                       <Input type="checkbox" wicket:id="check1" 
id="group1-check12" name="group" value="check1">check1</input>
+                       <input type="checkbox" wicket:id="check1" 
id="group1-check12" name="group" value="check1">check1</input>
                        <span wicket:id="container">
                                <input type="checkbox" wicket:id="check2" 
id="group1-check23" name="group" value="check2">check2</input>
                        </span>


Reply via email to