001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.valid;
016
017 import java.util.Locale;
018 import java.util.ResourceBundle;
019
020 /**
021 * Constants used for accessing validation message patterns.
022 *
023 * @author Paul Ferraro
024 */
025 public final class ValidationStrings
026 {
027 public static final String REQUIRED_FIELD = "field-is-required";
028
029 public static final String INVALID_DATE = "invalid-date-format";
030 public static final String INVALID_NUMBER = "invalid-numeric-format";
031 public static final String INVALID_EMAIL = "invalid-email-format";
032
033 public static final String REGEX_MISMATCH = "regex-mismatch";
034
035 public static final String PATTERN_MISMATCH = "pattern-not-matched";
036
037 public static final String VALUE_TOO_SHORT = "field-too-short";
038 public static final String VALUE_TOO_LONG = "field-too-long";
039
040 public static final String VALUE_TOO_SMALL = "number-too-small";
041 public static final String VALUE_TOO_LARGE = "number-too-large";
042
043 public static final String DATE_TOO_EARLY = "date-too-early";
044 public static final String DATE_TOO_LATE = "date-too-late";
045
046 public static final String INVALID_FIELD_EQUALITY = "invalid-field-equality";
047
048 private static final String RESOURCE_BUNDLE = ValidationStrings.class.getName();
049
050 private ValidationStrings()
051 {
052 // Disable construction
053 }
054
055 /**
056 * Fetches the appropriate validation message pattern from the appropriate localized resource.
057 * This method should be called with the locale of the current request.
058 */
059 public static String getMessagePattern(String key, Locale locale)
060 {
061 return ResourceBundle.getBundle(RESOURCE_BUNDLE, locale).getString(key);
062 }
063
064 }