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