Author: ivaynberg
Date: Thu Sep 24 06:41:11 2009
New Revision: 818379

URL: http://svn.apache.org/viewvc?rev=818379&view=rev
Log:
WICKET-2485 IComponentResolvers are not supported inside wicket:enclosure
Issue: WICKET-2485

Added:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java
   (with props)
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java
   (with props)
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java
   (with props)
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
   (with props)
Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.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=818379&r1=818378&r2=818379&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 
Thu Sep 24 06:41:11 2009
@@ -31,7 +31,7 @@
 import org.apache.wicket.markup.MarkupNotFoundException;
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.WicketTag;
-import org.apache.wicket.markup.resolver.IComponentResolver;
+import org.apache.wicket.markup.resolver.ComponentResolvers;
 import org.apache.wicket.model.IComponentInheritedModel;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.IWrapModel;
@@ -1520,33 +1520,9 @@
                        }
                        else
                        {
-                               // 2rd try: Components like Border and Panel 
might implement
-                               // the ComponentResolver interface as well.
-                               MarkupContainer container = this;
-                               while (container != null)
+                               if 
(ComponentResolvers.resolve(getApplication(), this, markupStream, tag))
                                {
-                                       if (container instanceof 
IComponentResolver)
-                                       {
-                                               if 
(((IComponentResolver)container).resolve(this, markupStream, tag))
-                                               {
-                                                       return;
-                                               }
-                                       }
-
-                                       container = 
container.findParent(MarkupContainer.class);
-                               }
-
-                               // 3rd try: Try application's component 
resolvers
-                               final List<IComponentResolver> 
componentResolvers = getApplication().getPageSettings()
-                                       .getComponentResolvers();
-                               final Iterator<IComponentResolver> iterator = 
componentResolvers.iterator();
-                               while (iterator.hasNext())
-                               {
-                                       final IComponentResolver resolver = 
iterator.next();
-                                       if (resolver.resolve(this, 
markupStream, tag))
-                                       {
-                                               return;
-                                       }
+                                       return;
                                }
 
                                if (tag instanceof WicketTag)

Added: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java?rev=818379&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java
 (added)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java
 Thu Sep 24 06:41:11 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.internal;
+
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.html.WebComponent;
+
+/**
+ * An auto component that renders markup
+ * 
+ * @author igor.vaynberg
+ */
+class AutoMarkupLabel extends WebComponent
+{
+       private static final long serialVersionUID = 1L;
+       private final CharSequence markup;
+
+       /**
+        * Constructor
+        * 
+        * @param id
+        * @param markup
+        */
+       public AutoMarkupLabel(String id, CharSequence markup)
+       {
+               super(id);
+               this.markup = markup;
+               setAuto(true);
+       }
+
+       /** {...@inheritdoc} */
+       @Override
+       protected void onComponentTagBody(MarkupStream markupStream, 
ComponentTag openTag)
+       {
+               replaceComponentTagBody(markupStream, openTag, markup);
+       }
+
+}
\ No newline at end of file

Propchange: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/AutoMarkupLabel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java?rev=818379&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java
 (added)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java
 Thu Sep 24 06:41:11 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.internal;
+
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.util.collections.ReadOnlyIterator;
+
+/**
+ * Iterator that iterates over direct child component tags of the given 
component tag
+ */
+class DirectChildTagIterator extends ReadOnlyIterator<ComponentTag>
+{
+       private final MarkupStream markupStream;
+       private final ComponentTag parent;
+       private ComponentTag next = null;
+       private int nextIndex;
+       private int currentIndex;
+       private final int originalIndex;
+
+       /**
+        * Construct.
+        * 
+        * @param markupStream
+        * @param parent
+        */
+       public DirectChildTagIterator(MarkupStream markupStream, ComponentTag 
parent)
+       {
+               super();
+               this.markupStream = markupStream;
+               this.parent = parent;
+               originalIndex = markupStream.getCurrentIndex();
+               findNext();
+       }
+
+       /**
+        * Resets markup stream to the original position
+        */
+       public void rewind()
+       {
+               markupStream.setCurrentIndex(originalIndex);
+       }
+
+       /**
+        * @see java.util.Iterator#hasNext()
+        */
+       public boolean hasNext()
+       {
+               return next != null;
+       }
+
+       /**
+        * @see java.util.Iterator#next()
+        */
+       public ComponentTag next()
+       {
+               ComponentTag ret = next;
+               currentIndex = nextIndex;
+               findNext();
+               return ret;
+       }
+
+       /**
+        * Gets currentIndex.
+        * 
+        * @return currentIndex
+        */
+       public int getCurrentIndex()
+       {
+               return currentIndex;
+       }
+
+       private void findNext()
+       {
+               ComponentTag tag = next;
+               next = null;
+
+               if (tag != null && tag.isOpenClose())
+               {
+                       // if current child tag is open-close look for next 
child
+                       tag = null;
+               }
+
+               while (markupStream.hasMore())
+               {
+                       final MarkupElement cursor = markupStream.next();
+
+                       if (cursor.closes(parent))
+                       {
+                               // parent close tag found, we are done
+                               break;
+                       }
+
+                       if (tag != null && cursor.closes(tag))
+                       {
+                               // child tag is closed, next tag is either 
parent-close or next direct child
+                               tag = null;
+                       }
+                       else if (tag == null && cursor instanceof ComponentTag)
+                       {
+                               // found next child
+                               next = (ComponentTag)cursor;
+                               nextIndex = markupStream.getCurrentIndex();
+                               break;
+                       }
+               }
+       }
+}
\ No newline at end of file

Propchange: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/DirectChildTagIterator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java?rev=818379&r1=818378&r2=818379&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/Enclosure.java
 Thu Sep 24 06:41:11 2009
@@ -23,17 +23,13 @@
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.WicketRuntimeException;
 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.WebMarkupContainer;
 import org.apache.wicket.markup.html.border.Border;
 import org.apache.wicket.markup.html.border.Border.BorderBodyContainer;
 import org.apache.wicket.markup.parser.filter.EnclosureHandler;
-import org.apache.wicket.util.collections.ReadOnlyIterator;
+import org.apache.wicket.markup.resolver.ComponentResolvers;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -89,7 +85,7 @@
        /** Id of the child component that will control visibility of the 
enclosure */
        private final CharSequence childId;
 
-       private transient Map<Component, Boolean> originalVisibilityStatus;
+       private transient Map<Component, Boolean> changes;
 
        /**
         * Construct.
@@ -100,6 +96,14 @@
        public Enclosure(final String id, final CharSequence childId)
        {
                super(id);
+
+
+               if (childId == null)
+               {
+                       throw new MarkupException(
+                               "You most likely forgot to register the 
EnclosureHandler with the MarkupParserFactory");
+               }
+
                this.childId = childId;
        }
 
@@ -114,35 +118,6 @@
        }
 
        /**
-        * 
-        * @param childId
-        * @return Child Component
-        */
-       public Component getChildComponent()
-       {
-               if (childComponent == null)
-               {
-                       MarkupContainer parent = getEnclosureParent();
-
-                       if (childId == null)
-                       {
-                               throw new MarkupException(
-                                       "You most likely forgot to register the 
EnclosureHandler with the MarkupParserFactory");
-                       }
-
-                       final Component child = parent.get(childId.toString());
-                       if (child == null)
-                       {
-                               throw new MarkupException(
-                                       "Didn't find child component of 
<wicket:enclosure> with id='" + childId +
-                                               "'. Component: " + 
this.toString());
-                       }
-                       childComponent = child;
-               }
-               return childComponent;
-       }
-
-       /**
         * Get the real parent container
         * 
         * @return enclosure's parent markup container
@@ -180,225 +155,131 @@
         *      org.apache.wicket.markup.ComponentTag)
         */
        @Override
-       protected void onComponentTagBody(MarkupStream markupStream, 
ComponentTag openTag)
+       protected void onComponentTagBody(final MarkupStream markupStream, 
ComponentTag enclosureOpenTag)
        {
-               final Component controller = getChildComponent();
-               if (controller == this)
-               {
-                       throw new WicketRuntimeException(
-                               "Programming error: childComponent == enclose 
component; endless loop");
-               }
+               // init changes map
+               changes = new HashMap<Component, Boolean>();
+
+               // enclosure's parent container
+               final MarkupContainer container = getEnclosureParent();
+
+               // iterate over all child tags and make sure all components are 
present, resolving them if
+               // necessary
+               ensureAllChildrenPresent(container, markupStream, 
enclosureOpenTag);
 
+               Component controller = container.get(childId.toString());
+               checkChildComponent(controller);
+
+               // set the enclosure visibility
                setVisible(controller.determineVisibility());
 
                // transfer visibility to direct children
-               originalVisibilityStatus = new HashMap<Component, Boolean>();
-               DirectChildTagIterator it = new 
DirectChildTagIterator(markupStream, openTag);
-               MarkupContainer controllerParent = getEnclosureParent();
-               while (it.hasNext())
-               {
-                       ComponentTag t = it.next();
-                       Component child = controllerParent.get(t.getId());
-                       if (child != null)
-                       {
-                               // record original visiblity allowed value, 
will restore later
-                               originalVisibilityStatus.put(child, 
child.isVisibilityAllowed());
-                               child.setVisibilityAllowed(isVisible());
-
-                       }
-               }
-               it.rewind();
+               applyEnclosureVisibilityToChildren(container, markupStream, 
enclosureOpenTag);
 
+               // render components inside the enclosure if its visible or 
skip it if it is not
                if (isVisible() == true)
                {
-                       super.onComponentTagBody(markupStream, openTag);
+                       super.onComponentTagBody(markupStream, 
enclosureOpenTag);
                }
                else
                {
-                       markupStream.skipToMatchingCloseTag(openTag);
+                       markupStream.skipToMatchingCloseTag(enclosureOpenTag);
                }
        }
 
-       @Override
-       protected void onDetach()
+       private void applyEnclosureVisibilityToChildren(final MarkupContainer 
container,
+               final MarkupStream markupStream, ComponentTag enclosureOpenTag)
        {
-               if (originalVisibilityStatus != null)
+               DirectChildTagIterator it = new 
DirectChildTagIterator(markupStream, enclosureOpenTag);
+               while (it.hasNext())
                {
-                       // restore original visibility statuses
-                       for (Map.Entry<Component, Boolean> entry : 
originalVisibilityStatus.entrySet())
-                       {
-                               
entry.getKey().setVisibilityAllowed(entry.getValue());
-                       }
-                       originalVisibilityStatus = null;
+                       final ComponentTag tag = it.next();
+                       final Component child = container.get(tag.getId());
+                       // record original visiblity allowed value, will 
restore later
+                       changes.put(child, child.isVisibilityAllowed());
+                       child.setVisibilityAllowed(isVisible());
                }
-               super.onDetach();
+               it.rewind();
        }
 
-       /**
-        * @see org.apache.wicket.Component#getMarkup()
-        */
-       @Override
-       public IMarkupFragment getMarkup()
+       private void checkChildComponent(Component controller)
        {
-               // Get the associated markup file
-               MarkupContainer parent = getParent();
-               IMarkupFragment markup = parent.getMarkup();
-               if ((markup != null) && (markup instanceof MarkupFragment))
+               if (controller == null)
                {
-                       markup = ((MarkupFragment)markup).getRootMarkup();
+                       throw new WicketRuntimeException("Could not find child 
with id: " + childId +
+                               " in the wicket:enclosure");
                }
-
-               // Find the enclosure tag
-               markup = findEnclosureMarkup(markup);
-               if (markup != null)
-               {
-                       return markup;
-               }
-
-               markup = parent.getMarkup(null);
-               if ((markup != null) && (markup instanceof MarkupFragment))
+               else if (controller == this)
                {
-                       markup = ((MarkupFragment)markup).getRootMarkup();
-               }
-
-               // Find the enclosure tag
-               markup = findEnclosureMarkup(markup);
-               if (markup != null)
-               {
-                       return markup;
-               }
-
-               // In case of BorderBody the enclosure markup is expected to be 
in between the
-               // <span wicket:id="myBorder">...</span> tags.
-               if (parent instanceof BorderBodyContainer)
-               {
-                       // Find the Border component
-                       while (((parent instanceof Border) == false) && (parent 
!= null))
-                       {
-                               parent = parent.getParent();
-                       }
-
-                       // Get the borders "calling" markup and find the 
enclosure tag
-                       markup = parent.getMarkup();
-                       return findEnclosureMarkup(markup);
+                       throw new WicketRuntimeException(
+                               "Programming error: childComponent == enclose 
component; endless loop");
                }
-               return null;
        }
 
-       /**
-        * Find the enclose tag
-        * 
-        * @param markup
-        * @return Null, if not found
-        */
-       private IMarkupFragment findEnclosureMarkup(IMarkupFragment markup)
+       private void ensureAllChildrenPresent(final MarkupContainer container,
+               final MarkupStream markupStream, ComponentTag enclosureOpenTag)
        {
-               for (int i = 0; i < markup.size(); i++)
+               DirectChildTagIterator it = new 
DirectChildTagIterator(markupStream, enclosureOpenTag);
+               while (it.hasNext())
                {
-                       MarkupElement elem = markup.get(i);
-                       if (elem instanceof WicketTag)
+                       final ComponentTag tag = it.next();
+
+                       Component child = container.get(tag.getId());
+                       if (child == null)
                        {
-                               WicketTag tag = (WicketTag)elem;
-                               if (tag.isEnclosureTag())
+                               // component does not yet exist in the 
container, attempt to resolve it using
+                               // resolvers
+                               final int tagIndex = it.getCurrentIndex();
+
+                               // because the resolvers can auto-add and 
therefore immediately render the component
+                               // we have to buffer the output since we do not 
yet know the visibility of the
+                               // enclosure
+                               CharSequence buffer = new 
ResponseBufferZone(getRequestCycle(), markupStream)
                                {
-                                       if ("_enclosure".equals(tag.getId()) || 
getId().equals(tag.getId()))
+                                       @Override
+                                       protected void 
executeInsideBufferedZone()
                                        {
-                                               if 
(childId.equals(tag.getAttribute(EnclosureHandler.CHILD_ATTRIBUTE)))
-                                               {
-                                                       return new 
MarkupFragment(markup, i);
-                                               }
+                                               
markupStream.setCurrentIndex(tagIndex);
+                                               
ComponentResolvers.resolve(getApplication(), container, markupStream, tag);
                                        }
+                               }.execute();
+
+                               child = container.get(tag.getId());
+                               checkChildComponent(child);
+
+                               if (buffer.length() > 0)
+                               {
+                                       // we have already rendered this child 
component, insert a stub component that
+                                       // will dump the markup during the 
normal render process if the enclosure is
+                                       // visible
+                                       final Component stub = new 
AutoMarkupLabel(child.getId(), buffer);
+                                       container.replace(stub); // ok here 
because we are replacing auto with auto
                                }
                        }
                }
-               return null;
+               it.rewind();
        }
 
-       /**
-        * Iterator that iterates over direct child component tags of the given 
component tag
-        * 
-        */
-       private static class DirectChildTagIterator extends 
ReadOnlyIterator<ComponentTag>
-       {
-               private final MarkupStream markupStream;
-               private final ComponentTag parent;
-               private ComponentTag next = null;
-               private final int originalIndex;
-
-               /**
-                * Construct.
-                * 
-                * @param markupStream
-                * @param parent
-                */
-               public DirectChildTagIterator(MarkupStream markupStream, 
ComponentTag parent)
-               {
-                       super();
-                       this.markupStream = markupStream;
-                       this.parent = parent;
-                       originalIndex = markupStream.getCurrentIndex();
-                       findNext();
-               }
 
-               /**
-                * Resets markup stream to the original position
-                */
-               public void rewind()
-               {
-                       markupStream.setCurrentIndex(originalIndex);
-               }
-
-               /**
-                * @see java.util.Iterator#hasNext()
-                */
-               public boolean hasNext()
-               {
-                       return next != null;
-               }
-
-               /**
-                * @see java.util.Iterator#next()
-                */
-               public ComponentTag next()
-               {
-                       ComponentTag ret = next;
-                       findNext();
-                       return ret;
-               }
+       @Override
+       protected void onDetach()
+       {
+               restoreOriginalChildVisibility();
+               super.onDetach();
+       }
 
-               private void findNext()
+       private void restoreOriginalChildVisibility()
+       {
+               if (changes != null)
                {
-                       ComponentTag tag = next;
-                       next = null;
+                       MarkupContainer container = getEnclosureParent();
 
-                       if (tag != null && tag.isOpenClose())
-                       {
-                               // if current child tag is open-close look for 
next child
-                               tag = null;
-                       }
-
-                       while (markupStream.hasMore())
+                       // restore original visibility statuses
+                       for (Map.Entry<Component, Boolean> entry : 
changes.entrySet())
                        {
-                               final MarkupElement cursor = 
markupStream.next();
-
-                               if (cursor.closes(parent))
-                               {
-                                       // parent close tag found, we are done
-                                       break;
-                               }
-
-                               if (tag != null && cursor.closes(tag))
-                               {
-                                       // child tag is closed, next tag is 
either parent-close or next direct child
-                                       tag = null;
-                               }
-                               else if (tag == null && cursor instanceof 
ComponentTag)
-                               {
-                                       // found next child
-                                       next = (ComponentTag)cursor;
-                                       break;
-                               }
+                               
entry.getKey().setVisibilityAllowed(entry.getValue());
                        }
+                       changes = null;
                }
        }
 }

Added: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java?rev=818379&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java
 (added)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java
 Thu Sep 24 06:41:11 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.internal;
+
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.Response;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.response.StringResponse;
+
+/**
+ * Utility class that buffers output and maintains markup stream index
+ * 
+ * @author igor.vaynberg
+ */
+abstract class ResponseBufferZone
+{
+       private final RequestCycle cycle;
+       private final MarkupStream stream;
+
+       public ResponseBufferZone(RequestCycle cycle, MarkupStream stream)
+       {
+               this.cycle = cycle;
+               this.stream = stream;
+       }
+
+       public CharSequence execute()
+       {
+               final int originalStreamPos = stream.getCurrentIndex();
+
+               final Response original = cycle.getResponse();
+
+               final StringResponse buffer = new StringResponse();
+               cycle.setResponse(buffer);
+               try
+               {
+                       executeInsideBufferedZone();
+                       return buffer.getBuffer();
+               }
+               finally
+               {
+                       cycle.setResponse(original);
+                       stream.setCurrentIndex(originalStreamPos);
+               }
+       }
+
+       protected abstract void executeInsideBufferedZone();
+}

Propchange: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/ResponseBufferZone.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java?rev=818379&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
 (added)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
 Thu Sep 24 06:41:11 2009
@@ -0,0 +1,90 @@
+/*
+ * 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 java.util.Iterator;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupStream;
+
+/**
+ * Utility class for {...@link IComponentResolver}s
+ * 
+ * @author igor.vaynberg
+ */
+public class ComponentResolvers
+{
+       private ComponentResolvers()
+       {
+
+       }
+
+       /**
+        * Attempts to resolve a component using resolvers. Tries resolvers in 
the component hierarchy
+        * as well as application-wide.
+        * <p>
+        * This method encapsulates the contract of resolving components and 
should be used any time a
+        * component needs to be resolved under normal circumstances.
+        * </p>
+        * 
+        * @param application
+        * @param container
+        * @param markupStream
+        * @param tag
+        * @return <code>true</code> if a component was resolved using on of 
tried resolvers,
+        *         <code>false</code> otherwise.
+        */
+       public static boolean resolve(final Application application, final 
MarkupContainer container,
+               MarkupStream markupStream, ComponentTag tag)
+       {
+
+               // try to resolve using component hierarchy
+
+               Component cursor = container;
+               while (cursor != null)
+               {
+                       if (cursor instanceof IComponentResolver)
+                       {
+                               if 
(((IComponentResolver)cursor).resolve(container, markupStream, tag))
+                               {
+                                       return true;
+                               }
+                       }
+                       cursor = cursor.findParent(MarkupContainer.class);
+               }
+
+               // fallback to application-level resolvers
+
+               Iterator<IComponentResolver> resolvers = 
application.getPageSettings()
+                       .getComponentResolvers()
+                       .iterator();
+               while (resolvers.hasNext())
+               {
+                       IComponentResolver resolver = resolvers.next();
+                       if (resolver.resolve(container, markupStream, tag))
+                       {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+}

Propchange: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/resolver/ComponentResolvers.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to