TRINIDAD-65 - The JS e.getFacesMessage method does not work when trinidad was compiled with Java 6 (JSLocaleElementsGenerator does not work with Java6)

Thanks to David Übelacker for his patch.
Issue is fully closed, once a new release of the plugins is used for Trinidad to build it...
diff --git a/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/JSLocaleElementsGenerator.java b/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/JSLocaleElementsGenerator.java
index 82cbdd2..b6cded9 100644
--- a/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/JSLocaleElementsGenerator.java
+++ b/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/JSLocaleElementsGenerator.java
@@ -384,23 +384,12 @@
     if (prettyPrint)
       output.write('\n');
 
-    Enumeration zoneEnumeration =
-                               new ArrayEnumeration(DATE_FORMAT_ZONE_GET_KEYS);
 
     // write the locale elements into the file
     _writeResourceContents(output,
                            _LOCALE_ELEMENTS_PATH,
                            new ArrayEnumeration(LOCALE_ELEMENTS_GET_KEYS),
                            targetLocale,
-                           zoneEnumeration.hasMoreElements(),
-                           prettyPrint);
-
-    // write the date format elements into the file
-    _writeResourceContents(output,
-                           _DATE_FORMAT_ZONE_PATH,
-                           zoneEnumeration,
-                           targetLocale,
-                           false,  // this is the last resource to write
                            prettyPrint);
 
     output.write("});");
@@ -415,15 +404,11 @@
     String      baseName,
     Enumeration keys,
     Locale      targetLocale,
-    boolean     hasMoreResources,
     boolean     prettyPrint
     ) throws IOException
   {
     try
     {
-      ResourceBundle elementsData = ResourceBundle.getBundle(baseName,
-                                                             targetLocale);
-
       while(keys.hasMoreElements())
       {
         String currKey = (String)keys.nextElement();
@@ -433,13 +418,13 @@
         if("CurrencyElements".equals(currKey))
           data = _getCurrencyData(targetLocale);
         else
-          data = _getElementData(currKey, elementsData, targetLocale);
+          data = LocaleDataResolver.getElementData(currKey, targetLocale);
 
         boolean wroteElement = _writeResourceElement(
                                     output,
                                     currKey,
                                     data,
-                                    hasMoreResources || keys.hasMoreElements(),
+                                    keys.hasMoreElements(),
                                     prettyPrint);
 
         if (wroteElement && prettyPrint)
diff --git a/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/LocaleDataResolver.java b/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/LocaleDataResolver.java
new file mode 100644
index 0000000..abf731b
--- /dev/null
+++ b/maven-i18n-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/i18n/uixtools/LocaleDataResolver.java
@@ -0,0 +1,162 @@
+/*

+ *  Licensed to the Apache Software Foundation (ASF) under one

+ *  or more contributor license agreements.  See the NOTICE file

+ *  distributed with this work for additional information

+ *  regarding copyright ownership.  The ASF licenses this file

+ *  to you under the Apache License, Version 2.0 (the

+ *  "License"); you may not use this file except in compliance

+ *  with the License.  You may obtain a copy of the License at

+ * 

+ *  http://www.apache.org/licenses/LICENSE-2.0

+ * 

+ *  Unless required by applicable law or agreed to in writing,

+ *  software distributed under the License is distributed on an

+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ *  KIND, either express or implied.  See the License for the

+ *  specific language governing permissions and limitations

+ *  under the License.

+ */

+package org.apache.myfaces.trinidadbuild.plugin.i18n.uixtools;

+

+import java.lang.reflect.InvocationTargetException;

+import java.lang.reflect.Method;

+import java.util.Enumeration;

+import java.util.Locale;

+import java.util.MissingResourceException;

+import java.util.ResourceBundle;

+

+/**

+ * Resolves locale specific elements like the names for month or date formats.

+ * With Java 6 the needed resources are not stored anymore in reousrce files

+ * but are hardcoded and can be accessed thru sun.util.resources.LocaleData.

+ * <br>

+ * This class uses reflection to access the resources to be compatible with

+ * Java 1.4, 5 and 6.

+ */

+class LocaleDataResolver {

+

+    private static final String LOCAL_ELEMENTS_RESOURCE_BUNDLE_JAVA_5 = "sun.text.resources.LocaleElements";

+

+    private static final String LOCAL_DATA_CLASS_JAVA_4 = "sun.text.resources.LocaleData";

+

+    private static final String LOCAL_DATA_CLASS_JAVA_6 = "sun.util.resources.LocaleData";

+

+    private static final String[] LOCAL_DATA_METHODS_JAVA_6 = new String[] {

+	    "getCalendarData", "getCollationData", "getCurrencyNames",

+	    "getDateFormatData", "getLocaleNames", "getNumberFormatData",

+	    "getTimeZoneNames" };

+

+    private static final String DATE_TIME_ELEMENTS = "DateTimeElements";

+

+    private static final String MINIMAL_DAYS_IN_FIRST_WEEK = "minimalDaysInFirstWeek";

+

+    private static final String FIRST_DAY_OF_WEEK = "firstDayOfWeek";

+

+    /**

+     * Returns the element data for the given key and locale.

+     *

+     * @param key the key for the element

+     * @param locale the locale to be used 

+     * @return the locale dependent element

+     */

+    public static Object getElementData(String key, Locale locale) {

+	try {

+	    Class.forName(LOCAL_DATA_CLASS_JAVA_4);

+	    return _getElementDataJava5(key, locale);

+	} catch (ClassNotFoundException e) {

+	    try {

+		Class.forName(LOCAL_DATA_CLASS_JAVA_6);

+		return _getElementDataJava6(key, locale);

+	    } catch (ClassNotFoundException e1) {

+		throw new IllegalStateException(

+			"could not access the java resource bundles");

+	    }

+	}

+    }

+

+    /**

+     * Returns the element data for the given key and locale using

+     * the java 1.4/5 mechanism to access the resources.

+     *

+     * @param key the key for the element

+     * @param locale the locale to be used 

+     * @return the locale dependent element

+     */

+    private static Object _getElementDataJava5(String key, Locale locale) {

+	ResourceBundle elementsData = ResourceBundle.getBundle(

+		LOCAL_ELEMENTS_RESOURCE_BUNDLE_JAVA_5, locale);

+	return elementsData.getObject(key);

+    }

+

+    /**

+     * Returns the element data for the given key and locale using

+     * the java 6 mechanism to access the resources.

+     *

+     * @param key the key for the element

+     * @param locale the locale to be used 

+     * @return the locale dependent element

+     */

+    private static Object _getElementDataJava6(String key, Locale locale) {

+

+	if (DATE_TIME_ELEMENTS.equals(key)) {

+	    return new Object[] {

+		    _getElementDataJava6(FIRST_DAY_OF_WEEK, locale),

+		    _getElementDataJava6(MINIMAL_DAYS_IN_FIRST_WEEK, locale) };

+	} else {

+	    for (int i = 0; i < LOCAL_DATA_METHODS_JAVA_6.length; i++) {

+		ResourceBundle bundle = _getLocaleDataResourceBundleJava6(

+			LOCAL_DATA_METHODS_JAVA_6[i], locale);

+		if (_containsKey(bundle, key)) {

+		    return bundle.getObject(key);

+		}

+	    }

+	}

+

+	throw new MissingResourceException(

+		"no element found in the java resource bundles for the given key",

+		null, key);

+    }

+

+    /**

+     * @param bundle 

+     * @param key 

+     * @return true if the given key exists in the given bundle

+     */

+    private static boolean _containsKey(ResourceBundle bundle, String key) {

+	for (Enumeration e = bundle.getKeys(); e.hasMoreElements();) {

+	    if (((String) e.nextElement()).equals(key))

+		return true;

+	}

+	return false;

+    }

+

+    /**

+     * Gives access to the java 6 implementation using reflection.

+     * 

+     * @param name

+     * @param locale

+     * @return the resource bundle for the given method name and locale

+     */

+    private static ResourceBundle _getLocaleDataResourceBundleJava6(

+	    String name, Locale locale) {

+	try {

+	    Class localDataClass = Class.forName(LOCAL_DATA_CLASS_JAVA_6);

+	    Method method = localDataClass.getMethod(name,

+		    new Class[] { Locale.class });

+	    Object bundle = method.invoke(null, new Object[] { locale });

+	    return (ResourceBundle) bundle;

+	} catch (ClassNotFoundException e) {

+	    throw new IllegalStateException();

+	} catch (SecurityException e) {

+	    throw new IllegalStateException();

+	} catch (NoSuchMethodException e) {

+	    throw new IllegalStateException();

+	} catch (IllegalArgumentException e) {

+	    throw new IllegalStateException();

+	} catch (IllegalAccessException e) {

+	    throw new IllegalStateException();

+	} catch (InvocationTargetException e) {

+	    throw new IllegalStateException();

+	}

+    }

+}
\ No newline at end of file