Author: scottbw
Date: Wed Jun 16 21:45:03 2010
New Revision: 955407

URL: http://svn.apache.org/viewvc?rev=955407&view=rev
Log:
[in PP branch] replaced calls for localization using collections with arrays; 
this is because the parser may be loaded with a different classloader, and so 
cannot appropriately cast the return arrays from the supplied collection.

Modified:
    
incubator/wookie/branches/pluggablepersistence/parser/java/src/org/apache/wookie/w3c/util/LocalizationUtils.java
    
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/IWidget.java
    
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/controller/WidgetInstancesController.java
    
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/helpers/WidgetHelper.java
    
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java

Modified: 
incubator/wookie/branches/pluggablepersistence/parser/java/src/org/apache/wookie/w3c/util/LocalizationUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/parser/java/src/org/apache/wookie/w3c/util/LocalizationUtils.java?rev=955407&r1=955406&r2=955407&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/parser/java/src/org/apache/wookie/w3c/util/LocalizationUtils.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/parser/java/src/org/apache/wookie/w3c/util/LocalizationUtils.java
 Wed Jun 16 21:45:03 2010
@@ -49,20 +49,6 @@ public class LocalizationUtils {
        }
        
        /**
-        * Returns the first (best) match for an element given the set of 
locales, or null
-        * if there are no suitable elements.
-        * @param elements collection
-        * @param locales
-        * @return an ILocalizedElement, or null if there are no valid entries
-        */
-       public static ILocalizedElement getLocalizedElement(Collection<? 
extends ILocalizedElement> elements, String[] locales){
-               if (elements == null) return null;
-               ILocalizedElement[] elementsArray = 
processElementsByLocales(elements,locales);
-               if (elementsArray.length == 0) return null;
-               return elementsArray[0];
-       }
-       
-       /**
         * Filters and sorts a list of localized elements using the given 
locale list; only localized elements
         * are returned unless no appropriate localized elements are found, in 
which case nonlocalized elements
         * are returned
@@ -79,23 +65,6 @@ public class LocalizationUtils {
        }
        
        /**
-        * Filters and sorts a list of localized elements using the given 
locale list; only localized elements
-        * are returned unless no appropriate localized elements are found, in 
which case nonlocalized elements
-        * are returned
-        * 
-        * @param elements collection
-        * @param locales
-        * @return the sorted and filtered set of elements
-        */
-       public static ILocalizedElement[] processElementsByLocales(Collection<? 
extends ILocalizedElement> elements,String[] locales){
-               if (elements == null) return null;
-               List<ULocale> localesList = getProcessedLocaleList(locales);
-        ILocalizedElement[] elementsArray = elements.toArray(new 
ILocalizedElement[elements.size()]);
-               Arrays.sort(elementsArray, new LocaleComparator(localesList));
-               return filter(elementsArray,localesList);
-       }
-       
-       /**
         * Sorts an array of localized elements using default locales (*). This 
places
         * any localized elements first, then any unlocalized elements
         * @return

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/IWidget.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/IWidget.java?rev=955407&r1=955406&r2=955407&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/IWidget.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/IWidget.java
 Wed Jun 16 21:45:03 2010
@@ -332,7 +332,8 @@ public interface IWidget extends IBean
          */
         public static String getWidgetTitle(IWidget widget, String locale)
         {
-            IName name = 
(IName)LocalizationUtils.getLocalizedElement(widget.getNames(), new 
String[]{locale});
+               IName[] names = widget.getNames().toArray(new 
IName[widget.getNames().size()]);
+            IName name = (IName)LocalizationUtils.getLocalizedElement(names, 
new String[]{locale});
             return ((name != null) ? name.getName() : 
IW3CXMLConfiguration.UNKNOWN);
         }
         
@@ -345,7 +346,8 @@ public interface IWidget extends IBean
          */
         public static String getWidgetDescription(IWidget widget, String 
locale)
         {
-            IDescription description = 
(IDescription)LocalizationUtils.getLocalizedElement(widget.getDescriptions(), 
new String[]{locale});
+               IDescription[] descriptions = 
widget.getDescriptions().toArray(new 
IDescription[widget.getDescriptions().size()]);
+            IDescription description = 
(IDescription)LocalizationUtils.getLocalizedElement(descriptions, new 
String[]{locale});
             return ((description != null) ? description.getContent() : null);
         }
 
@@ -358,7 +360,8 @@ public interface IWidget extends IBean
          */
         public static String getWidgetShortName(IWidget widget, String locale)
         {
-            IName name = 
(IName)LocalizationUtils.getLocalizedElement(widget.getNames(), new 
String[]{locale});
+               IName[] names = widget.getNames().toArray(new 
IName[widget.getNames().size()]);
+            IName name = (IName)LocalizationUtils.getLocalizedElement(names, 
new String[]{locale});
             return ((name != null) ? name.getShortName() : 
IW3CXMLConfiguration.UNKNOWN);
         }
         
@@ -411,7 +414,8 @@ public interface IWidget extends IBean
          */
         public static String getUrl(IWidget widget, String locale)
         {
-            IStartFile startFile = 
(IStartFile)LocalizationUtils.getLocalizedElement(widget.getStartFiles(), new 
String[]{locale});
+               IStartFile[] startFiles = widget.getStartFiles().toArray(new 
IStartFile[widget.getStartFiles().size()]);
+            IStartFile startFile = 
(IStartFile)LocalizationUtils.getLocalizedElement(startFiles, new 
String[]{locale});
             return ((startFile != null) ? startFile.getUrl() : null);
         }
 
@@ -424,7 +428,8 @@ public interface IWidget extends IBean
          */
         public static String getWidgetIconLocation(IWidget widget, String 
locale)
         {
-            IWidgetIcon icon = 
(IWidgetIcon)LocalizationUtils.getLocalizedElement(widget.getWidgetIcons(), new 
String[]{locale});
+               IWidgetIcon[] icons = widget.getWidgetIcons().toArray(new 
IWidgetIcon[widget.getWidgetIcons().size()]);
+            IWidgetIcon icon = 
(IWidgetIcon)LocalizationUtils.getLocalizedElement(icons, new String[]{locale});
             return ((icon != null) ? icon.getSrc() : null);
         }
     }

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/controller/WidgetInstancesController.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=955407&r1=955406&r2=955407&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/controller/WidgetInstancesController.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/controller/WidgetInstancesController.java
 Wed Jun 16 21:45:03 2010
@@ -305,7 +305,7 @@ public class WidgetInstancesController e
        protected static String getUrl(HttpServletRequest request, 
IWidgetInstance instance) throws IOException{
                String url = "";
 
-               Collection<IStartFile> startFiles = 
instance.getWidget().getStartFiles();
+               IStartFile[] startFiles = 
instance.getWidget().getStartFiles().toArray(new 
IStartFile[instance.getWidget().getStartFiles().size()]);
         IStartFile sf = (IStartFile) 
LocalizationUtils.getLocalizedElement(startFiles, new 
String[]{instance.getLang()});
                // Try default locale if no appropriate localization found
                if (sf == null) sf = (IStartFile) 
LocalizationUtils.getLocalizedElement(startFiles, null);

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/helpers/WidgetHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/helpers/WidgetHelper.java?rev=955407&r1=955406&r2=955407&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/helpers/WidgetHelper.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/helpers/WidgetHelper.java
 Wed Jun 16 21:45:03 2010
@@ -115,7 +115,8 @@ public class WidgetHelper {
        
        private static String getLicenses(IWidget widget, String[] locales){
                String out = "";
-               ILicense[] licenses = 
(ILicense[])LocalizationUtils.processElementsByLocales(widget.getLicenses(), 
locales);
+               ILicense[] licenses = widget.getLicenses().toArray(new 
ILicense[widget.getLicenses().size()]);
+               licenses = 
(ILicense[])LocalizationUtils.processElementsByLocales(licenses, locales);
                for (ILicense license: licenses){
                        out +="\t\t<license ";
                        if (license.getLang()!=null) out+=" 
xml:lang=\""+license.getLang()+"\"";
@@ -135,7 +136,8 @@ public class WidgetHelper {
        }
 
        private static String getName(IWidget widget, String[] locales){
-               IName name = 
(IName)LocalizationUtils.getLocalizedElement(widget.getNames(),locales);
+       IName[] names = widget.getNames().toArray(new 
IName[widget.getNames().size()]);
+               IName name = 
(IName)LocalizationUtils.getLocalizedElement(names,locales);
                String shortName = null;
                String longName = null;
                if (name != null) {
@@ -152,7 +154,8 @@ public class WidgetHelper {
        }
 
        private static String getDescription(IWidget widget, String[] locales){
-               IDescription desc = 
(IDescription)LocalizationUtils.getLocalizedElement(widget.getDescriptions(), 
locales);     
+       IDescription[] descriptions = widget.getDescriptions().toArray(new 
IDescription[widget.getDescriptions().size()]);
+               IDescription desc = 
(IDescription)LocalizationUtils.getLocalizedElement(descriptions, locales); 
                String out = "\t\t<description";
                if (desc!= null && desc.getDir()!=null) out+=" 
dir=\""+desc.getDir()+"\"";
                out += ">";
@@ -174,7 +177,7 @@ public class WidgetHelper {
                String out = "";
                IWidgetIcon[] icons;
                if (locales != null && locales.length != 0){
-                       icons = 
(IWidgetIcon[])LocalizationUtils.processElementsByLocales(widget.getWidgetIcons(),
 locales);
+                       icons = 
(IWidgetIcon[])LocalizationUtils.processElementsByLocales(widget.getWidgetIcons().toArray(new
 IWidgetIcon[widget.getWidgetIcons().size()]), locales);
                } else {
                        icons = widget.getWidgetIcons().toArray(new 
IWidgetIcon[widget.getWidgetIcons().size()]);
                }

Modified: 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java?rev=955407&r1=955406&r2=955407&view=diff
==============================================================================
--- 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 (original)
+++ 
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/util/opensocial/OpenSocialUtils.java
 Wed Jun 16 21:45:03 2010
@@ -127,8 +127,8 @@ public class OpenSocialUtils {
        }
        
        private static String getUrl(IWidgetInstance instance){
-           Collection<IStartFile> files = instance.getWidget().getStartFiles();
-               IStartFile start = (IStartFile) 
LocalizationUtils.getLocalizedElement(files, new String[]{"en"});
+       IStartFile[] startFiles = 
instance.getWidget().getStartFiles().toArray(new 
IStartFile[instance.getWidget().getStartFiles().size()]);
+               IStartFile start = (IStartFile) 
LocalizationUtils.getLocalizedElement(startFiles, new String[]{"en"});
                return start.getUrl();
        }
 


Reply via email to