Coverage Report - org.apache.tapestry5.services.ajax.SingleZonePartialRendererFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
SingleZonePartialRendererFilter
100%
11/11
N/A
1
SingleZonePartialRendererFilter$1
100%
5/5
N/A
1
SingleZonePartialRendererFilter$1$1
100%
6/6
N/A
1
 
 1  
 // Copyright 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.services.ajax;
 16  
 
 17  
 import org.apache.tapestry5.MarkupWriter;
 18  
 import org.apache.tapestry5.dom.Element;
 19  
 import org.apache.tapestry5.internal.services.PageRenderQueue;
 20  
 import org.apache.tapestry5.json.JSONObject;
 21  
 import org.apache.tapestry5.runtime.RenderCommand;
 22  
 import org.apache.tapestry5.runtime.RenderQueue;
 23  
 import org.apache.tapestry5.services.PartialMarkupRenderer;
 24  
 import org.apache.tapestry5.services.PartialMarkupRendererFilter;
 25  
 
 26  
 /**
 27  
  * Responsible for capturing the content for a single zone and storing it into the JSON reply object.
 28  
  *
 29  
  * @see org.apache.tapestry5.ajax.MultiZoneUpdate
 30  
  * @since 5.1.0.1
 31  
  */
 32  18
 public class SingleZonePartialRendererFilter implements PartialMarkupRendererFilter
 33  
 {
 34  
     private final String zoneId;
 35  
 
 36  
     private final RenderCommand zoneRenderCommand;
 37  
 
 38  
     private final PageRenderQueue queue;
 39  
 
 40  
     public SingleZonePartialRendererFilter(String zoneId, RenderCommand zoneRenderCommand, PageRenderQueue queue)
 41  6
     {
 42  6
         this.zoneId = zoneId;
 43  6
         this.zoneRenderCommand = zoneRenderCommand;
 44  6
         this.queue = queue;
 45  6
     }
 46  
 
 47  
     public void renderMarkup(MarkupWriter writer, final JSONObject reply, PartialMarkupRenderer renderer)
 48  
     {
 49  6
         RenderCommand forZone = new RenderCommand()
 50  
         {
 51  6
             public void render(MarkupWriter writer, RenderQueue queue)
 52  
             {
 53  
                 // Create an element to contain the content for the zone. We give it a menumonic
 54  
                 // element name and attribute just to help with debugging (the element itself is discarded).
 55  
 
 56  6
                 final Element zoneContainer = writer.element("zone-update", "zoneId", zoneId);
 57  
 
 58  6
                 queue.push(new RenderCommand()
 59  
                 {
 60  6
                     public void render(MarkupWriter writer, RenderQueue queue)
 61  
                     {
 62  6
                         writer.end(); // the zoneContainer element
 63  
 
 64  6
                         String zoneUpdateContent = zoneContainer.getChildMarkup();
 65  
 
 66  6
                         zoneContainer.remove();
 67  
 
 68  6
                         reply.getJSONObject("zones").put(zoneId, zoneUpdateContent);
 69  6
                     }
 70  
                 });
 71  
 
 72  
                 // Make sure the zone's actual rendering command is processed first, then the inline
 73  
                 // RenderCommand just above.
 74  
 
 75  6
                 queue.push(zoneRenderCommand);
 76  6
             }
 77  
         };
 78  
 
 79  6
         RenderCommand existing = queue.getRootRenderCommand();
 80  
 
 81  6
         queue.initializeForPartialPageRender(new CombinedRenderCommand(existing, forZone));
 82  
 
 83  6
         renderer.renderMarkup(writer, reply);
 84  6
     }
 85  
 }