001 /*
002 * Copyright 2004 Chris Nelson
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing,
008 * software distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and limitations under the License.
011 */
012 package org.trails.component;
013
014 import org.apache.tapestry.BaseComponent;
015 import org.apache.tapestry.annotations.InjectObject;
016 import org.trails.i18n.TrailsMessageSource;
017
018
019 /**
020 * @author fus8882
021 * <p/>
022 * TODO To change the template for this generated type comment go to
023 * Window - Preferences - Java - Code Style - Code Templates
024 */
025 public abstract class TrailsComponent extends BaseComponent
026 {
027 public static String DEFAULT = "Default";
028
029 /**
030 * Return the Spring TrailsMessageSource. This is used to implement
031 * i18n in all Trails components, accessing a i18n properties file in the
032 * application instead of accessing the property file located in org.trais.component package.
033 * By doing this, someone who would need i18n wouldn't need to change the property
034 * located in the org.trails.component package and rebuild the trails.jar
035 *
036 * @return
037 */
038 @InjectObject("service:trails.core.MessageSource")
039 public abstract TrailsMessageSource getResourceBundleMessageSource();
040
041 /**
042 * This method will lookup for a message in Trails resource bundle
043 * and return a message, if found, in the default Locale. This is normally called from
044 * Component templates, so messages will be looked up outside the component,
045 * making it easier for an user to localize Trails.
046 */
047 public String getMessage(String key)
048 {
049 return getResourceBundleMessageSource().getMessageWithDefaultValue(key, "[TRAILS][" + key.toUpperCase() + "]");
050 }
051
052 }