Clover coverage report - Code Coverage for tapestry release 4.0-beta-9
Coverage timestamp: Sat Oct 1 2005 08:36:20 EDT
file stats: LOC: 142   Methods: 6
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LinkSubmit.java 100% 96.4% 83.3% 95%
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  3 protected boolean isClicked(IRequestCycle cycle, String name)
 48    {
 49  3 String value = cycle.getParameter(name);
 50   
 51  3 return HiveMind.isNonBlank(value);
 52    }
 53   
 54    public abstract IScript getScript();
 55   
 56    /**
 57    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 58    * org.apache.tapestry.IRequestCycle)
 59    */
 60  2 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 61    {
 62  2 boolean disabled = isDisabled();
 63   
 64  2 IForm form = getForm();
 65  2 String name = getName();
 66   
 67  2 String hiddenId = cycle.getUniqueId(TapestryUtils
 68    .convertTapestryIdToNMToken(getIdParameter()));
 69   
 70    // Store for later access by the FieldLabel (or JavaScript).
 71   
 72  2 setClientId(hiddenId);
 73   
 74    // Add a hidden field used to identify the link that caused the submission.
 75    // Client-side JavaScript will set the value to non-null when the link is clicked,
 76    // then force the form to submit.
 77   
 78  2 form.addHiddenValue(name, hiddenId, "");
 79   
 80  2 if (!disabled)
 81    {
 82  1 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 83   
 84  1 Map symbols = new HashMap();
 85  1 symbols.put("form", form);
 86  1 symbols.put("hiddenId", hiddenId);
 87   
 88  1 getScript().execute(cycle, pageRenderSupport, symbols);
 89   
 90  1 writer.begin("a");
 91  1 writer.attribute("href", (String) symbols.get("href"));
 92  1 renderInformalParameters(writer, cycle);
 93    }
 94   
 95  2 renderBody(writer, cycle);
 96   
 97  2 if (!disabled)
 98  1 writer.end();
 99   
 100    }
 101   
 102    /**
 103    * When a LinkSubmit rewinds, it should invoke its listener, etc., but should also render any
 104    * components in its body.
 105    */
 106  1 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 107    {
 108  1 super.rewindFormComponent(writer, cycle);
 109   
 110  1 renderBody(writer, cycle);
 111    }
 112   
 113    /**
 114    * @see org.apache.tapestry.AbstractComponent#prepareForRender(org.apache.tapestry.IRequestCycle)
 115    */
 116  2 protected void prepareForRender(IRequestCycle cycle)
 117    {
 118  2 IComponent outer = (IComponent) cycle.getAttribute(ATTRIBUTE_NAME);
 119   
 120  2 if (outer != null)
 121  1 throw new ApplicationRuntimeException(FormMessages.linkSubmitMayNotNest(this, outer),
 122    this, getLocation(), null);
 123   
 124  1 cycle.setAttribute(ATTRIBUTE_NAME, this);
 125    }
 126   
 127    /**
 128    * @see org.apache.tapestry.AbstractComponent#cleanupAfterRender(org.apache.tapestry.IRequestCycle)
 129    */
 130  1 protected void cleanupAfterRender(IRequestCycle cycle)
 131    {
 132  1 cycle.removeAttribute(ATTRIBUTE_NAME);
 133    }
 134   
 135    /**
 136    * Links can not take focus.
 137    */
 138  0 protected boolean getCanTakeFocus()
 139    {
 140  0 return false;
 141    }
 142    }