turbine-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pain...@apache.org
Subject svn commit: r1045251 [13/34] - in /websites/production/turbine/content/fulcrum/fulcrum-localization: ./ announcements/ apidocs/ apidocs/org/apache/fulcrum/localization/ apidocs/org/apache/fulcrum/localization/class-use/ apidocs/resources/ apidocs/src-h...
Date Tue, 21 May 2019 03:35:36 GMT
Modified: websites/production/turbine/content/fulcrum/fulcrum-localization/apidocs/src-html/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.html
==============================================================================
--- websites/production/turbine/content/fulcrum/fulcrum-localization/apidocs/src-html/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.html (original)
+++ websites/production/turbine/content/fulcrum/fulcrum-localization/apidocs/src-html/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.html Tue May 21 03:35:35 2019
@@ -1,574 +1,646 @@
-<HTML>
-<BODY BGCOLOR="white">
-<PRE>
-<FONT color="green">001</FONT>    package org.apache.fulcrum.localization;<a name="line.1"></a>
-<FONT color="green">002</FONT>    <a name="line.2"></a>
-<FONT color="green">003</FONT>    /*<a name="line.3"></a>
-<FONT color="green">004</FONT>     * Licensed to the Apache Software Foundation (ASF) under one<a name="line.4"></a>
-<FONT color="green">005</FONT>     * or more contributor license agreements.  See the NOTICE file<a name="line.5"></a>
-<FONT color="green">006</FONT>     * distributed with this work for additional information<a name="line.6"></a>
-<FONT color="green">007</FONT>     * regarding copyright ownership.  The ASF licenses this file<a name="line.7"></a>
-<FONT color="green">008</FONT>     * to you under the Apache License, Version 2.0 (the<a name="line.8"></a>
-<FONT color="green">009</FONT>     * "License"); you may not use this file except in compliance<a name="line.9"></a>
-<FONT color="green">010</FONT>     * with the License.  You may obtain a copy of the License at<a name="line.10"></a>
-<FONT color="green">011</FONT>     *<a name="line.11"></a>
-<FONT color="green">012</FONT>     *   http://www.apache.org/licenses/LICENSE-2.0<a name="line.12"></a>
-<FONT color="green">013</FONT>     *<a name="line.13"></a>
-<FONT color="green">014</FONT>     * Unless required by applicable law or agreed to in writing,<a name="line.14"></a>
-<FONT color="green">015</FONT>     * software distributed under the License is distributed on an<a name="line.15"></a>
-<FONT color="green">016</FONT>     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.16"></a>
-<FONT color="green">017</FONT>     * KIND, either express or implied.  See the License for the<a name="line.17"></a>
-<FONT color="green">018</FONT>     * specific language governing permissions and limitations<a name="line.18"></a>
-<FONT color="green">019</FONT>     * under the License.<a name="line.19"></a>
-<FONT color="green">020</FONT>     */<a name="line.20"></a>
-<FONT color="green">021</FONT>    <a name="line.21"></a>
-<FONT color="green">022</FONT>    import java.text.MessageFormat;<a name="line.22"></a>
-<FONT color="green">023</FONT>    import java.util.HashMap;<a name="line.23"></a>
-<FONT color="green">024</FONT>    import java.util.Locale;<a name="line.24"></a>
-<FONT color="green">025</FONT>    import java.util.Map;<a name="line.25"></a>
-<FONT color="green">026</FONT>    import java.util.MissingResourceException;<a name="line.26"></a>
-<FONT color="green">027</FONT>    import java.util.ResourceBundle;<a name="line.27"></a>
-<FONT color="green">028</FONT>    <a name="line.28"></a>
-<FONT color="green">029</FONT>    import org.apache.avalon.framework.activity.Initializable;<a name="line.29"></a>
-<FONT color="green">030</FONT>    import org.apache.avalon.framework.configuration.Configurable;<a name="line.30"></a>
-<FONT color="green">031</FONT>    import org.apache.avalon.framework.configuration.Configuration;<a name="line.31"></a>
-<FONT color="green">032</FONT>    import org.apache.avalon.framework.configuration.ConfigurationException;<a name="line.32"></a>
-<FONT color="green">033</FONT>    import org.apache.avalon.framework.logger.AbstractLogEnabled;<a name="line.33"></a>
-<FONT color="green">034</FONT>    import org.apache.commons.lang.StringUtils;<a name="line.34"></a>
-<FONT color="green">035</FONT>    <a name="line.35"></a>
-<FONT color="green">036</FONT>    /**<a name="line.36"></a>
-<FONT color="green">037</FONT>     * &lt;p&gt;This class is the single point of access to all localization<a name="line.37"></a>
-<FONT color="green">038</FONT>     * resources.  It caches different ResourceBundles for different<a name="line.38"></a>
-<FONT color="green">039</FONT>     * Locales.&lt;/p&gt;<a name="line.39"></a>
-<FONT color="green">040</FONT>     *<a name="line.40"></a>
-<FONT color="green">041</FONT>     * &lt;p&gt;Usage example:&lt;/p&gt;<a name="line.41"></a>
-<FONT color="green">042</FONT>     *<a name="line.42"></a>
-<FONT color="green">043</FONT>     * &lt;blockquote&gt;&lt;code&gt;&lt;pre&gt;<a name="line.43"></a>
-<FONT color="green">044</FONT>     * SimpleLocalizationService ls = (SimpleLocalizationService) TurbineServices<a name="line.44"></a>
-<FONT color="green">045</FONT>     *     .getInstance().getService(SimpleLocalizationService.SERVICE_NAME);<a name="line.45"></a>
-<FONT color="green">046</FONT>     * &lt;/pre&gt;&lt;/code&gt;&lt;/blockquote&gt;<a name="line.46"></a>
-<FONT color="green">047</FONT>     *<a name="line.47"></a>
-<FONT color="green">048</FONT>     * &lt;p&gt;Then call {@link #getString(String, Locale, String)}, or one of<a name="line.48"></a>
-<FONT color="green">049</FONT>     * two methods to retrieve a ResourceBundle:<a name="line.49"></a>
-<FONT color="green">050</FONT>     *<a name="line.50"></a>
-<FONT color="green">051</FONT>     * &lt;ul&gt;<a name="line.51"></a>
-<FONT color="green">052</FONT>     * &lt;li&gt;getBundle("MyBundleName")&lt;/li&gt;<a name="line.52"></a>
-<FONT color="green">053</FONT>     * &lt;li&gt;getBundle("MyBundleName", Locale)&lt;/li&gt;<a name="line.53"></a>
-<FONT color="green">054</FONT>     * &lt;li&gt;etc.&lt;/li&gt;<a name="line.54"></a>
-<FONT color="green">055</FONT>     * &lt;/ul&gt;&lt;/p&gt;<a name="line.55"></a>
-<FONT color="green">056</FONT>     *<a name="line.56"></a>
-<FONT color="green">057</FONT>     * @author &lt;a href="mailto:jm@mediaphil.de"&gt;Jonas Maurus&lt;/a&gt;<a name="line.57"></a>
-<FONT color="green">058</FONT>     * @author &lt;a href="mailto:jon@latchkey.com"&gt;Jon S. Stevens&lt;/a&gt;<a name="line.58"></a>
-<FONT color="green">059</FONT>     * @author &lt;a href="mailto:novalidemail@foo.com"&gt;Frank Y. Kim&lt;/a&gt;<a name="line.59"></a>
-<FONT color="green">060</FONT>     * @author &lt;a href="mailto:dlr@finemaltcoding.com"&gt;Daniel Rall&lt;/a&gt;<a name="line.60"></a>
-<FONT color="green">061</FONT>     * @author &lt;a href="mailto:leonardr@collab.net"&gt;Leonard Richardson&lt;/a&gt;<a name="line.61"></a>
-<FONT color="green">062</FONT>     * @author &lt;a href="mailto:mcconnell@apache.org"&gt;Stephen McConnell&lt;/a&gt;<a name="line.62"></a>
-<FONT color="green">063</FONT>     * @author &lt;a href="mailto:tv@apache.org"&gt;Thomas Vandahl&lt;/a&gt;<a name="line.63"></a>
-<FONT color="green">064</FONT>     * @version $Id: DefaultLocalizationService.java 535465 2007-05-05 06:58:06Z tv $<a name="line.64"></a>
-<FONT color="green">065</FONT>     * @avalon.component name="localization" lifestyle="singleton"<a name="line.65"></a>
-<FONT color="green">066</FONT>     * @avalon.service type="org.apache.fulcrum.localization.SimpleLocalizationService"<a name="line.66"></a>
-<FONT color="green">067</FONT>     */<a name="line.67"></a>
-<FONT color="green">068</FONT>    public class SimpleLocalizationServiceImpl<a name="line.68"></a>
-<FONT color="green">069</FONT>        extends AbstractLogEnabled<a name="line.69"></a>
-<FONT color="green">070</FONT>        implements SimpleLocalizationService, Configurable, Initializable<a name="line.70"></a>
-<FONT color="green">071</FONT>    {<a name="line.71"></a>
-<FONT color="green">072</FONT>        /** Key Prefix for our bundles */<a name="line.72"></a>
-<FONT color="green">073</FONT>        private static final String BUNDLES = "bundles";<a name="line.73"></a>
-<FONT color="green">074</FONT>        /**<a name="line.74"></a>
-<FONT color="green">075</FONT>         * The value to pass to &lt;code&gt;MessageFormat&lt;/code&gt; if a<a name="line.75"></a>
-<FONT color="green">076</FONT>         * &lt;code&gt;null&lt;/code&gt; reference is passed to &lt;code&gt;format()&lt;/code&gt;.<a name="line.76"></a>
-<FONT color="green">077</FONT>         */<a name="line.77"></a>
-<FONT color="green">078</FONT>        private static final Object[] NO_ARGS = new Object[0];<a name="line.78"></a>
-<FONT color="green">079</FONT>        /**<a name="line.79"></a>
-<FONT color="green">080</FONT>         * Bundle name keys a HashMap of the ResourceBundles in this<a name="line.80"></a>
-<FONT color="green">081</FONT>         * service (which is in turn keyed by Locale).<a name="line.81"></a>
-<FONT color="green">082</FONT>         */<a name="line.82"></a>
-<FONT color="green">083</FONT>        private HashMap bundles = null;<a name="line.83"></a>
-<FONT color="green">084</FONT>        /**<a name="line.84"></a>
-<FONT color="green">085</FONT>         * The list of default bundles to search.<a name="line.85"></a>
-<FONT color="green">086</FONT>         */<a name="line.86"></a>
-<FONT color="green">087</FONT>        private String[] bundleNames = null;<a name="line.87"></a>
-<FONT color="green">088</FONT>        /**<a name="line.88"></a>
-<FONT color="green">089</FONT>         * The default bundle name to use if not specified.<a name="line.89"></a>
-<FONT color="green">090</FONT>         */<a name="line.90"></a>
-<FONT color="green">091</FONT>        private String defaultBundleName = null;<a name="line.91"></a>
-<FONT color="green">092</FONT>        /**<a name="line.92"></a>
-<FONT color="green">093</FONT>         * The name of the default locale to use (includes language and<a name="line.93"></a>
-<FONT color="green">094</FONT>         * country).<a name="line.94"></a>
-<FONT color="green">095</FONT>         */<a name="line.95"></a>
-<FONT color="green">096</FONT>        private Locale defaultLocale = null;<a name="line.96"></a>
-<FONT color="green">097</FONT>        /** The name of the default language to use. */<a name="line.97"></a>
-<FONT color="green">098</FONT>        private String defaultLanguage;<a name="line.98"></a>
-<FONT color="green">099</FONT>        /** The name of the default country to use. */<a name="line.99"></a>
-<FONT color="green">100</FONT>        private String defaultCountry = null;<a name="line.100"></a>
-<FONT color="green">101</FONT>    <a name="line.101"></a>
-<FONT color="green">102</FONT>        /**<a name="line.102"></a>
-<FONT color="green">103</FONT>         * Creates a new instance.<a name="line.103"></a>
-<FONT color="green">104</FONT>         */<a name="line.104"></a>
-<FONT color="green">105</FONT>        public SimpleLocalizationServiceImpl()<a name="line.105"></a>
-<FONT color="green">106</FONT>        {<a name="line.106"></a>
-<FONT color="green">107</FONT>            bundles = new HashMap();<a name="line.107"></a>
-<FONT color="green">108</FONT>        }<a name="line.108"></a>
-<FONT color="green">109</FONT>    <a name="line.109"></a>
-<FONT color="green">110</FONT>        /**<a name="line.110"></a>
-<FONT color="green">111</FONT>         * Avalon lifecycle method<a name="line.111"></a>
-<FONT color="green">112</FONT>         * <a name="line.112"></a>
-<FONT color="green">113</FONT>         * @see {@link Configurable}<a name="line.113"></a>
-<FONT color="green">114</FONT>         */<a name="line.114"></a>
-<FONT color="green">115</FONT>        public void configure(Configuration conf) throws ConfigurationException<a name="line.115"></a>
-<FONT color="green">116</FONT>        {<a name="line.116"></a>
-<FONT color="green">117</FONT>            Locale jvmDefault = Locale.getDefault();<a name="line.117"></a>
-<FONT color="green">118</FONT>            defaultLanguage =<a name="line.118"></a>
-<FONT color="green">119</FONT>                conf<a name="line.119"></a>
-<FONT color="green">120</FONT>                    .getAttribute(<a name="line.120"></a>
-<FONT color="green">121</FONT>                        "locale-default-language",<a name="line.121"></a>
-<FONT color="green">122</FONT>                        jvmDefault.getLanguage())<a name="line.122"></a>
-<FONT color="green">123</FONT>                    .trim();<a name="line.123"></a>
-<FONT color="green">124</FONT>            defaultCountry =<a name="line.124"></a>
-<FONT color="green">125</FONT>                conf<a name="line.125"></a>
-<FONT color="green">126</FONT>                    .getAttribute("locale-default-country", jvmDefault.getCountry())<a name="line.126"></a>
-<FONT color="green">127</FONT>                    .trim();<a name="line.127"></a>
-<FONT color="green">128</FONT>            // FIXME! need to add bundle names<a name="line.128"></a>
-<FONT color="green">129</FONT>            getLogger().info(<a name="line.129"></a>
-<FONT color="green">130</FONT>                "initialized lang="<a name="line.130"></a>
-<FONT color="green">131</FONT>                    + defaultLanguage<a name="line.131"></a>
-<FONT color="green">132</FONT>                    + " country="<a name="line.132"></a>
-<FONT color="green">133</FONT>                    + defaultCountry);<a name="line.133"></a>
-<FONT color="green">134</FONT>            final Configuration bundles = conf.getChild(BUNDLES, false);<a name="line.134"></a>
-<FONT color="green">135</FONT>            if (bundles != null)<a name="line.135"></a>
-<FONT color="green">136</FONT>            {<a name="line.136"></a>
-<FONT color="green">137</FONT>                Configuration[] nameVal = bundles.getChildren();<a name="line.137"></a>
-<FONT color="green">138</FONT>                String bundleName[] = new String[nameVal.length];<a name="line.138"></a>
-<FONT color="green">139</FONT>                for (int i = 0; i &lt; nameVal.length; i++)<a name="line.139"></a>
-<FONT color="green">140</FONT>                {<a name="line.140"></a>
-<FONT color="green">141</FONT>                    String val = nameVal[i].getValue();<a name="line.141"></a>
-<FONT color="green">142</FONT>                    getLogger().debug("Registered bundle " + val);<a name="line.142"></a>
-<FONT color="green">143</FONT>                    bundleName[i] = val;<a name="line.143"></a>
-<FONT color="green">144</FONT>                }<a name="line.144"></a>
-<FONT color="green">145</FONT>                initBundleNames(bundleName);<a name="line.145"></a>
-<FONT color="green">146</FONT>            }<a name="line.146"></a>
-<FONT color="green">147</FONT>        }<a name="line.147"></a>
-<FONT color="green">148</FONT>        <a name="line.148"></a>
-<FONT color="green">149</FONT>        /**<a name="line.149"></a>
-<FONT color="green">150</FONT>         * Called the first time the Service is used.<a name="line.150"></a>
-<FONT color="green">151</FONT>         */<a name="line.151"></a>
-<FONT color="green">152</FONT>        public void initialize() throws Exception<a name="line.152"></a>
-<FONT color="green">153</FONT>        {<a name="line.153"></a>
-<FONT color="green">154</FONT>            // initBundleNames(null);<a name="line.154"></a>
-<FONT color="green">155</FONT>            defaultLocale = new Locale(defaultLanguage, defaultCountry);<a name="line.155"></a>
-<FONT color="green">156</FONT>            if (getLogger().isInfoEnabled())<a name="line.156"></a>
-<FONT color="green">157</FONT>            {<a name="line.157"></a>
-<FONT color="green">158</FONT>                getLogger().info("Localization Service is Initialized now..");<a name="line.158"></a>
-<FONT color="green">159</FONT>            }<a name="line.159"></a>
-<FONT color="green">160</FONT>        }<a name="line.160"></a>
-<FONT color="green">161</FONT>        <a name="line.161"></a>
-<FONT color="green">162</FONT>        /**<a name="line.162"></a>
-<FONT color="green">163</FONT>         * Initialize list of default bundle names.<a name="line.163"></a>
-<FONT color="green">164</FONT>         *<a name="line.164"></a>
-<FONT color="green">165</FONT>         * @param ignored names Ignored.<a name="line.165"></a>
-<FONT color="green">166</FONT>         */<a name="line.166"></a>
-<FONT color="green">167</FONT>        protected void initBundleNames(String[] intBundleNames)<a name="line.167"></a>
-<FONT color="green">168</FONT>        {<a name="line.168"></a>
-<FONT color="green">169</FONT>            //System.err.println("cfg=" + getConfiguration());<a name="line.169"></a>
-<FONT color="green">170</FONT>            if (defaultBundleName != null &amp;&amp; defaultBundleName.length() &gt; 0)<a name="line.170"></a>
-<FONT color="green">171</FONT>            {<a name="line.171"></a>
-<FONT color="green">172</FONT>                // Using old-style single bundle name property.<a name="line.172"></a>
-<FONT color="green">173</FONT>                if (intBundleNames == null || intBundleNames.length &lt;= 0)<a name="line.173"></a>
-<FONT color="green">174</FONT>                {<a name="line.174"></a>
-<FONT color="green">175</FONT>                    bundleNames = new String[] { defaultBundleName };<a name="line.175"></a>
-<FONT color="green">176</FONT>                }<a name="line.176"></a>
-<FONT color="green">177</FONT>                else<a name="line.177"></a>
-<FONT color="green">178</FONT>                {<a name="line.178"></a>
-<FONT color="green">179</FONT>                    // Prepend "default" bundle name.<a name="line.179"></a>
-<FONT color="green">180</FONT>                    String[] array = new String[intBundleNames.length + 1];<a name="line.180"></a>
-<FONT color="green">181</FONT>                    array[0] = defaultBundleName;<a name="line.181"></a>
-<FONT color="green">182</FONT>                    System.arraycopy(<a name="line.182"></a>
-<FONT color="green">183</FONT>                        intBundleNames,<a name="line.183"></a>
-<FONT color="green">184</FONT>                        0,<a name="line.184"></a>
-<FONT color="green">185</FONT>                        array,<a name="line.185"></a>
-<FONT color="green">186</FONT>                        1,<a name="line.186"></a>
-<FONT color="green">187</FONT>                        intBundleNames.length);<a name="line.187"></a>
-<FONT color="green">188</FONT>                    bundleNames = array;<a name="line.188"></a>
-<FONT color="green">189</FONT>                }<a name="line.189"></a>
-<FONT color="green">190</FONT>            }<a name="line.190"></a>
-<FONT color="green">191</FONT>            if (intBundleNames == null)<a name="line.191"></a>
-<FONT color="green">192</FONT>            {<a name="line.192"></a>
-<FONT color="green">193</FONT>                bundleNames = new String[0];<a name="line.193"></a>
-<FONT color="green">194</FONT>            }<a name="line.194"></a>
-<FONT color="green">195</FONT>            bundleNames = intBundleNames;<a name="line.195"></a>
-<FONT color="green">196</FONT>        }<a name="line.196"></a>
-<FONT color="green">197</FONT>        <a name="line.197"></a>
-<FONT color="green">198</FONT>        /**<a name="line.198"></a>
-<FONT color="green">199</FONT>         * Retrieves the default language (specified in the config file).<a name="line.199"></a>
-<FONT color="green">200</FONT>         */<a name="line.200"></a>
-<FONT color="green">201</FONT>        public String getDefaultLanguage()<a name="line.201"></a>
-<FONT color="green">202</FONT>        {<a name="line.202"></a>
-<FONT color="green">203</FONT>            return defaultLanguage;<a name="line.203"></a>
-<FONT color="green">204</FONT>        }<a name="line.204"></a>
-<FONT color="green">205</FONT>        <a name="line.205"></a>
-<FONT color="green">206</FONT>        /**<a name="line.206"></a>
-<FONT color="green">207</FONT>         * Retrieves the default country (specified in the config file).<a name="line.207"></a>
-<FONT color="green">208</FONT>         */<a name="line.208"></a>
-<FONT color="green">209</FONT>        public String getDefaultCountry()<a name="line.209"></a>
-<FONT color="green">210</FONT>        {<a name="line.210"></a>
-<FONT color="green">211</FONT>            return defaultCountry;<a name="line.211"></a>
-<FONT color="green">212</FONT>        }<a name="line.212"></a>
-<FONT color="green">213</FONT>        <a name="line.213"></a>
-<FONT color="green">214</FONT>        /**<a name="line.214"></a>
-<FONT color="green">215</FONT>         * Retrieves the default Locale (as created from default<a name="line.215"></a>
-<FONT color="green">216</FONT>         * language and default country).<a name="line.216"></a>
-<FONT color="green">217</FONT>         */<a name="line.217"></a>
-<FONT color="green">218</FONT>        public Locale getDefaultLocale()<a name="line.218"></a>
-<FONT color="green">219</FONT>        {<a name="line.219"></a>
-<FONT color="green">220</FONT>            return defaultLocale;<a name="line.220"></a>
-<FONT color="green">221</FONT>        }<a name="line.221"></a>
-<FONT color="green">222</FONT>    <a name="line.222"></a>
-<FONT color="green">223</FONT>        /**<a name="line.223"></a>
-<FONT color="green">224</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#getDefaultBundleName()<a name="line.224"></a>
-<FONT color="green">225</FONT>         */<a name="line.225"></a>
-<FONT color="green">226</FONT>        public String getDefaultBundleName()<a name="line.226"></a>
-<FONT color="green">227</FONT>        {<a name="line.227"></a>
-<FONT color="green">228</FONT>            return (bundleNames.length &gt; 0 ? bundleNames[0] : "");<a name="line.228"></a>
-<FONT color="green">229</FONT>        }<a name="line.229"></a>
-<FONT color="green">230</FONT>        <a name="line.230"></a>
-<FONT color="green">231</FONT>        /**<a name="line.231"></a>
-<FONT color="green">232</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundleNames()<a name="line.232"></a>
-<FONT color="green">233</FONT>         */<a name="line.233"></a>
-<FONT color="green">234</FONT>        public String[] getBundleNames()<a name="line.234"></a>
-<FONT color="green">235</FONT>        {<a name="line.235"></a>
-<FONT color="green">236</FONT>            return (String[]) bundleNames.clone();<a name="line.236"></a>
-<FONT color="green">237</FONT>        }<a name="line.237"></a>
-<FONT color="green">238</FONT>        <a name="line.238"></a>
-<FONT color="green">239</FONT>        /**<a name="line.239"></a>
-<FONT color="green">240</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundle()<a name="line.240"></a>
-<FONT color="green">241</FONT>         */<a name="line.241"></a>
-<FONT color="green">242</FONT>        public ResourceBundle getBundle()<a name="line.242"></a>
-<FONT color="green">243</FONT>        {<a name="line.243"></a>
-<FONT color="green">244</FONT>            return getBundle(getDefaultBundleName(), (Locale) null);<a name="line.244"></a>
-<FONT color="green">245</FONT>        }<a name="line.245"></a>
-<FONT color="green">246</FONT>        <a name="line.246"></a>
-<FONT color="green">247</FONT>        /**<a name="line.247"></a>
-<FONT color="green">248</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundle(String)<a name="line.248"></a>
-<FONT color="green">249</FONT>         */<a name="line.249"></a>
-<FONT color="green">250</FONT>        public ResourceBundle getBundle(String bundleName)<a name="line.250"></a>
-<FONT color="green">251</FONT>        {<a name="line.251"></a>
-<FONT color="green">252</FONT>            return getBundle(bundleName, (Locale) null);<a name="line.252"></a>
-<FONT color="green">253</FONT>        }<a name="line.253"></a>
-<FONT color="green">254</FONT>        <a name="line.254"></a>
-<FONT color="green">255</FONT>        /**<a name="line.255"></a>
-<FONT color="green">256</FONT>         * This method returns a ResourceBundle for the given bundle name<a name="line.256"></a>
-<FONT color="green">257</FONT>         * and the given Locale.<a name="line.257"></a>
-<FONT color="green">258</FONT>         *<a name="line.258"></a>
-<FONT color="green">259</FONT>         * @param bundleName Name of bundle (or &lt;code&gt;null&lt;/code&gt; for the<a name="line.259"></a>
-<FONT color="green">260</FONT>         * default bundle).<a name="line.260"></a>
-<FONT color="green">261</FONT>         * @param locale The locale (or &lt;code&gt;null&lt;/code&gt; for the locale<a name="line.261"></a>
-<FONT color="green">262</FONT>         * indicated by the default language and country).<a name="line.262"></a>
-<FONT color="green">263</FONT>         * @return A localized ResourceBundle.<a name="line.263"></a>
-<FONT color="green">264</FONT>         */<a name="line.264"></a>
-<FONT color="green">265</FONT>        public ResourceBundle getBundle(String bundleName, Locale locale)<a name="line.265"></a>
-<FONT color="green">266</FONT>        {<a name="line.266"></a>
-<FONT color="green">267</FONT>            // Assure usable inputs.<a name="line.267"></a>
-<FONT color="green">268</FONT>            bundleName =<a name="line.268"></a>
-<FONT color="green">269</FONT>                (bundleName == null ? getDefaultBundleName() : bundleName.trim());<a name="line.269"></a>
-<FONT color="green">270</FONT>            if (locale == null)<a name="line.270"></a>
-<FONT color="green">271</FONT>            {<a name="line.271"></a>
-<FONT color="green">272</FONT>                locale = getDefaultLocale();<a name="line.272"></a>
-<FONT color="green">273</FONT>            }<a name="line.273"></a>
-<FONT color="green">274</FONT>            // Find/retrieve/cache bundle.<a name="line.274"></a>
-<FONT color="green">275</FONT>            ResourceBundle rb = null;<a name="line.275"></a>
-<FONT color="green">276</FONT>            HashMap bundlesByLocale = (HashMap) bundles.get(bundleName);<a name="line.276"></a>
-<FONT color="green">277</FONT>            if (bundlesByLocale != null)<a name="line.277"></a>
-<FONT color="green">278</FONT>            {<a name="line.278"></a>
-<FONT color="green">279</FONT>                // Cache of bundles by locale for the named bundle exists.<a name="line.279"></a>
-<FONT color="green">280</FONT>                // Check the cache for a bundle corresponding to locale.<a name="line.280"></a>
-<FONT color="green">281</FONT>                rb = (ResourceBundle) bundlesByLocale.get(locale);<a name="line.281"></a>
-<FONT color="green">282</FONT>                if (rb == null)<a name="line.282"></a>
-<FONT color="green">283</FONT>                {<a name="line.283"></a>
-<FONT color="green">284</FONT>                    // Not yet cached.<a name="line.284"></a>
-<FONT color="green">285</FONT>                    rb = cacheBundle(bundleName, locale);<a name="line.285"></a>
-<FONT color="green">286</FONT>                }<a name="line.286"></a>
-<FONT color="green">287</FONT>            }<a name="line.287"></a>
-<FONT color="green">288</FONT>            else<a name="line.288"></a>
-<FONT color="green">289</FONT>            {<a name="line.289"></a>
-<FONT color="green">290</FONT>                rb = cacheBundle(bundleName, locale);<a name="line.290"></a>
-<FONT color="green">291</FONT>            }<a name="line.291"></a>
-<FONT color="green">292</FONT>            return rb;<a name="line.292"></a>
-<FONT color="green">293</FONT>        }<a name="line.293"></a>
-<FONT color="green">294</FONT>        <a name="line.294"></a>
-<FONT color="green">295</FONT>        /**<a name="line.295"></a>
-<FONT color="green">296</FONT>         * Caches the named bundle for fast lookups.  This operation is<a name="line.296"></a>
-<FONT color="green">297</FONT>         * relatively expensive in terms of memory use, but is optimized<a name="line.297"></a>
-<FONT color="green">298</FONT>         * for run-time speed in the usual case.<a name="line.298"></a>
-<FONT color="green">299</FONT>         *<a name="line.299"></a>
-<FONT color="green">300</FONT>         * @exception MissingResourceException Bundle not found.<a name="line.300"></a>
-<FONT color="green">301</FONT>         */<a name="line.301"></a>
-<FONT color="green">302</FONT>        private synchronized ResourceBundle cacheBundle(<a name="line.302"></a>
-<FONT color="green">303</FONT>            String bundleName,<a name="line.303"></a>
-<FONT color="green">304</FONT>            Locale locale)<a name="line.304"></a>
-<FONT color="green">305</FONT>            throws MissingResourceException<a name="line.305"></a>
-<FONT color="green">306</FONT>        {<a name="line.306"></a>
-<FONT color="green">307</FONT>            HashMap bundlesByLocale = (HashMap) bundles.get(bundleName);<a name="line.307"></a>
-<FONT color="green">308</FONT>            ResourceBundle rb =<a name="line.308"></a>
-<FONT color="green">309</FONT>                (bundlesByLocale == null<a name="line.309"></a>
-<FONT color="green">310</FONT>                    ? null<a name="line.310"></a>
-<FONT color="green">311</FONT>                    : (ResourceBundle) bundlesByLocale.get(locale));<a name="line.311"></a>
-<FONT color="green">312</FONT>            if (rb == null)<a name="line.312"></a>
-<FONT color="green">313</FONT>            {<a name="line.313"></a>
-<FONT color="green">314</FONT>                bundlesByLocale =<a name="line.314"></a>
-<FONT color="green">315</FONT>                    (bundlesByLocale == null<a name="line.315"></a>
-<FONT color="green">316</FONT>                        ? new HashMap(3)<a name="line.316"></a>
-<FONT color="green">317</FONT>                        : new HashMap(bundlesByLocale));<a name="line.317"></a>
-<FONT color="green">318</FONT>                try<a name="line.318"></a>
-<FONT color="green">319</FONT>                {<a name="line.319"></a>
-<FONT color="green">320</FONT>                    rb = ResourceBundle.getBundle(bundleName, locale);<a name="line.320"></a>
-<FONT color="green">321</FONT>                }<a name="line.321"></a>
-<FONT color="green">322</FONT>                catch (MissingResourceException e)<a name="line.322"></a>
-<FONT color="green">323</FONT>                {<a name="line.323"></a>
-<FONT color="green">324</FONT>                    rb = findBundleByLocale(bundleName, locale, bundlesByLocale);<a name="line.324"></a>
-<FONT color="green">325</FONT>                    if (rb == null)<a name="line.325"></a>
-<FONT color="green">326</FONT>                    {<a name="line.326"></a>
-<FONT color="green">327</FONT>                        throw (MissingResourceException) e.fillInStackTrace();<a name="line.327"></a>
-<FONT color="green">328</FONT>                    }<a name="line.328"></a>
-<FONT color="green">329</FONT>                }<a name="line.329"></a>
-<FONT color="green">330</FONT>                if (rb != null)<a name="line.330"></a>
-<FONT color="green">331</FONT>                {<a name="line.331"></a>
-<FONT color="green">332</FONT>                    // Cache bundle.<a name="line.332"></a>
-<FONT color="green">333</FONT>                    bundlesByLocale.put(rb.getLocale(), rb);<a name="line.333"></a>
-<FONT color="green">334</FONT>                    HashMap bundlesByName = new HashMap(bundles);<a name="line.334"></a>
-<FONT color="green">335</FONT>                    bundlesByName.put(bundleName, bundlesByLocale);<a name="line.335"></a>
-<FONT color="green">336</FONT>                    this.bundles = bundlesByName;<a name="line.336"></a>
-<FONT color="green">337</FONT>                }<a name="line.337"></a>
-<FONT color="green">338</FONT>            }<a name="line.338"></a>
-<FONT color="green">339</FONT>            return rb;<a name="line.339"></a>
-<FONT color="green">340</FONT>        }<a name="line.340"></a>
-<FONT color="green">341</FONT>        <a name="line.341"></a>
-<FONT color="green">342</FONT>        /**<a name="line.342"></a>
-<FONT color="green">343</FONT>         * &lt;p&gt;Retrieves the bundle most closely matching first against the<a name="line.343"></a>
-<FONT color="green">344</FONT>         * supplied inputs, then against the defaults.&lt;/p&gt;<a name="line.344"></a>
-<FONT color="green">345</FONT>         *<a name="line.345"></a>
-<FONT color="green">346</FONT>         * &lt;p&gt;Use case: some clients send a HTTP Accept-Language header<a name="line.346"></a>
-<FONT color="green">347</FONT>         * with a value of only the language to use<a name="line.347"></a>
-<FONT color="green">348</FONT>         * (i.e. "Accept-Language: en"), and neglect to include a country.<a name="line.348"></a>
-<FONT color="green">349</FONT>         * When there is no bundle for the requested language, this method<a name="line.349"></a>
-<FONT color="green">350</FONT>         * can be called to try the default country (checking internally<a name="line.350"></a>
-<FONT color="green">351</FONT>         * to assure the requested criteria matches the default to avoid<a name="line.351"></a>
-<FONT color="green">352</FONT>         * disconnects between language and country).&lt;/p&gt;<a name="line.352"></a>
-<FONT color="green">353</FONT>         *<a name="line.353"></a>
-<FONT color="green">354</FONT>         * &lt;p&gt;Since we're really just guessing at possible bundles to use,<a name="line.354"></a>
-<FONT color="green">355</FONT>         * we don't ever throw &lt;code&gt;MissingResourceException&lt;/code&gt;.&lt;/p&gt;<a name="line.355"></a>
-<FONT color="green">356</FONT>         */<a name="line.356"></a>
-<FONT color="green">357</FONT>        private ResourceBundle findBundleByLocale(<a name="line.357"></a>
-<FONT color="green">358</FONT>            String bundleName,<a name="line.358"></a>
-<FONT color="green">359</FONT>            Locale locale,<a name="line.359"></a>
-<FONT color="green">360</FONT>            Map bundlesByLocale)<a name="line.360"></a>
-<FONT color="green">361</FONT>        {<a name="line.361"></a>
-<FONT color="green">362</FONT>            ResourceBundle rb = null;<a name="line.362"></a>
-<FONT color="green">363</FONT>            if (!StringUtils.isNotEmpty(locale.getCountry())<a name="line.363"></a>
-<FONT color="green">364</FONT>                &amp;&amp; defaultLanguage.equals(locale.getLanguage()))<a name="line.364"></a>
-<FONT color="green">365</FONT>            {<a name="line.365"></a>
-<FONT color="green">366</FONT>                /*<a name="line.366"></a>
-<FONT color="green">367</FONT>                 *            category.debug("Requested language '" + locale.getLanguage() +<a name="line.367"></a>
-<FONT color="green">368</FONT>                 *                           "' matches default: Attempting to guess bundle " +<a name="line.368"></a>
-<FONT color="green">369</FONT>                 *                           "using default country '" + defaultCountry + '\'');<a name="line.369"></a>
-<FONT color="green">370</FONT>                 */<a name="line.370"></a>
-<FONT color="green">371</FONT>                Locale withDefaultCountry =<a name="line.371"></a>
-<FONT color="green">372</FONT>                    new Locale(locale.getLanguage(), defaultCountry);<a name="line.372"></a>
-<FONT color="green">373</FONT>                rb = (ResourceBundle) bundlesByLocale.get(withDefaultCountry);<a name="line.373"></a>
-<FONT color="green">374</FONT>                if (rb == null)<a name="line.374"></a>
-<FONT color="green">375</FONT>                {<a name="line.375"></a>
-<FONT color="green">376</FONT>                    rb = getBundleIgnoreException(bundleName, withDefaultCountry);<a name="line.376"></a>
-<FONT color="green">377</FONT>                }<a name="line.377"></a>
-<FONT color="green">378</FONT>            }<a name="line.378"></a>
-<FONT color="green">379</FONT>            else if (<a name="line.379"></a>
-<FONT color="green">380</FONT>                !StringUtils.isNotEmpty(locale.getLanguage())<a name="line.380"></a>
-<FONT color="green">381</FONT>                    &amp;&amp; defaultCountry.equals(locale.getCountry()))<a name="line.381"></a>
-<FONT color="green">382</FONT>            {<a name="line.382"></a>
-<FONT color="green">383</FONT>                Locale withDefaultLanguage =<a name="line.383"></a>
-<FONT color="green">384</FONT>                    new Locale(defaultLanguage, locale.getCountry());<a name="line.384"></a>
-<FONT color="green">385</FONT>                rb = (ResourceBundle) bundlesByLocale.get(withDefaultLanguage);<a name="line.385"></a>
-<FONT color="green">386</FONT>                if (rb == null)<a name="line.386"></a>
-<FONT color="green">387</FONT>                {<a name="line.387"></a>
-<FONT color="green">388</FONT>                    rb = getBundleIgnoreException(bundleName, withDefaultLanguage);<a name="line.388"></a>
-<FONT color="green">389</FONT>                }<a name="line.389"></a>
-<FONT color="green">390</FONT>            }<a name="line.390"></a>
-<FONT color="green">391</FONT>            if (rb == null &amp;&amp; !defaultLocale.equals(locale))<a name="line.391"></a>
-<FONT color="green">392</FONT>            {<a name="line.392"></a>
-<FONT color="green">393</FONT>                rb = getBundleIgnoreException(bundleName, defaultLocale);<a name="line.393"></a>
-<FONT color="green">394</FONT>            }<a name="line.394"></a>
-<FONT color="green">395</FONT>            return rb;<a name="line.395"></a>
-<FONT color="green">396</FONT>        }<a name="line.396"></a>
-<FONT color="green">397</FONT>        <a name="line.397"></a>
-<FONT color="green">398</FONT>        /**<a name="line.398"></a>
-<FONT color="green">399</FONT>         * Retrieves the bundle using the<a name="line.399"></a>
-<FONT color="green">400</FONT>         * &lt;code&gt;ResourceBundle.getBundle(String, Locale)&lt;/code&gt; method,<a name="line.400"></a>
-<FONT color="green">401</FONT>         * returning &lt;code&gt;null&lt;/code&gt; instead of throwing<a name="line.401"></a>
-<FONT color="green">402</FONT>         * &lt;code&gt;MissingResourceException&lt;/code&gt;.<a name="line.402"></a>
-<FONT color="green">403</FONT>         */<a name="line.403"></a>
-<FONT color="green">404</FONT>        private final ResourceBundle getBundleIgnoreException(<a name="line.404"></a>
-<FONT color="green">405</FONT>            String bundleName,<a name="line.405"></a>
-<FONT color="green">406</FONT>            Locale locale)<a name="line.406"></a>
-<FONT color="green">407</FONT>        {<a name="line.407"></a>
-<FONT color="green">408</FONT>            try<a name="line.408"></a>
-<FONT color="green">409</FONT>            {<a name="line.409"></a>
-<FONT color="green">410</FONT>                return ResourceBundle.getBundle(bundleName, locale);<a name="line.410"></a>
-<FONT color="green">411</FONT>            }<a name="line.411"></a>
-<FONT color="green">412</FONT>            catch (MissingResourceException ignored)<a name="line.412"></a>
-<FONT color="green">413</FONT>            {<a name="line.413"></a>
-<FONT color="green">414</FONT>                return null;<a name="line.414"></a>
-<FONT color="green">415</FONT>            }<a name="line.415"></a>
-<FONT color="green">416</FONT>        }<a name="line.416"></a>
-<FONT color="green">417</FONT>        <a name="line.417"></a>
-<FONT color="green">418</FONT>        /**<a name="line.418"></a>
-<FONT color="green">419</FONT>         * This method sets the name of the first bundle in the search<a name="line.419"></a>
-<FONT color="green">420</FONT>         * list (the "default" bundle).<a name="line.420"></a>
-<FONT color="green">421</FONT>         *<a name="line.421"></a>
-<FONT color="green">422</FONT>         * @param defaultBundle Name of default bundle.<a name="line.422"></a>
-<FONT color="green">423</FONT>         */<a name="line.423"></a>
-<FONT color="green">424</FONT>        public void setBundle(String defaultBundle)<a name="line.424"></a>
-<FONT color="green">425</FONT>        {<a name="line.425"></a>
-<FONT color="green">426</FONT>            if (bundleNames.length &gt; 0)<a name="line.426"></a>
-<FONT color="green">427</FONT>            {<a name="line.427"></a>
-<FONT color="green">428</FONT>                bundleNames[0] = defaultBundle;<a name="line.428"></a>
-<FONT color="green">429</FONT>            }<a name="line.429"></a>
-<FONT color="green">430</FONT>            else<a name="line.430"></a>
-<FONT color="green">431</FONT>            {<a name="line.431"></a>
-<FONT color="green">432</FONT>                synchronized (this)<a name="line.432"></a>
-<FONT color="green">433</FONT>                {<a name="line.433"></a>
-<FONT color="green">434</FONT>                    if (bundleNames.length &lt;= 0)<a name="line.434"></a>
-<FONT color="green">435</FONT>                    {<a name="line.435"></a>
-<FONT color="green">436</FONT>                        bundleNames = new String[] { defaultBundle };<a name="line.436"></a>
-<FONT color="green">437</FONT>                    }<a name="line.437"></a>
-<FONT color="green">438</FONT>                }<a name="line.438"></a>
-<FONT color="green">439</FONT>            }<a name="line.439"></a>
-<FONT color="green">440</FONT>        }<a name="line.440"></a>
-<FONT color="green">441</FONT>        <a name="line.441"></a>
-<FONT color="green">442</FONT>        /**<a name="line.442"></a>
-<FONT color="green">443</FONT>         * @exception MissingResourceException Specified key cannot be matched.<a name="line.443"></a>
-<FONT color="green">444</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#getString(String, Locale, String)<a name="line.444"></a>
-<FONT color="green">445</FONT>         */<a name="line.445"></a>
-<FONT color="green">446</FONT>        public String getString(String bundleName, Locale locale, String key)<a name="line.446"></a>
-<FONT color="green">447</FONT>          throws MissingResourceException<a name="line.447"></a>
-<FONT color="green">448</FONT>        {<a name="line.448"></a>
-<FONT color="green">449</FONT>            String value = null;<a name="line.449"></a>
-<FONT color="green">450</FONT>            if (locale == null)<a name="line.450"></a>
-<FONT color="green">451</FONT>            {<a name="line.451"></a>
-<FONT color="green">452</FONT>                locale = getDefaultLocale();<a name="line.452"></a>
-<FONT color="green">453</FONT>            }<a name="line.453"></a>
-<FONT color="green">454</FONT>            // Look for text in requested bundle.<a name="line.454"></a>
-<FONT color="green">455</FONT>            ResourceBundle rb = getBundle(bundleName, locale);<a name="line.455"></a>
-<FONT color="green">456</FONT>            value = getStringOrNull(rb, key);<a name="line.456"></a>
-<FONT color="green">457</FONT>            // Look for text in list of default bundles.<a name="line.457"></a>
-<FONT color="green">458</FONT>            if (value == null &amp;&amp; bundleNames.length &gt; 0)<a name="line.458"></a>
-<FONT color="green">459</FONT>            {<a name="line.459"></a>
-<FONT color="green">460</FONT>                String name;<a name="line.460"></a>
-<FONT color="green">461</FONT>                for (int i = 0; i &lt; bundleNames.length; i++)<a name="line.461"></a>
-<FONT color="green">462</FONT>                {<a name="line.462"></a>
-<FONT color="green">463</FONT>                    name = bundleNames[i];<a name="line.463"></a>
-<FONT color="green">464</FONT>                    //System.out.println("getString(): name=" + name +<a name="line.464"></a>
-<FONT color="green">465</FONT>                    //                   ", locale=" + locale + ", i=" + i);<a name="line.465"></a>
-<FONT color="green">466</FONT>                    if (!name.equals(bundleName))<a name="line.466"></a>
-<FONT color="green">467</FONT>                    {<a name="line.467"></a>
-<FONT color="green">468</FONT>                        rb = getBundle(name, locale);<a name="line.468"></a>
-<FONT color="green">469</FONT>                        value = getStringOrNull(rb, key);<a name="line.469"></a>
-<FONT color="green">470</FONT>                        if (value != null)<a name="line.470"></a>
-<FONT color="green">471</FONT>                        {<a name="line.471"></a>
-<FONT color="green">472</FONT>                            locale = rb.getLocale();<a name="line.472"></a>
-<FONT color="green">473</FONT>                            break;<a name="line.473"></a>
-<FONT color="green">474</FONT>                        }<a name="line.474"></a>
-<FONT color="green">475</FONT>                    }<a name="line.475"></a>
-<FONT color="green">476</FONT>                }<a name="line.476"></a>
-<FONT color="green">477</FONT>            }<a name="line.477"></a>
-<FONT color="green">478</FONT>            if (value == null)<a name="line.478"></a>
-<FONT color="green">479</FONT>            {<a name="line.479"></a>
-<FONT color="green">480</FONT>                String loc = locale.toString();<a name="line.480"></a>
-<FONT color="green">481</FONT>                String mesg =<a name="line.481"></a>
-<FONT color="green">482</FONT>                    LocalizationService.SERVICE_NAME<a name="line.482"></a>
-<FONT color="green">483</FONT>                        + " noticed missing resource: "<a name="line.483"></a>
-<FONT color="green">484</FONT>                        + "bundleName="<a name="line.484"></a>
-<FONT color="green">485</FONT>                        + bundleName<a name="line.485"></a>
-<FONT color="green">486</FONT>                        + ", locale="<a name="line.486"></a>
-<FONT color="green">487</FONT>                        + loc<a name="line.487"></a>
-<FONT color="green">488</FONT>                        + ", key="<a name="line.488"></a>
-<FONT color="green">489</FONT>                        + key;<a name="line.489"></a>
-<FONT color="green">490</FONT>                getLogger().debug(mesg);<a name="line.490"></a>
-<FONT color="green">491</FONT>                // Text not found in requested or default bundles.<a name="line.491"></a>
-<FONT color="green">492</FONT>                throw new MissingResourceException(mesg, bundleName, key);<a name="line.492"></a>
-<FONT color="green">493</FONT>            }<a name="line.493"></a>
-<FONT color="green">494</FONT>            return value;<a name="line.494"></a>
-<FONT color="green">495</FONT>        }<a name="line.495"></a>
-<FONT color="green">496</FONT>        <a name="line.496"></a>
-<FONT color="green">497</FONT>        /**<a name="line.497"></a>
-<FONT color="green">498</FONT>         * Gets localized text from a bundle if it's there.  Otherwise,<a name="line.498"></a>
-<FONT color="green">499</FONT>         * returns &lt;code&gt;null&lt;/code&gt; (ignoring a possible<a name="line.499"></a>
-<FONT color="green">500</FONT>         * &lt;code&gt;MissingResourceException&lt;/code&gt;).<a name="line.500"></a>
-<FONT color="green">501</FONT>         */<a name="line.501"></a>
-<FONT color="green">502</FONT>        protected final String getStringOrNull(ResourceBundle rb, String key)<a name="line.502"></a>
-<FONT color="green">503</FONT>        {<a name="line.503"></a>
-<FONT color="green">504</FONT>            if (rb != null)<a name="line.504"></a>
-<FONT color="green">505</FONT>            {<a name="line.505"></a>
-<FONT color="green">506</FONT>                try<a name="line.506"></a>
-<FONT color="green">507</FONT>                {<a name="line.507"></a>
-<FONT color="green">508</FONT>                    return rb.getString(key);<a name="line.508"></a>
-<FONT color="green">509</FONT>                }<a name="line.509"></a>
-<FONT color="green">510</FONT>                catch (MissingResourceException ignored)<a name="line.510"></a>
-<FONT color="green">511</FONT>                {<a name="line.511"></a>
-<FONT color="green">512</FONT>                    // ignore<a name="line.512"></a>
-<FONT color="green">513</FONT>                }<a name="line.513"></a>
-<FONT color="green">514</FONT>            }<a name="line.514"></a>
-<FONT color="green">515</FONT>            return null;<a name="line.515"></a>
-<FONT color="green">516</FONT>        }<a name="line.516"></a>
-<FONT color="green">517</FONT>        <a name="line.517"></a>
-<FONT color="green">518</FONT>        /**<a name="line.518"></a>
-<FONT color="green">519</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#format(String, Locale, String, Object)<a name="line.519"></a>
-<FONT color="green">520</FONT>         */<a name="line.520"></a>
-<FONT color="green">521</FONT>        public String format(<a name="line.521"></a>
-<FONT color="green">522</FONT>            String bundleName,<a name="line.522"></a>
-<FONT color="green">523</FONT>            Locale locale,<a name="line.523"></a>
-<FONT color="green">524</FONT>            String key,<a name="line.524"></a>
-<FONT color="green">525</FONT>            Object arg1)<a name="line.525"></a>
-<FONT color="green">526</FONT>        {<a name="line.526"></a>
-<FONT color="green">527</FONT>            return format(bundleName, locale, key, new Object[] { arg1 });<a name="line.527"></a>
-<FONT color="green">528</FONT>        }<a name="line.528"></a>
-<FONT color="green">529</FONT>        <a name="line.529"></a>
-<FONT color="green">530</FONT>        /**<a name="line.530"></a>
-<FONT color="green">531</FONT>         * @see org.apache.fulcrum.localization.SimpleLocalizationService#format(String, Locale, String, Object, Object)<a name="line.531"></a>
-<FONT color="green">532</FONT>         */<a name="line.532"></a>
-<FONT color="green">533</FONT>        public String format(<a name="line.533"></a>
-<FONT color="green">534</FONT>            String bundleName,<a name="line.534"></a>
-<FONT color="green">535</FONT>            Locale locale,<a name="line.535"></a>
-<FONT color="green">536</FONT>            String key,<a name="line.536"></a>
-<FONT color="green">537</FONT>            Object arg1,<a name="line.537"></a>
-<FONT color="green">538</FONT>            Object arg2)<a name="line.538"></a>
-<FONT color="green">539</FONT>        {<a name="line.539"></a>
-<FONT color="green">540</FONT>            return format(bundleName, locale, key, new Object[] { arg1, arg2 });<a name="line.540"></a>
-<FONT color="green">541</FONT>        }<a name="line.541"></a>
-<FONT color="green">542</FONT>        <a name="line.542"></a>
-<FONT color="green">543</FONT>        /**<a name="line.543"></a>
-<FONT color="green">544</FONT>         * Looks up the value for &lt;code&gt;key&lt;/code&gt; in the<a name="line.544"></a>
-<FONT color="green">545</FONT>         * &lt;code&gt;ResourceBundle&lt;/code&gt; referenced by<a name="line.545"></a>
-<FONT color="green">546</FONT>         * &lt;code&gt;bundleName&lt;/code&gt;, then formats that value for the<a name="line.546"></a>
-<FONT color="green">547</FONT>         * specified &lt;code&gt;Locale&lt;/code&gt; using &lt;code&gt;args&lt;/code&gt;.<a name="line.547"></a>
-<FONT color="green">548</FONT>         *<a name="line.548"></a>
-<FONT color="green">549</FONT>         * @return Localized, formatted text identified by<a name="line.549"></a>
-<FONT color="green">550</FONT>         * &lt;code&gt;key&lt;/code&gt;.<a name="line.550"></a>
-<FONT color="green">551</FONT>         */<a name="line.551"></a>
-<FONT color="green">552</FONT>        public String format(<a name="line.552"></a>
-<FONT color="green">553</FONT>            String bundleName,<a name="line.553"></a>
-<FONT color="green">554</FONT>            Locale locale,<a name="line.554"></a>
-<FONT color="green">555</FONT>            String key,<a name="line.555"></a>
-<FONT color="green">556</FONT>            Object[] args)<a name="line.556"></a>
-<FONT color="green">557</FONT>        {<a name="line.557"></a>
-<FONT color="green">558</FONT>            // When formatting Date objects and such, MessageFormat<a name="line.558"></a>
-<FONT color="green">559</FONT>            // cannot have a null Locale.<a name="line.559"></a>
-<FONT color="green">560</FONT>            Locale formatLocale = (locale == null) ? getDefaultLocale() : locale; <a name="line.560"></a>
-<FONT color="green">561</FONT>            String value = getString(bundleName, locale, key);<a name="line.561"></a>
-<FONT color="green">562</FONT>            <a name="line.562"></a>
-<FONT color="green">563</FONT>            Object[] formatArgs = (args == null) ? NO_ARGS : args;<a name="line.563"></a>
-<FONT color="green">564</FONT>            <a name="line.564"></a>
-<FONT color="green">565</FONT>            MessageFormat messageFormat = new MessageFormat(value, formatLocale);<a name="line.565"></a>
-<FONT color="green">566</FONT>            return messageFormat.format(formatArgs);<a name="line.566"></a>
-<FONT color="green">567</FONT>        }<a name="line.567"></a>
-<FONT color="green">568</FONT>    }<a name="line.568"></a>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<title>Source code</title>
+<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
+</head>
+<body>
+<div class="sourceContainer">
+<pre><span class="sourceLineNo">001</span>package org.apache.fulcrum.localization;<a name="line.1"></a>
+<span class="sourceLineNo">002</span><a name="line.2"></a>
+<span class="sourceLineNo">003</span>/*<a name="line.3"></a>
+<span class="sourceLineNo">004</span> * Licensed to the Apache Software Foundation (ASF) under one<a name="line.4"></a>
+<span class="sourceLineNo">005</span> * or more contributor license agreements.  See the NOTICE file<a name="line.5"></a>
+<span class="sourceLineNo">006</span> * distributed with this work for additional information<a name="line.6"></a>
+<span class="sourceLineNo">007</span> * regarding copyright ownership.  The ASF licenses this file<a name="line.7"></a>
+<span class="sourceLineNo">008</span> * to you under the Apache License, Version 2.0 (the<a name="line.8"></a>
+<span class="sourceLineNo">009</span> * "License"); you may not use this file except in compliance<a name="line.9"></a>
+<span class="sourceLineNo">010</span> * with the License.  You may obtain a copy of the License at<a name="line.10"></a>
+<span class="sourceLineNo">011</span> *<a name="line.11"></a>
+<span class="sourceLineNo">012</span> *   http://www.apache.org/licenses/LICENSE-2.0<a name="line.12"></a>
+<span class="sourceLineNo">013</span> *<a name="line.13"></a>
+<span class="sourceLineNo">014</span> * Unless required by applicable law or agreed to in writing,<a name="line.14"></a>
+<span class="sourceLineNo">015</span> * software distributed under the License is distributed on an<a name="line.15"></a>
+<span class="sourceLineNo">016</span> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.16"></a>
+<span class="sourceLineNo">017</span> * KIND, either express or implied.  See the License for the<a name="line.17"></a>
+<span class="sourceLineNo">018</span> * specific language governing permissions and limitations<a name="line.18"></a>
+<span class="sourceLineNo">019</span> * under the License.<a name="line.19"></a>
+<span class="sourceLineNo">020</span> */<a name="line.20"></a>
+<span class="sourceLineNo">021</span><a name="line.21"></a>
+<span class="sourceLineNo">022</span>import java.text.MessageFormat;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.util.HashMap;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import java.util.Locale;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import java.util.Map;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import java.util.MissingResourceException;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import java.util.ResourceBundle;<a name="line.27"></a>
+<span class="sourceLineNo">028</span><a name="line.28"></a>
+<span class="sourceLineNo">029</span>import org.apache.avalon.framework.activity.Initializable;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.avalon.framework.configuration.Configurable;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import org.apache.avalon.framework.configuration.Configuration;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import org.apache.avalon.framework.configuration.ConfigurationException;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import org.apache.avalon.framework.logger.AbstractLogEnabled;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import org.apache.commons.lang3.StringUtils;<a name="line.34"></a>
+<span class="sourceLineNo">035</span><a name="line.35"></a>
+<span class="sourceLineNo">036</span>/**<a name="line.36"></a>
+<span class="sourceLineNo">037</span> * &lt;p&gt;<a name="line.37"></a>
+<span class="sourceLineNo">038</span> * This class is the single point of access to all localization<a name="line.38"></a>
+<span class="sourceLineNo">039</span> * resources.  It caches different ResourceBundles for different<a name="line.39"></a>
+<span class="sourceLineNo">040</span> * Locales.<a name="line.40"></a>
+<span class="sourceLineNo">041</span> * &lt;/p&gt;<a name="line.41"></a>
+<span class="sourceLineNo">042</span> *<a name="line.42"></a>
+<span class="sourceLineNo">043</span> * &lt;p&gt;Usage example:&lt;/p&gt;<a name="line.43"></a>
+<span class="sourceLineNo">044</span> *<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * &lt;pre&gt;<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * &lt;code&gt;<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * SimpleLocalizationService ls = (SimpleLocalizationService) TurbineServices<a name="line.47"></a>
+<span class="sourceLineNo">048</span> *     .getInstance().getService(SimpleLocalizationService.SERVICE_NAME);<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * &lt;/code&gt;<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * &lt;/pre&gt;<a name="line.50"></a>
+<span class="sourceLineNo">051</span> *<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * &lt;p&gt;<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * Then call {@link #getString(String, Locale, String)}, or one of<a name="line.53"></a>
+<span class="sourceLineNo">054</span> * two methods to retrieve a ResourceBundle:<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * &lt;/p&gt;<a name="line.55"></a>
+<span class="sourceLineNo">056</span> *<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * &lt;ul&gt;<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * &lt;li&gt;getBundle("MyBundleName")&lt;/li&gt;<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * &lt;li&gt;getBundle("MyBundleName", Locale)&lt;/li&gt;<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * &lt;li&gt;etc.&lt;/li&gt;<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * &lt;/ul&gt;<a name="line.61"></a>
+<span class="sourceLineNo">062</span> *<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * @author &lt;a href="mailto:jm@mediaphil.de"&gt;Jonas Maurus&lt;/a&gt;<a name="line.63"></a>
+<span class="sourceLineNo">064</span> * @author &lt;a href="mailto:jon@latchkey.com"&gt;Jon S. Stevens&lt;/a&gt;<a name="line.64"></a>
+<span class="sourceLineNo">065</span> * @author &lt;a href="mailto:novalidemail@foo.com"&gt;Frank Y. Kim&lt;/a&gt;<a name="line.65"></a>
+<span class="sourceLineNo">066</span> * @author &lt;a href="mailto:dlr@finemaltcoding.com"&gt;Daniel Rall&lt;/a&gt;<a name="line.66"></a>
+<span class="sourceLineNo">067</span> * @author &lt;a href="mailto:leonardr@collab.net"&gt;Leonard Richardson&lt;/a&gt;<a name="line.67"></a>
+<span class="sourceLineNo">068</span> * @author &lt;a href="mailto:mcconnell@apache.org"&gt;Stephen McConnell&lt;/a&gt;<a name="line.68"></a>
+<span class="sourceLineNo">069</span> * @author &lt;a href="mailto:tv@apache.org"&gt;Thomas Vandahl&lt;/a&gt;<a name="line.69"></a>
+<span class="sourceLineNo">070</span> * @version $Id: DefaultLocalizationService.java 535465 2007-05-05 06:58:06Z tv $<a name="line.70"></a>
+<span class="sourceLineNo">071</span> * <a name="line.71"></a>
+<span class="sourceLineNo">072</span> * avalon.component name="localization" lifestyle="singleton"<a name="line.72"></a>
+<span class="sourceLineNo">073</span> * avalon.service type="org.apache.fulcrum.localization.SimpleLocalizationService"<a name="line.73"></a>
+<span class="sourceLineNo">074</span> */<a name="line.74"></a>
+<span class="sourceLineNo">075</span>public class SimpleLocalizationServiceImpl<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    extends AbstractLogEnabled<a name="line.76"></a>
+<span class="sourceLineNo">077</span>    implements SimpleLocalizationService, Configurable, Initializable<a name="line.77"></a>
+<span class="sourceLineNo">078</span>{<a name="line.78"></a>
+<span class="sourceLineNo">079</span>    /** Key Prefix for our bundles */<a name="line.79"></a>
+<span class="sourceLineNo">080</span>    private static final String BUNDLES = "bundles";<a name="line.80"></a>
+<span class="sourceLineNo">081</span>    <a name="line.81"></a>
+<span class="sourceLineNo">082</span>    /**<a name="line.82"></a>
+<span class="sourceLineNo">083</span>     * The value to pass to &lt;code&gt;MessageFormat&lt;/code&gt; if a<a name="line.83"></a>
+<span class="sourceLineNo">084</span>     * &lt;code&gt;null&lt;/code&gt; reference is passed to &lt;code&gt;format()&lt;/code&gt;.<a name="line.84"></a>
+<span class="sourceLineNo">085</span>     */<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    private static final Object[] NO_ARGS = new Object[0];<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    <a name="line.87"></a>
+<span class="sourceLineNo">088</span>    /**<a name="line.88"></a>
+<span class="sourceLineNo">089</span>     * Bundle name keys a HashMap of the ResourceBundles in this<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     * service (which is in turn keyed by Locale).<a name="line.90"></a>
+<span class="sourceLineNo">091</span>     */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    private HashMap&lt;String, HashMap&lt;Locale, ResourceBundle&gt;&gt; bundles = null;<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    <a name="line.93"></a>
+<span class="sourceLineNo">094</span>    /**<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     * The list of default bundles to search.<a name="line.95"></a>
+<span class="sourceLineNo">096</span>     */<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    private String[] bundleNames = null;<a name="line.97"></a>
+<span class="sourceLineNo">098</span><a name="line.98"></a>
+<span class="sourceLineNo">099</span>    /**<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     * The name of the default locale to use (includes language and<a name="line.100"></a>
+<span class="sourceLineNo">101</span>     * country).<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     */<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    private Locale defaultLocale = null;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    <a name="line.104"></a>
+<span class="sourceLineNo">105</span>    /** The name of the default language to use. */<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    private String defaultLanguage = null;<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    <a name="line.107"></a>
+<span class="sourceLineNo">108</span>    /** The name of the default country to use. */<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    private String defaultCountry = null;<a name="line.109"></a>
+<span class="sourceLineNo">110</span><a name="line.110"></a>
+<span class="sourceLineNo">111</span>    /**<a name="line.111"></a>
+<span class="sourceLineNo">112</span>     * Creates a new instance.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>     */<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    public SimpleLocalizationServiceImpl()<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        bundles = new HashMap&lt;String, HashMap&lt;Locale, ResourceBundle&gt;&gt;();<a name="line.116"></a>
+<span class="sourceLineNo">117</span>    }<a name="line.117"></a>
+<span class="sourceLineNo">118</span><a name="line.118"></a>
+<span class="sourceLineNo">119</span>    /**<a name="line.119"></a>
+<span class="sourceLineNo">120</span>     * Avalon lifecycle method<a name="line.120"></a>
+<span class="sourceLineNo">121</span>     * <a name="line.121"></a>
+<span class="sourceLineNo">122</span>     * {@link org.apache.avalon.framework.configuration.Configurable}<a name="line.122"></a>
+<span class="sourceLineNo">123</span>     * <a name="line.123"></a>
+<span class="sourceLineNo">124</span>     * @param conf the configuration<a name="line.124"></a>
+<span class="sourceLineNo">125</span>     * @throws ConfigurationException if failed to configure<a name="line.125"></a>
+<span class="sourceLineNo">126</span>     */<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    @Override<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        public void configure(Configuration conf) throws ConfigurationException<a name="line.128"></a>
+<span class="sourceLineNo">129</span>    {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>        Locale jvmDefault = Locale.getDefault();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>        defaultLanguage =<a name="line.131"></a>
+<span class="sourceLineNo">132</span>            conf<a name="line.132"></a>
+<span class="sourceLineNo">133</span>                .getAttribute(<a name="line.133"></a>
+<span class="sourceLineNo">134</span>                    "locale-default-language",<a name="line.134"></a>
+<span class="sourceLineNo">135</span>                    jvmDefault.getLanguage())<a name="line.135"></a>
+<span class="sourceLineNo">136</span>                .trim();<a name="line.136"></a>
+<span class="sourceLineNo">137</span>        defaultCountry =<a name="line.137"></a>
+<span class="sourceLineNo">138</span>            conf<a name="line.138"></a>
+<span class="sourceLineNo">139</span>                .getAttribute("locale-default-country", jvmDefault.getCountry())<a name="line.139"></a>
+<span class="sourceLineNo">140</span>                .trim();<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        // FIXME! need to add bundle names<a name="line.141"></a>
+<span class="sourceLineNo">142</span>        getLogger().info(<a name="line.142"></a>
+<span class="sourceLineNo">143</span>            "initialized lang="<a name="line.143"></a>
+<span class="sourceLineNo">144</span>                + defaultLanguage<a name="line.144"></a>
+<span class="sourceLineNo">145</span>                + " country="<a name="line.145"></a>
+<span class="sourceLineNo">146</span>                + defaultCountry);<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        final Configuration bundles = conf.getChild(BUNDLES, false);<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        if (bundles != null)<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>            Configuration[] nameVal = bundles.getChildren();<a name="line.150"></a>
+<span class="sourceLineNo">151</span>            String bundleName[] = new String[nameVal.length];<a name="line.151"></a>
+<span class="sourceLineNo">152</span>            for (int i = 0; i &lt; nameVal.length; i++)<a name="line.152"></a>
+<span class="sourceLineNo">153</span>            {<a name="line.153"></a>
+<span class="sourceLineNo">154</span>                String val = nameVal[i].getValue();<a name="line.154"></a>
+<span class="sourceLineNo">155</span>                getLogger().debug("Registered bundle " + val);<a name="line.155"></a>
+<span class="sourceLineNo">156</span>                bundleName[i] = val;<a name="line.156"></a>
+<span class="sourceLineNo">157</span>            }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>            initBundleNames(bundleName);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>        }<a name="line.159"></a>
+<span class="sourceLineNo">160</span>    }<a name="line.160"></a>
+<span class="sourceLineNo">161</span>    <a name="line.161"></a>
+<span class="sourceLineNo">162</span>    /**<a name="line.162"></a>
+<span class="sourceLineNo">163</span>     * Called the first time the Service is used.<a name="line.163"></a>
+<span class="sourceLineNo">164</span>     * <a name="line.164"></a>
+<span class="sourceLineNo">165</span>     * @throws Exception generic exception<a name="line.165"></a>
+<span class="sourceLineNo">166</span>     */<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    @Override<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        public void initialize() throws Exception<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    {<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        defaultLocale = new Locale(defaultLanguage, defaultCountry);<a name="line.170"></a>
+<span class="sourceLineNo">171</span>        if (getLogger().isInfoEnabled())<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>            getLogger().info("Localization Service is Initialized now..");<a name="line.173"></a>
+<span class="sourceLineNo">174</span>        }<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    }<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    <a name="line.176"></a>
+<span class="sourceLineNo">177</span>    /**<a name="line.177"></a>
+<span class="sourceLineNo">178</span>     * Initialize list of default bundle names.<a name="line.178"></a>
+<span class="sourceLineNo">179</span>     *<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     * @param intBundleNames set bundle names<a name="line.180"></a>
+<span class="sourceLineNo">181</span>     */<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    protected void initBundleNames(String[] intBundleNames)<a name="line.182"></a>
+<span class="sourceLineNo">183</span>    {<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        if (intBundleNames == null)<a name="line.184"></a>
+<span class="sourceLineNo">185</span>            bundleNames = new String[0];<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        else<a name="line.186"></a>
+<span class="sourceLineNo">187</span>                bundleNames = intBundleNames;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    }<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    <a name="line.189"></a>
+<span class="sourceLineNo">190</span>    /**<a name="line.190"></a>
+<span class="sourceLineNo">191</span>     * Retrieves the default language (specified in the config file).<a name="line.191"></a>
+<span class="sourceLineNo">192</span>     * <a name="line.192"></a>
+<span class="sourceLineNo">193</span>     * @return the default language<a name="line.193"></a>
+<span class="sourceLineNo">194</span>     */<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    @Override<a name="line.195"></a>
+<span class="sourceLineNo">196</span>        public String getDefaultLanguage()<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>        return defaultLanguage;<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    }<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    <a name="line.200"></a>
+<span class="sourceLineNo">201</span>    /**<a name="line.201"></a>
+<span class="sourceLineNo">202</span>     * Retrieves the default country (specified in the config file).<a name="line.202"></a>
+<span class="sourceLineNo">203</span>     * <a name="line.203"></a>
+<span class="sourceLineNo">204</span>     * @return the default country<a name="line.204"></a>
+<span class="sourceLineNo">205</span>     */<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    @Override<a name="line.206"></a>
+<span class="sourceLineNo">207</span>        public String getDefaultCountry()<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>        return defaultCountry;<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    }<a name="line.210"></a>
+<span class="sourceLineNo">211</span>    <a name="line.211"></a>
+<span class="sourceLineNo">212</span>    /**<a name="line.212"></a>
+<span class="sourceLineNo">213</span>     * Retrieves the default Locale (as created from default<a name="line.213"></a>
+<span class="sourceLineNo">214</span>     * language and default country).<a name="line.214"></a>
+<span class="sourceLineNo">215</span>     * <a name="line.215"></a>
+<span class="sourceLineNo">216</span>     * @return the default locale<a name="line.216"></a>
+<span class="sourceLineNo">217</span>     */<a name="line.217"></a>
+<span class="sourceLineNo">218</span>    @Override<a name="line.218"></a>
+<span class="sourceLineNo">219</span>        public Locale getDefaultLocale()<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>        return defaultLocale;<a name="line.221"></a>
+<span class="sourceLineNo">222</span>    }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>    /**<a name="line.224"></a>
+<span class="sourceLineNo">225</span>     * {@link org.apache.fulcrum.localization.SimpleLocalizationService#getDefaultBundleName()}<a name="line.225"></a>
+<span class="sourceLineNo">226</span>     * <a name="line.226"></a>
+<span class="sourceLineNo">227</span>     * @return the default bundle name<a name="line.227"></a>
+<span class="sourceLineNo">228</span>     */<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    @Override<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        public String getDefaultBundleName()<a name="line.230"></a>
+<span class="sourceLineNo">231</span>    {<a name="line.231"></a>
+<span class="sourceLineNo">232</span>        return (bundleNames.length &gt; 0 ? bundleNames[0] : "");<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    }<a name="line.233"></a>
+<span class="sourceLineNo">234</span>    <a name="line.234"></a>
+<span class="sourceLineNo">235</span>    /**<a name="line.235"></a>
+<span class="sourceLineNo">236</span>     * {@link org.apache.fulcrum.localization.SimpleLocalizationService#getBundleNames()}<a name="line.236"></a>
+<span class="sourceLineNo">237</span>     * <a name="line.237"></a>
+<span class="sourceLineNo">238</span>     * @return list of bundle names available<a name="line.238"></a>
+<span class="sourceLineNo">239</span>     */<a name="line.239"></a>
+<span class="sourceLineNo">240</span>    @Override<a name="line.240"></a>
+<span class="sourceLineNo">241</span>        public String[] getBundleNames()<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>        return bundleNames.clone();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    <a name="line.245"></a>
+<span class="sourceLineNo">246</span>    /**<a name="line.246"></a>
+<span class="sourceLineNo">247</span>     * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundle()<a name="line.247"></a>
+<span class="sourceLineNo">248</span>     * <a name="line.248"></a>
+<span class="sourceLineNo">249</span>     * @return the default resource bundle<a name="line.249"></a>
+<span class="sourceLineNo">250</span>     */<a name="line.250"></a>
+<span class="sourceLineNo">251</span>    @Override<a name="line.251"></a>
+<span class="sourceLineNo">252</span>        public ResourceBundle getBundle()<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        return getBundle(getDefaultBundleName(), (Locale) null);<a name="line.254"></a>
+<span class="sourceLineNo">255</span>    }<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    <a name="line.256"></a>
+<span class="sourceLineNo">257</span>    /**<a name="line.257"></a>
+<span class="sourceLineNo">258</span>     * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundle(java.lang.String)<a name="line.258"></a>
+<span class="sourceLineNo">259</span>     * <a name="line.259"></a>
+<span class="sourceLineNo">260</span>     * @param bundleName the name of a bundle<a name="line.260"></a>
+<span class="sourceLineNo">261</span>     * @return the resource bundle<a name="line.261"></a>
+<span class="sourceLineNo">262</span>     */<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    @Override<a name="line.263"></a>
+<span class="sourceLineNo">264</span>        public ResourceBundle getBundle(String bundleName)<a name="line.264"></a>
+<span class="sourceLineNo">265</span>    {<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        return getBundle(bundleName, (Locale) null);<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    }<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    <a name="line.268"></a>
+<span class="sourceLineNo">269</span>    /**<a name="line.269"></a>
+<span class="sourceLineNo">270</span>     * @see org.apache.fulcrum.localization.SimpleLocalizationService#getBundle(java.lang.String, java.util.Locale)<a name="line.270"></a>
+<span class="sourceLineNo">271</span>     * <a name="line.271"></a>
+<span class="sourceLineNo">272</span>     * This method returns a ResourceBundle for the given bundle name<a name="line.272"></a>
+<span class="sourceLineNo">273</span>     * and the given Locale.<a name="line.273"></a>
+<span class="sourceLineNo">274</span>     *<a name="line.274"></a>
+<span class="sourceLineNo">275</span>     * @param bundleName Name of bundle (or &lt;code&gt;null&lt;/code&gt; for the<a name="line.275"></a>
+<span class="sourceLineNo">276</span>     * default bundle).<a name="line.276"></a>
+<span class="sourceLineNo">277</span>     * @param locale The locale (or &lt;code&gt;null&lt;/code&gt; for the locale<a name="line.277"></a>
+<span class="sourceLineNo">278</span>     * indicated by the default language and country).<a name="line.278"></a>
+<span class="sourceLineNo">279</span>     * @return A localized ResourceBundle.<a name="line.279"></a>
+<span class="sourceLineNo">280</span>     */<a name="line.280"></a>
+<span class="sourceLineNo">281</span>    @Override<a name="line.281"></a>
+<span class="sourceLineNo">282</span>        public ResourceBundle getBundle(String bundleName, Locale locale)<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    {<a name="line.283"></a>
+<span class="sourceLineNo">284</span>        // Assure usable inputs.<a name="line.284"></a>
+<span class="sourceLineNo">285</span>        bundleName =<a name="line.285"></a>
+<span class="sourceLineNo">286</span>            (bundleName == null ? getDefaultBundleName() : bundleName.trim());<a name="line.286"></a>
+<span class="sourceLineNo">287</span>        if (locale == null)<a name="line.287"></a>
+<span class="sourceLineNo">288</span>        {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>            locale = getDefaultLocale();<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        }<a name="line.290"></a>
+<span class="sourceLineNo">291</span>        // Find/retrieve/cache bundle.<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        ResourceBundle rb = null;<a name="line.292"></a>
+<span class="sourceLineNo">293</span>        HashMap&lt;?, ?&gt; bundlesByLocale = (HashMap&lt;?, ?&gt;) bundles.get(bundleName);<a name="line.293"></a>
+<span class="sourceLineNo">294</span>        if (bundlesByLocale != null)<a name="line.294"></a>
+<span class="sourceLineNo">295</span>        {<a name="line.295"></a>
+<span class="sourceLineNo">296</span>            // Cache of bundles by locale for the named bundle exists.<a name="line.296"></a>
+<span class="sourceLineNo">297</span>            // Check the cache for a bundle corresponding to locale.<a name="line.297"></a>
+<span class="sourceLineNo">298</span>            rb = (ResourceBundle) bundlesByLocale.get(locale);<a name="line.298"></a>
+<span class="sourceLineNo">299</span>            if (rb == null)<a name="line.299"></a>
+<span class="sourceLineNo">300</span>            {<a name="line.300"></a>
+<span class="sourceLineNo">301</span>                // Not yet cached.<a name="line.301"></a>
+<span class="sourceLineNo">302</span>                rb = cacheBundle(bundleName, locale);<a name="line.302"></a>
+<span class="sourceLineNo">303</span>            }<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        }<a name="line.304"></a>
+<span class="sourceLineNo">305</span>        else<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        {<a name="line.306"></a>
+<span class="sourceLineNo">307</span>            rb = cacheBundle(bundleName, locale);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>        }<a name="line.308"></a>
+<span class="sourceLineNo">309</span>        return rb;<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    }<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    <a name="line.311"></a>
+<span class="sourceLineNo">312</span>    /**<a name="line.312"></a>
+<span class="sourceLineNo">313</span>     * Caches the named bundle for fast lookups.  This operation is<a name="line.313"></a>
+<span class="sourceLineNo">314</span>     * relatively expensive in terms of memory use, but is optimized<a name="line.314"></a>
+<span class="sourceLineNo">315</span>     * for run-time speed in the usual case.<a name="line.315"></a>
+<span class="sourceLineNo">316</span>     *<a name="line.316"></a>
+<span class="sourceLineNo">317</span>     * @param bundleName Name of bundle (or &lt;code&gt;null&lt;/code&gt; for the<a name="line.317"></a>
+<span class="sourceLineNo">318</span>     * default bundle).<a name="line.318"></a>
+<span class="sourceLineNo">319</span>     * @param locale The locale (or &lt;code&gt;null&lt;/code&gt; for the locale<a name="line.319"></a>
+<span class="sourceLineNo">320</span>     * indicated by the default language and country).<a name="line.320"></a>
+<span class="sourceLineNo">321</span>     * @throws MissingResourceException Bundle not found.<a name="line.321"></a>
+<span class="sourceLineNo">322</span>     * @return a localized resource bundle<a name="line.322"></a>
+<span class="sourceLineNo">323</span>     */<a name="line.323"></a>
+<span class="sourceLineNo">324</span>    private synchronized ResourceBundle cacheBundle(<a name="line.324"></a>
+<span class="sourceLineNo">325</span>        String bundleName,<a name="line.325"></a>
+<span class="sourceLineNo">326</span>        Locale locale)<a name="line.326"></a>
+<span class="sourceLineNo">327</span>        throws MissingResourceException<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    {<a name="line.328"></a>
+<span class="sourceLineNo">329</span>        HashMap&lt;Locale, ResourceBundle&gt; bundlesByLocale = (HashMap&lt;Locale, ResourceBundle&gt;) bundles.get(bundleName);<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        ResourceBundle rb =<a name="line.330"></a>
+<span class="sourceLineNo">331</span>            (bundlesByLocale == null<a name="line.331"></a>
+<span class="sourceLineNo">332</span>                ? null<a name="line.332"></a>
+<span class="sourceLineNo">333</span>                : (ResourceBundle) bundlesByLocale.get(locale));<a name="line.333"></a>
+<span class="sourceLineNo">334</span>        if (rb == null)<a name="line.334"></a>
+<span class="sourceLineNo">335</span>        {<a name="line.335"></a>
+<span class="sourceLineNo">336</span>            bundlesByLocale =<a name="line.336"></a>
+<span class="sourceLineNo">337</span>                (bundlesByLocale == null<a name="line.337"></a>
+<span class="sourceLineNo">338</span>                    ? new HashMap&lt;Locale, ResourceBundle&gt;(3)<a name="line.338"></a>
+<span class="sourceLineNo">339</span>                    : new HashMap&lt;Locale, ResourceBundle&gt;(bundlesByLocale));<a name="line.339"></a>
+<span class="sourceLineNo">340</span>            try<a name="line.340"></a>
+<span class="sourceLineNo">341</span>            {<a name="line.341"></a>
+<span class="sourceLineNo">342</span>                rb = ResourceBundle.getBundle(bundleName, locale);<a name="line.342"></a>
+<span class="sourceLineNo">343</span>            }<a name="line.343"></a>
+<span class="sourceLineNo">344</span>            catch (MissingResourceException e)<a name="line.344"></a>
+<span class="sourceLineNo">345</span>            {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>                rb = findBundleByLocale(bundleName, locale, bundlesByLocale);<a name="line.346"></a>
+<span class="sourceLineNo">347</span>                if (rb == null)<a name="line.347"></a>
+<span class="sourceLineNo">348</span>                {<a name="line.348"></a>
+<span class="sourceLineNo">349</span>                    throw (MissingResourceException) e.fillInStackTrace();<a name="line.349"></a>
+<span class="sourceLineNo">350</span>                }<a name="line.350"></a>
+<span class="sourceLineNo">351</span>            }<a name="line.351"></a>
+<span class="sourceLineNo">352</span>            if (rb != null)<a name="line.352"></a>
+<span class="sourceLineNo">353</span>            {<a name="line.353"></a>
+<span class="sourceLineNo">354</span>                // Cache bundle.<a name="line.354"></a>
+<span class="sourceLineNo">355</span>                bundlesByLocale.put(rb.getLocale(), rb);<a name="line.355"></a>
+<span class="sourceLineNo">356</span>                HashMap&lt;String, HashMap&lt;Locale, ResourceBundle&gt;&gt; bundlesByName <a name="line.356"></a>
+<span class="sourceLineNo">357</span>                        = new HashMap&lt;String, HashMap&lt;Locale, ResourceBundle&gt;&gt;(bundles);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>                bundlesByName.put(bundleName, bundlesByLocale);<a name="line.358"></a>
+<span class="sourceLineNo">359</span>                this.bundles = bundlesByName;<a name="line.359"></a>
+<span class="sourceLineNo">360</span>            }<a name="line.360"></a>
+<span class="sourceLineNo">361</span>        }<a name="line.361"></a>
+<span class="sourceLineNo">362</span>        return rb;<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    }<a name="line.363"></a>
+<span class="sourceLineNo">364</span>    <a name="line.364"></a>
+<span class="sourceLineNo">365</span>    /**<a name="line.365"></a>
+<span class="sourceLineNo">366</span>     * &lt;p&gt;Retrieves the bundle most closely matching first against the<a name="line.366"></a>
+<span class="sourceLineNo">367</span>     * supplied inputs, then against the defaults.&lt;/p&gt;<a name="line.367"></a>
+<span class="sourceLineNo">368</span>     *<a name="line.368"></a>
+<span class="sourceLineNo">369</span>     * &lt;p&gt;Use case: some clients send a HTTP Accept-Language header<a name="line.369"></a>
+<span class="sourceLineNo">370</span>     * with a value of only the language to use<a name="line.370"></a>
+<span class="sourceLineNo">371</span>     * (i.e. "Accept-Language: en"), and neglect to include a country.<a name="line.371"></a>
+<span class="sourceLineNo">372</span>     * When there is no bundle for the requested language, this method<a name="line.372"></a>
+<span class="sourceLineNo">373</span>     * can be called to try the default country (checking internally<a name="line.373"></a>
+<span class="sourceLineNo">374</span>     * to assure the requested criteria matches the default to avoid<a name="line.374"></a>
+<span class="sourceLineNo">375</span>     * disconnects between language and country).&lt;/p&gt;<a name="line.375"></a>
+<span class="sourceLineNo">376</span>     *<a name="line.376"></a>
+<span class="sourceLineNo">377</span>     * &lt;p&gt;Since we're really just guessing at possible bundles to use,<a name="line.377"></a>
+<span class="sourceLineNo">378</span>     * we don't ever throw &lt;code&gt;MissingResourceException&lt;/code&gt;.&lt;/p&gt;<a name="line.378"></a>
+<span class="sourceLineNo">379</span>     * <a name="line.379"></a>
+<span class="sourceLineNo">380</span>     * @param bundleName Name of bundle (or &lt;code&gt;null&lt;/code&gt; for the<a name="line.380"></a>
+<span class="sourceLineNo">381</span>     * default bundle).<a name="line.381"></a>
+<span class="sourceLineNo">382</span>     * @param locale The locale (or &lt;code&gt;null&lt;/code&gt; for the locale<a name="line.382"></a>
+<span class="sourceLineNo">383</span>     * indicated by the default language and country).<a name="line.383"></a>
+<span class="sourceLineNo">384</span>     * @param bundleByLocale map of locales and resource bundles<a name="line.384"></a>
+<span class="sourceLineNo">385</span>     * @return a localized resource bundle<a name="line.385"></a>
+<span class="sourceLineNo">386</span>     * <a name="line.386"></a>
+<span class="sourceLineNo">387</span>     */<a name="line.387"></a>
+<span class="sourceLineNo">388</span>    private ResourceBundle findBundleByLocale(<a name="line.388"></a>
+<span class="sourceLineNo">389</span>        String bundleName,<a name="line.389"></a>
+<span class="sourceLineNo">390</span>        Locale locale,<a name="line.390"></a>

[... 261 lines stripped ...]


Mime
View raw message