Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 100   Methods: 1
NCLOC: 45   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FieldLabel.java 100% 100% 100% 100%
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.valid;
 16   
 17    import org.apache.tapestry.AbstractComponent;
 18    import org.apache.tapestry.BindingException;
 19    import org.apache.tapestry.IForm;
 20    import org.apache.tapestry.IMarkupWriter;
 21    import org.apache.tapestry.IRequestCycle;
 22    import org.apache.tapestry.Tapestry;
 23    import org.apache.tapestry.TapestryUtils;
 24    import org.apache.tapestry.form.IFormComponent;
 25   
 26    /**
 27    * Used to label an {@link IFormComponent}. Because such fields know their displayName
 28    * (user-presentable name), there's no reason to hard code the label in a page's HTML template (this
 29    * also helps with localization). [ <a
 30    * href="../../../../../ComponentReference/FieldLabel.html">Component Reference </a>]
 31    *
 32    * @author Howard Lewis Lewis Ship
 33    */
 34   
 35    public abstract class FieldLabel extends AbstractComponent
 36    {
 37    // Parameter
 38    public abstract boolean isPrerender();
 39   
 40    /**
 41    * Gets the {@link IForm}&nbsp;and {@link IValidationDelegate delegate}, then renders the
 42    * label obtained from the field. Does nothing when rewinding.
 43    */
 44   
 45  8 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 46    {
 47  8 IForm form = TapestryUtils.getForm(cycle, this);
 48   
 49  8 IFormComponent field = getField();
 50   
 51  8 if (field != null && isPrerender())
 52  4 form.prerenderField(writer, field, getLocation());
 53   
 54  8 if (cycle.isRewinding())
 55  1 return;
 56   
 57  7 String displayName = getDisplayName();
 58   
 59  7 if (displayName == null)
 60    {
 61  5 if (field == null)
 62  1 throw Tapestry.createRequiredParameterException(this, "field");
 63   
 64  4 displayName = field.getDisplayName();
 65   
 66  4 if (displayName == null)
 67  1 throw new BindingException(ValidMessages.noDisplayName(this, field), this, null,
 68    getBinding("field"), null);
 69    }
 70   
 71  5 IValidationDelegate delegate = form.getDelegate();
 72   
 73  5 String id = field == null ? null : field.getClientId();
 74   
 75  5 delegate.writeLabelPrefix(field, writer, cycle);
 76   
 77  5 writer.begin("label");
 78   
 79  5 if (id != null)
 80  1 writer.attribute("for", id);
 81   
 82  5 delegate.writeLabelAttributes(writer, cycle, field);
 83  5 renderInformalParameters(writer, cycle);
 84   
 85  5 writer.print(displayName, getRaw());
 86   
 87  5 writer.end();
 88   
 89  5 delegate.writeLabelSuffix(field, writer, cycle);
 90    }
 91   
 92    /** displayName parameter */
 93    public abstract String getDisplayName();
 94   
 95    /** field parameter */
 96    public abstract IFormComponent getField();
 97   
 98    /** raw parameter */
 99    public abstract boolean getRaw();
 100    }