Clover coverage report - Code Coverage for tapestry release 4.0-beta-8
Coverage timestamp: Sat Sep 24 2005 11:50:34 EDT
file stats: LOC: 160   Methods: 3
NCLOC: 87   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Rollover.java 0% 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.html;
 16   
 17    import java.util.HashMap;
 18    import java.util.Map;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.tapestry.AbstractComponent;
 22    import org.apache.tapestry.IAsset;
 23    import org.apache.tapestry.IMarkupWriter;
 24    import org.apache.tapestry.IRequestCycle;
 25    import org.apache.tapestry.IScript;
 26    import org.apache.tapestry.PageRenderSupport;
 27    import org.apache.tapestry.Tapestry;
 28    import org.apache.tapestry.TapestryUtils;
 29    import org.apache.tapestry.components.ILinkComponent;
 30    import org.apache.tapestry.components.LinkEventType;
 31   
 32    /**
 33    * Combines a link component (such as {@link org.apache.tapestry.link.DirectLink}) with an
 34    * <img> and JavaScript code to create a rollover effect that works with both Netscape
 35    * Navigator and Internet Explorer. [ <a
 36    * href="../../../../../ComponentReference/Rollover.html">Component Reference </a>]
 37    *
 38    * @author Howard Lewis Ship
 39    */
 40   
 41    public abstract class Rollover extends AbstractComponent
 42    {
 43    /**
 44    * Converts an {@link IAsset}binding into a usable URL. Returns null if the binding does not
 45    * exist or the binding's value is null.
 46    */
 47   
 48  0 protected String getAssetURL(IAsset asset, IRequestCycle cycle)
 49    {
 50  0 if (asset == null)
 51  0 return null;
 52   
 53  0 return asset.buildURL(cycle);
 54    }
 55   
 56  0 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 57    {
 58    // No body, so we skip it all if not rewinding (assumes no side effects on
 59    // accessors).
 60   
 61  0 if (cycle.isRewinding())
 62  0 return;
 63   
 64  0 String imageURL = null;
 65  0 String focusURL = null;
 66  0 String blurURL = null;
 67  0 boolean dynamic = false;
 68  0 String imageName = null;
 69   
 70  0 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 71   
 72  0 ILinkComponent serviceLink = (ILinkComponent) cycle
 73    .getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
 74   
 75  0 if (serviceLink == null)
 76  0 throw new ApplicationRuntimeException(Tapestry
 77    .getMessage("Rollover.must-be-contained-by-link"), this, null, null);
 78   
 79  0 boolean linkDisabled = serviceLink.isDisabled();
 80   
 81  0 if (linkDisabled)
 82    {
 83  0 imageURL = getAssetURL(getDisabled(), cycle);
 84   
 85  0 if (imageURL == null)
 86  0 imageURL = getAssetURL(getImage(), cycle);
 87    }
 88    else
 89    {
 90  0 imageURL = getAssetURL(getImage(), cycle);
 91  0 focusURL = getAssetURL(getFocus(), cycle);
 92  0 blurURL = getAssetURL(getBlur(), cycle);
 93   
 94  0 dynamic = (focusURL != null) || (blurURL != null);
 95    }
 96   
 97  0 if (imageURL == null)
 98  0 throw Tapestry.createRequiredParameterException(this, "image");
 99   
 100  0 writer.beginEmpty("img");
 101   
 102  0 writer.attribute("src", imageURL);
 103   
 104  0 if (dynamic)
 105    {
 106  0 if (focusURL == null)
 107  0 focusURL = imageURL;
 108   
 109  0 if (blurURL == null)
 110  0 blurURL = imageURL;
 111   
 112  0 imageName = writeScript(cycle, pageRenderSupport, serviceLink, focusURL, blurURL);
 113   
 114  0 writer.attribute("name", imageName);
 115    }
 116   
 117  0 renderInformalParameters(writer, cycle);
 118   
 119  0 writer.closeTag();
 120   
 121    }
 122   
 123    // Injected
 124   
 125    public abstract IScript getScript();
 126   
 127  0 private String writeScript(IRequestCycle cycle, PageRenderSupport pageRenderSupport,
 128    ILinkComponent link, String focusURL, String blurURL)
 129    {
 130  0 String imageName = pageRenderSupport.getUniqueString(getId());
 131  0 String focusImageURL = pageRenderSupport.getPreloadedImageReference(focusURL);
 132  0 String blurImageURL = pageRenderSupport.getPreloadedImageReference(blurURL);
 133   
 134  0 Map symbols = new HashMap();
 135   
 136  0 symbols.put("imageName", imageName);
 137  0 symbols.put("focusImageURL", focusImageURL);
 138  0 symbols.put("blurImageURL", blurImageURL);
 139   
 140  0 getScript().execute(cycle, pageRenderSupport, symbols);
 141   
 142    // Add attributes to the link to control mouse over/out.
 143    // Because the script is written before the <body> tag,
 144    // there won't be any timing issues (such as cause
 145    // bug #113893).
 146   
 147  0 link.addEventHandler(LinkEventType.MOUSE_OVER, (String) symbols.get("onMouseOverName"));
 148  0 link.addEventHandler(LinkEventType.MOUSE_OUT, (String) symbols.get("onMouseOutName"));
 149   
 150  0 return imageName;
 151    }
 152   
 153    public abstract IAsset getBlur();
 154   
 155    public abstract IAsset getDisabled();
 156   
 157    public abstract IAsset getFocus();
 158   
 159    public abstract IAsset getImage();
 160    }