Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 144   Methods: 7
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LinkSubmit.java 100% 92.6% 71.4% 90%
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  6 protected boolean isClicked(IRequestCycle cycle, String name)
 51    {
 52  6 String value = cycle.getParameter(FormConstants.SUBMIT_NAME_PARAMETER);
 53   
 54  6 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  4 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 64    {
 65  4 boolean disabled = isDisabled();
 66   
 67  4 IForm form = getForm();
 68  4 String name = getName();
 69   
 70  4 if (!disabled)
 71    {
 72  2 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 73   
 74  2 Map symbols = new HashMap();
 75  2 symbols.put("form", form);
 76  2 symbols.put("name", name);
 77   
 78  2 getScript().execute(cycle, pageRenderSupport, symbols);
 79   
 80  2 writer.begin("a");
 81  2 writer.attribute("href", (String) symbols.get("href"));
 82   
 83  2 renderIdAttribute(writer, cycle);
 84   
 85  2 renderInformalParameters(writer, cycle);
 86    }
 87   
 88  4 renderBody(writer, cycle);
 89   
 90  4 if (!disabled)
 91  2 writer.end();
 92   
 93    }
 94   
 95    /**
 96    * @see org.apache.tapestry.form.AbstractSubmit#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 97    */
 98  2 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 99    {
 100  2 super.rewindFormComponent(writer, cycle);
 101   
 102  2 renderBody(writer, cycle);
 103    }
 104   
 105    /**
 106    * @see org.apache.tapestry.AbstractComponent#prepareForRender(org.apache.tapestry.IRequestCycle)
 107    */
 108  4 protected void prepareForRender(IRequestCycle cycle)
 109    {
 110  4 IComponent outer = (IComponent) cycle.getAttribute(ATTRIBUTE_NAME);
 111   
 112  4 if (outer != null)
 113  2 throw new ApplicationRuntimeException(FormMessages.linkSubmitMayNotNest(this, outer),
 114    this, getLocation(), null);
 115   
 116  2 cycle.setAttribute(ATTRIBUTE_NAME, this);
 117    }
 118   
 119    /**
 120    * @see org.apache.tapestry.AbstractComponent#cleanupAfterRender(org.apache.tapestry.IRequestCycle)
 121    */
 122  2 protected void cleanupAfterRender(IRequestCycle cycle)
 123    {
 124  2 cycle.removeAttribute(ATTRIBUTE_NAME);
 125    }
 126   
 127    /**
 128    * Links can not take focus, ever.
 129    */
 130  0 protected boolean getCanTakeFocus()
 131    {
 132  0 return false;
 133    }
 134   
 135    /**
 136    * Returns true; the LinkSubmit's body should render during a rewind, even if the component is
 137    * itself disabled.
 138    */
 139  0 protected boolean getAlwaysRenderBodyOnRewind()
 140    {
 141  0 return true;
 142    }
 143   
 144    }