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