Listing 1

protected Object handleGetObject( String key ){
		if( key == null || key.trim().equals("") ) return "";

Object result = null;
		for( int i = 0; i < _resources.length; i++ ) {
			String resourceName = _resources[i];
			if( CMA_RESOURCE.equals( resourceName ) ){
				try{
					Label label = ContentBO.getInstance().getLabel( key, _locale );
					if( label != null ){
						result = label.getDisplayText();
					}
				}
				catch( Exception exception ){
					if( log.isErrorEnabled() ){
						String errorMessage = "Error retrieving label from CMA using key : " + 
						key + " : locale : " + _locale;
						log.error( errorMessage, exception);
					}
				}
			}
			else{
				try{
					result = ResourceBundle.getBundle( resourceName, _locale ).getObject(key);
				}
				catch( Exception exception ){
					if( log.isErrorEnabled() ){
						String errorMessage = "Error retrieving label from " + resourceName +
						" using key : " + key + " : locale : " + _locale;
						log.error( errorMessage, exception);
					}
				}
			}

			if( result == null ){
				continue;
			}
			else{
				break;
			}
		}

		return result;
	}

Listing 2

public Label getLabel( String contentKey, Locale locale ) throws Exception {
		DAOInterface dao = DAOFactory.getInstance().getDAO( DAOFactory.LABEL_DAO );
		Label label = (Label) dao.getContent( contentKey, locale );
		if( label == null ){
			ArrayList list = getFallBackLocales( locale );
			if( list != null ){
				int size = list.size();
				for( int i = 0; i < size; i++ ){
					Locale fallBackLocale = (Locale) list.get(i);
					label = (Label) dao.getContent( contentKey, fallBackLocale );
					if( label != null ){
						break;
					}
				}
			}
		}
		return label;
	}


Listing 3

String country = locale.getCountry();
String language = locale.getLanguage();
String siteName = locale.getVariant();

	String sqlQuery = 	"SELECT * FROM LABEL label, INTERNATIONAL intl," +
	" CONTENT_KEYS ckeys, LOCALE locale, SITE site" +
			 " WHERE intl.LOCALE_ID=locale.LOCALE_ID" + 
			 " AND intl.KEY_ID=ckeys.KEY_ID" +
			 " AND intl.SITE_ID=site.SITE_ID" +
			 " AND label.INTNL_ID=intl.INTNL_ID" +
			" AND ckeys.KEY_NAME='" + contentKey + "'" + 
			" AND lower(site.SITE_NAME)=lower( '" + siteName +"' )";

	if( country.trim().length() > 0 ){
		sqlQuery = sqlQuery + " AND locale.COUNTRY_CODE='" + country + "'";
	}

	if( language.trim().length() > 0 ){
		sqlQuery = sqlQuery + " AND locale.LANGUAGE_CODE='" + language + "'";
	}

public class DynaMessageResources extends MessageResources{

private static Log log = LogFactory.getLog("I18N_LOG");
		private HashMap resourceBundleMap;

		public DynaMessageResources( MessageResourcesFactory factory, String config ){
			super( factory, config );
			resourceBundleMap = new HashMap();
		}

		public DynaMessageResources( MessageResourcesFactory factory, String config, boolean
		 returnNull ){
			this( factory, config );
			this.returnNull = returnNull;
		}

		public String getMessage(Locale locale, String key, Object args[]) {
       			 if (locale == null){
           				 locale = defaultLocale;
       			 }
        			String formatString = getMessage(locale, key);
        			if (formatString == null) {
           				 return returnNull ? null : ("???" + key + "???");
       			 }
        			MessageFormat format = new MessageFormat(escape(formatString));
       			 format.setLocale(locale);
       			 return format.format(args);
   		 }

		public String getMessage( Locale locale, String key ){
			if( key == null || key.trim().equals("") )
				return "";

			DynaResourceBundle bundle = getBundle( locale );
			String result = null;
			try{
				result = bundle.getString(key);
			}
			catch( MissingResourceException exception ){
				if( log.isErrorEnabled() ){
					String errorMessage = "Error retrieving message for key : " + 
					key + " : locale : " + locale;
					log.error( errorMessage, exception);
				}
			}
			return result;
		}

		private DynaResourceBundle getBundle( Locale locale ){
			String bundleKey = locale.getCountry() + locale.getLanguage() + locale.getVariant();
			DynaResourceBundle bundle = (DynaResourceBundle) resourceBundleMap.get( bundleKey );
			if( bundle == null ){
				String [] resources = config.split( "," );
				bundle = new DynaResourceBundle( locale, resources );
				resourceBundleMap.put( bundleKey, bundle );
			}

			return bundle;
		}
}


Listing 4

public class DynaMessageResources extends MessageResources{

private static Log log = LogFactory.getLog("I18N_LOG");
		private HashMap resourceBundleMap;

		public DynaMessageResources( MessageResourcesFactory factory, String config ){
			super( factory, config );
			resourceBundleMap = new HashMap();
		}

		public DynaMessageResources( MessageResourcesFactory factory, String config, boolean
		 returnNull ){
			this( factory, config );
			this.returnNull = returnNull;
		}

		public String getMessage(Locale locale, String key, Object args[]) {
       			 if (locale == null){
           				 locale = defaultLocale;
       			 }
        			String formatString = getMessage(locale, key);
        			if (formatString == null) {
           				 return returnNull ? null : ("???" + key + "???");
       			 }
        			MessageFormat format = new MessageFormat(escape(formatString));
       			 format.setLocale(locale);
       			 return format.format(args);
   		 }

		public String getMessage( Locale locale, String key ){
			if( key == null || key.trim().equals("") )
				return "";

			DynaResourceBundle bundle = getBundle( locale );
			String result = null;
			try{
				result = bundle.getString(key);
			}
			catch( MissingResourceException exception ){
				if( log.isErrorEnabled() ){
					String errorMessage = "Error retrieving message for key : " + 
					key + " : locale : " + locale;
					log.error( errorMessage, exception);
				}
			}
			return result;
		}

		private DynaResourceBundle getBundle( Locale locale ){
			String bundleKey = locale.getCountry() + locale.getLanguage() + locale.getVariant();
			DynaResourceBundle bundle = (DynaResourceBundle) resourceBundleMap.get( bundleKey );
			if( bundle == null ){
				String [] resources = config.split( "," );
				bundle = new DynaResourceBundle( locale, resources );
				resourceBundleMap.put( bundleKey, bundle );
			}

			return bundle;
		}
}


Listing 5

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
………………………
<tr>
<td width="100" align="left" valign="middle">
		<label for="stops"><font class="formFieldLabel"><bean:message
		 key="ui.i18n.label.maxStops" /></font></label>
	</td>
	<td align="left" valign="middle">
		<html:select property="maxNumberOfStops" tabindex="17" styleId="stops">
			<c:forEach items="${SessionHelper.stopsList}" var="stop" >
				<c:set var="stopsContentKey" value="ui.i18n.label.stops.${stop.text}" />
   	    			<html-el:option value="${stop.value}" key="${stopsContentKey}" >
					 </html-el:option>
   	    		</c:forEach>
       		</html:select>
	</td>
</tr>


Listing 6

<form name="tripTemplateForm">
             		 <field property="from" depends="required">
                  		<arg0 key="ui.text.o_and_d.from_label"/>
              		</ field >
              		< field property="to" depends="required">
                 		<arg0 key="ui.text.o_and_d.to_label_uppercase"/>
              		</ field >
              		< field property="departDay" depends="required">
                  		<arg0 key="ui.text.trip_template_edit.depart_label"/>
              		</ field >
              		< field property="departTime" depends="required">
                  		<arg0 key="ui.text.trip_template_edit.depart_label"/>
              		</ field >
          	</form>


Listing 7

public class LocaleActionServlet extends ActionServlet{
	public static final String DEFAULT_LANGUAGE = "en";
	public static final String DEFAULT_COUNTRY = "us";
	public static final String DEFAULT_SITE = "core";

	public void service( HttpServletRequest request, HttpServletResponse response ) throws
	 ServletException, IOException{
		String language = DEFAULT_LANGUAGE;
		String country = DEFAULT_COUNTRY;
		String site = DEFAULT_SITE;

		MessageResources messageResources = (MessageResources)
		 this.getServletContext().getAttribute( Globals.MESSAGES_KEY );
		String configParam = messageResources.getConfig();
		HttpSession session = request.getSession(true);
		SessionHelper sessionHelper = SessionHelper.getSessionHelper( session );

		String servletPath = request.getServletPath();
		servletPath = servletPath.substring( 1 );
		String [] pathValues = servletPath.split( "/" );

		if( pathValues.length <= 2 ) {
			Locale locale = ( Locale ) session.getAttribute( Globals.LOCALE_KEY );

			if( locale == null ) {
				locale = new Locale( language, country, site );
				sessionHelper.setLocale(locale, configParam);
			}

			super.service( request, response );
		}
		else if( pathValues.length == 4 ||  pathValues.length == 5 ) {
			site = pathValues[0];
			country = pathValues[1];
			language = pathValues[2];

			Locale locale = new Locale(language, country, site);
			sessionHelper.setLocale(locale, configParam);

			String resourcePath = "";

			for( int i = 3; i < pathValues.length; i++ ) {
				resourcePath =  resourcePath + "/" + pathValues[i];
			}

			RequestDispatcher dispatcher = request.getRequestDispatcher( resourcePath );
			dispatcher.forward( request, response );
		}
		else{
			response.sendError( HttpServletResponse.SC_BAD_REQUEST );
		}
	}
}


Listing 8

public void setLocale( Locale locale, String configParam ){
	//Setting the locale in session such that Struts can use it
	currentSession.setAttribute(Globals.LOCALE_KEY, locale);

	//Setting the locale in session such that JSTL can use it
	Config.set( currentSession, Config.FMT_LOCALE, locale );

	String[] resources = configParam.split(",");
	LocalizationContext jstlLocalizationContext = new LocalizationContext(  new
	 DynaResourceBundle(locale, resources), locale );
	Config.set( currentSession, Config.FMT_LOCALIZATION_CONTEXT, jstlLocalizationContext );
}