Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 120   Methods: 10
NCLOC: 60   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
NumberTranslator.java - 92.3% 90% 91.3%
coverage coverage
 1    // Copyright 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.translator;
 16   
 17    import java.text.DecimalFormat;
 18    import java.text.DecimalFormatSymbols;
 19    import java.text.Format;
 20    import java.util.Locale;
 21   
 22    import org.apache.tapestry.IForm;
 23    import org.apache.tapestry.IMarkupWriter;
 24    import org.apache.tapestry.IRequestCycle;
 25    import org.apache.tapestry.form.FormComponentContributorContext;
 26    import org.apache.tapestry.form.IFormComponent;
 27    import org.apache.tapestry.valid.ValidationConstraint;
 28    import org.apache.tapestry.valid.ValidationStrings;
 29   
 30    /**
 31    * A {@link java.text.DecimalFormat}-based {@link Translator} implementation.
 32    *
 33    * @author Paul Ferraro
 34    * @since 4.0
 35    */
 36    public class NumberTranslator extends FormatTranslator
 37    {
 38   
 39  11 public NumberTranslator()
 40    {
 41    }
 42   
 43    // Needed until HIVEMIND-134 fix is available
 44  0 public NumberTranslator(String initializer)
 45    {
 46  0 super(initializer);
 47    }
 48   
 49    /**
 50    * @see org.apache.tapestry.form.AbstractFormComponentContributor#defaultScript()
 51    */
 52  11 protected String defaultScript()
 53    {
 54  11 return "/org/apache/tapestry/form/translator/NumberTranslator.js";
 55    }
 56   
 57    /**
 58    * @see org.apache.tapestry.form.translator.FormatTranslator#defaultPattern()
 59    */
 60  11 protected String defaultPattern()
 61    {
 62  11 return "#";
 63    }
 64   
 65    /**
 66    * @see org.apache.tapestry.form.translator.FormatTranslator#getFormat(java.util.Locale)
 67    */
 68  7 protected Format getFormat(Locale locale)
 69    {
 70  7 return getDecimalFormat(locale);
 71    }
 72   
 73  12 public DecimalFormat getDecimalFormat(Locale locale)
 74    {
 75  12 return new DecimalFormat(getPattern(), new DecimalFormatSymbols(locale));
 76    }
 77   
 78    /**
 79    * @see org.apache.tapestry.form.translator.FormatTranslator#getMessageKey()
 80    */
 81  5 protected String getMessageKey()
 82    {
 83  5 return ValidationStrings.INVALID_NUMBER;
 84    }
 85   
 86    /**
 87    * @see org.apache.tapestry.form.translator.AbstractTranslator#getMessageParameters(java.util.Locale,
 88    * java.lang.String)
 89    */
 90  5 protected Object[] getMessageParameters(Locale locale, String label)
 91    {
 92  5 String pattern = getDecimalFormat(locale).toLocalizedPattern();
 93   
 94  5 return new Object[]
 95    { label, pattern };
 96    }
 97   
 98    /**
 99    * @see org.apache.tapestry.form.FormComponentContributor#renderContribution(org.apache.tapestry.IMarkupWriter,
 100    * org.apache.tapestry.IRequestCycle, FormComponentContributorContext, org.apache.tapestry.form.IFormComponent)
 101    */
 102  3 public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field)
 103    {
 104  3 super.renderContribution(writer, cycle, context, field);
 105   
 106  3 String message = buildMessage(field, getMessageKey());
 107  3 IForm form = field.getForm();
 108   
 109  3 addSubmitHandler(form, "validate_number(event, document." + form.getName() + "."
 110    + field.getName() + ",'" + message + "')");
 111    }
 112   
 113    /**
 114    * @see org.apache.tapestry.form.translator.FormatTranslator#getConstraint()
 115    */
 116  2 protected ValidationConstraint getConstraint()
 117    {
 118  2 return ValidationConstraint.NUMBER_FORMAT;
 119    }
 120    }