| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NumericTranslatorSupport |
|
| 0.0;0 |
| 1 | // Copyright 2009 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.tapestry5.internal.translator; | |
| 16 | ||
| 17 | import org.apache.tapestry5.Field; | |
| 18 | ||
| 19 | import java.text.ParseException; | |
| 20 | ||
| 21 | /** | |
| 22 | * Used to generate the client-side JSON specification for how a number-based validator operates. Uses {@link | |
| 23 | * org.apache.tapestry5.ioc.services.ThreadLocale} to determine the locale for any locale-specific operations. | |
| 24 | * | |
| 25 | * @since 5.1.0.1 | |
| 26 | */ | |
| 27 | public interface NumericTranslatorSupport | |
| 28 | { | |
| 29 | /** | |
| 30 | * Parses a client-submitted value in a localized manner. | |
| 31 | * | |
| 32 | * @param type desired type of value | |
| 33 | * @param clientValue value from client; this will be trimmed of leading/trailing whitespace | |
| 34 | * @param <T> | |
| 35 | * @return the parsed value | |
| 36 | * @throws ParseException | |
| 37 | * @see org.apache.tapestry5.Translator#parseClient(org.apache.tapestry5.Field, String, String) | |
| 38 | */ | |
| 39 | <T extends Number> T parseClient(Class<T> type, String clientValue) throws ParseException; | |
| 40 | ||
| 41 | /** | |
| 42 | * Converts a server-side value to a client-side string. Integer types are formatted simply; decimal types may be | |
| 43 | * formatted using thousands-seperator commas. | |
| 44 | * | |
| 45 | * @param type type of value to convert | |
| 46 | * @param value current (non-null) value | |
| 47 | * @param <T> | |
| 48 | * @return value formatted | |
| 49 | */ | |
| 50 | <T extends Number> String toClient(Class<T> type, T value); | |
| 51 | ||
| 52 | /** | |
| 53 | * Returns the default message key for parse failures for the indicated type. | |
| 54 | * | |
| 55 | * @param type | |
| 56 | * @param <T> | |
| 57 | * @return a message key: either "integer-format-exception" or "number-format-exception" | |
| 58 | */ | |
| 59 | <T extends Number> String getMessageKey(Class<T> type); | |
| 60 | ||
| 61 | /** | |
| 62 | * Adds client-side format validation for the field, appropriate to the indicated type. | |
| 63 | * | |
| 64 | * @param type value type | |
| 65 | * @param field field to which validation should be added | |
| 66 | * @param message message if the client-side value can't be parsed as a number | |
| 67 | * @param <T> | |
| 68 | */ | |
| 69 | <T extends Number> void addValidation(Class<T> type, Field field, String message); | |
| 70 | } |