Author: [email protected]
Date: Fri Aug 26 17:12:51 2011
New Revision: 1350

Log:
[AMDATUOPENSOCIAL-97] Fixed the error by 'cleaning' the message XML prior to 
parsing it

Modified:
   
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java

Modified: 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
  (original)
+++ 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigOpenSocialContainerImpl.java
  Fri Aug 26 17:12:51 2011
@@ -159,7 +159,7 @@
                     Locale locale = getPreferredLocale(defaultLocale, locales);
 
                     // First replace messages with the preferred language 
labels
-                    String messageXML = 
loadContentFromURL(locales.get(locale).getMessages().toString());
+                    String messageXML = 
cleanMessageXML(loadContentFromURL(locales.get(locale).getMessages().toString()));
                     MessageBundle bundle = new 
MessageBundle(locales.get(locale), messageXML);
                     Substitutions substituter = new Substitutions();
                     substituter.addSubstitutions(Substitutions.Type.MESSAGE, 
bundle.getMessages());
@@ -167,7 +167,7 @@
 
                     // Replace the remaining messages with 'all' messages
                     locale = getPreferredLocale(new Locale("all", "all"), 
locales);
-                    messageXML = 
loadContentFromURL(locales.get(locale).getMessages().toString());
+                    messageXML = 
cleanMessageXML(loadContentFromURL(locales.get(locale).getMessages().toString()));
                     bundle = new MessageBundle(locales.get(locale), 
messageXML);
                     substituter = new Substitutions();
                     substituter.addSubstitutions(Substitutions.Type.MESSAGE, 
bundle.getMessages());
@@ -228,6 +228,21 @@
         String responseBody = httpClient.execute(httpGet, responseHandler);
         return responseBody;
     }
+    
+    /**
+     * This method omits any content prior to <messagebundle>. It appears that 
some gadgets,
+     * see http://jira.amdatu.org/jira/browse/AMDATUOPENSOCIAL-97, return XML 
that is not 
+     * completely correct.
+     * @param messages The message XML to clean
+     * @return The cleaned XML
+     */
+    private String cleanMessageXML(String xml) {
+        if (xml.startsWith("<messagebundle>")) {
+            return xml;
+        } else {
+            return xml.substring(xml.indexOf("<messagebundle>"));
+        }
+    }
 
     private UserPrefs loadUserPrefs(GadgetSpec spec, final Map<String, String> 
userPrefs) {
         // Default userpref values, when there are no user specific userprefs 
stored (yet)
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to