Coverage Report - org.apache.tapestry.contrib.link.PopupLinkRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
PopupLinkRenderer
0%
0/28
0%
0/2
1.286
 
 1  
 // Copyright 2004, 2005 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.tapestry.contrib.link;
 16  
 
 17  
 import org.apache.hivemind.service.BodyBuilder;
 18  
 import org.apache.tapestry.IRequestCycle;
 19  
 import org.apache.tapestry.PageRenderSupport;
 20  
 import org.apache.tapestry.TapestryUtils;
 21  
 import org.apache.tapestry.components.ILinkComponent;
 22  
 import org.apache.tapestry.engine.ILink;
 23  
 import org.apache.tapestry.link.DefaultLinkRenderer;
 24  
 
 25  
 /**
 26  
  * This renderer emits javascript to launch the link in a window.
 27  
  * 
 28  
  * @author David Solis
 29  
  * @since 3.0.1
 30  
  */
 31  
 public class PopupLinkRenderer extends DefaultLinkRenderer
 32  
 {
 33  
 
 34  
     private String _windowName;
 35  
 
 36  
     private String _features;
 37  
 
 38  
     public PopupLinkRenderer()
 39  0
     {
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Initializes the name and features for javascript window.open function.
 44  
      * 
 45  
      * @param windowName
 46  
      *            the window name
 47  
      * @param features
 48  
      *            the window features
 49  
      */
 50  
     public PopupLinkRenderer(String windowName, String features)
 51  0
     {
 52  0
         _windowName = windowName;
 53  0
         _features = features;
 54  0
     }
 55  
 
 56  
     /**
 57  
      * @see DefaultLinkRenderer#constructURL(org.apache.tapestry.components.ILinkComponent,
 58  
      *      org.apache.tapestry.IRequestCycle)
 59  
      */
 60  
     protected String constructURL(ILinkComponent component, IRequestCycle cycle)
 61  
     {
 62  0
         if (cycle.isRewinding())
 63  
         {
 64  0
             return null;
 65  
         }
 66  
         
 67  0
         String anchor = component.getAnchor();
 68  0
         ILink link = component.getLink(cycle);
 69  
 
 70  0
         String url = link.getURL(anchor, true);
 71  
 
 72  0
         PageRenderSupport support = TapestryUtils.getPageRenderSupport(cycle, component);
 73  
 
 74  0
         String functionName = support.getUniqueString("popup_window");
 75  
 
 76  0
         BodyBuilder builder = new BodyBuilder();
 77  
 
 78  0
         builder.addln("{0}=function()", functionName);
 79  0
         builder.begin();
 80  0
         builder.add(
 81  
                 "var newWindow = window.open({0}, {1}, {2});",
 82  
                 TapestryUtils.enquote(url),
 83  
                 TapestryUtils.enquote(getWindowName()),
 84  
                 TapestryUtils.enquote(getFeatures()));
 85  0
         builder.add("newWindow.focus();");
 86  0
         builder.end();
 87  0
         builder.addln(";");
 88  
 
 89  0
         support.addBodyScript(component, builder.toString());
 90  
 
 91  0
         return "javascript:" + functionName + "();";
 92  
     }
 93  
 
 94  
     public String getWindowName()
 95  
     {
 96  0
         return _windowName;
 97  
     }
 98  
 
 99  
     public void setWindowName(String windowName)
 100  
     {
 101  0
         _windowName = windowName;
 102  0
     }
 103  
 
 104  
     public String getFeatures()
 105  
     {
 106  0
         return _features;
 107  
     }
 108  
 
 109  
     public void setFeatures(String features)
 110  
     {
 111  0
         _features = features;
 112  0
     }
 113  
 }