Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 135   Methods: 6
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LinkSubmit.java 100% 96% 83.3% 94.6%
coverage 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.form;
 16   
 17    import java.util.HashMap;
 18    import java.util.Map;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.hivemind.HiveMind;
 22    import org.apache.tapestry.IComponent;
 23    import org.apache.tapestry.IForm;
 24    import org.apache.tapestry.IMarkupWriter;
 25    import org.apache.tapestry.IRequestCycle;
 26    import org.apache.tapestry.IScript;
 27    import org.apache.tapestry.PageRenderSupport;
 28    import org.apache.tapestry.TapestryUtils;
 29   
 30    /**
 31    * Implements a component that submits its enclosing form via a JavaScript link. [ <a
 32    * href="../../../../../ComponentReference/LinkSubmit.html">Component Reference </a>]
 33    *
 34    * @author Richard Lewis-Shell
 35    */
 36   
 37    public abstract class LinkSubmit extends AbstractSubmit
 38    {
 39   
 40    /**
 41    * The name of an {@link org.apache.tapestry.IRequestCycle} attribute in which the current
 42    * submit link is stored. LinkSubmits do not nest.
 43    */
 44   
 45    public static final String ATTRIBUTE_NAME = "org.apache.tapestry.form.LinkSubmit";
 46   
 47    /**
 48    * Checks the submit name ({@link FormConstants#SUBMIT_NAME_PARAMETER}) to see if it matches
 49    * this LinkSubmit's assigned element name.
 50    */
 51  3 protected boolean isClicked(IRequestCycle cycle, String name)
 52    {
 53  3 String value = cycle.getParameter(FormConstants.SUBMIT_NAME_PARAMETER);
 54   
 55  3 return name.equals(value);
 56    }
 57   
 58    public abstract IScript getScript();
 59   
 60    /**
 61    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 62    * org.apache.tapestry.IRequestCycle)
 63    */
 64  2 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 65    {
 66  2 boolean disabled = isDisabled();
 67   
 68  2 IForm form = getForm();
 69  2 String name = getName();
 70   
 71  2 if (!disabled)
 72    {
 73  1 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 74   
 75  1 Map symbols = new HashMap();
 76  1 symbols.put("form", form);
 77  1 symbols.put("name", name);
 78   
 79  1 getScript().execute(cycle, pageRenderSupport, symbols);
 80   
 81  1 writer.begin("a");
 82  1 writer.attribute("href", (String) symbols.get("href"));
 83   
 84  1 renderIdAttribute(writer, cycle);
 85   
 86  1 renderInformalParameters(writer, cycle);
 87    }
 88   
 89  2 renderBody(writer, cycle);
 90   
 91  2 if (!disabled)
 92  1 writer.end();
 93   
 94    }
 95   
 96    /**
 97    * @see org.apache.tapestry.AbstractComponent#prepareForRender(org.apache.tapestry.IRequestCycle)
 98    */
 99  2 protected void prepareForRender(IRequestCycle cycle)
 100    {
 101  2 IComponent outer = (IComponent) cycle.getAttribute(ATTRIBUTE_NAME);
 102   
 103  2 if (outer != null)
 104  1 throw new ApplicationRuntimeException(FormMessages.linkSubmitMayNotNest(this, outer),
 105    this, getLocation(), null);
 106   
 107  1 cycle.setAttribute(ATTRIBUTE_NAME, this);
 108    }
 109   
 110    /**
 111    * @see org.apache.tapestry.AbstractComponent#cleanupAfterRender(org.apache.tapestry.IRequestCycle)
 112    */
 113  1 protected void cleanupAfterRender(IRequestCycle cycle)
 114    {
 115  1 cycle.removeAttribute(ATTRIBUTE_NAME);
 116    }
 117   
 118    /**
 119    * Links can not take focus, ever.
 120    */
 121  0 protected boolean getCanTakeFocus()
 122    {
 123  0 return false;
 124    }
 125   
 126    /**
 127    * Returns true; the LinkSubmit's body should render during a rewind, even if the component is
 128    * itself disabled.
 129    */
 130  1 protected boolean getRenderBodyOnRewind()
 131    {
 132  1 return true;
 133    }
 134   
 135    }