Author: woonsan
Date: Wed Apr 15 13:41:20 2009
New Revision: 765194

URL: http://svn.apache.org/viewvc?rev=765194&view=rev
Log:
APA-5: Changes GoogleMapsPortlet to use google maps API v2.x because the 
previous version is not complying with dynamic head element contribution

Modified:
    
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java

Modified: 
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java?rev=765194&r1=765193&r2=765194&view=diff
==============================================================================
--- 
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
 (original)
+++ 
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
 Wed Apr 15 13:41:20 2009
@@ -1,9 +1,9 @@
 /*
- * 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
+ * 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
@@ -18,6 +18,7 @@
 
 
 import java.io.IOException;
+import java.text.MessageFormat;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -37,14 +38,15 @@
  */
 public class GoogleMapsPortlet extends AbstractDojoVelocityPortlet
 {
-
-    /**
-     * no change
-     */
-    public GoogleMapsPortlet()
-    {
-        super();
-    }
+    
+    private static final String LOAD_MAPS_JS_FUNCTION_BODY = 
+        "function {0}loadMaps() '{'\r\n" +
+        "  if (window.{0}mapit) '{'\r\n" +
+        "    {0}mapit();\r\n" +
+        "  '}' else '{'\r\n" +
+        "    setTimeout(''{0}loadMaps()'', 100);\r\n" +
+        "  '}'\r\n" +
+        "'}'";
     
     /**
      * save submitted value
@@ -82,9 +84,17 @@
     protected void doHeaders(RenderRequest request, RenderResponse response)
     {
         super.doHeaders(request, response);
+
+        String namespace = response.getNamespace();
+        String loadMapsCallback = namespace + "loadMaps";
+        
+        String loadMapsCallbackBody = 
MessageFormat.format(LOAD_MAPS_JS_FUNCTION_BODY, namespace);
+        DojoPortletHelper.contributeScript(response, "JavaScript", 
"text/javascript", null, loadMapsCallbackBody);
         
         String apiKey = request.getPreferences().getValue("APIKey", "");
-        DojoPortletHelper.contributeScript(response, "JavaScript", 
"text/javascript", "http://maps.google.com/maps?file=api&v=2&key="; + apiKey, 
null);
+        String googleMapsSourceUrl = "http://www.google.com/jsapi?key="; + 
apiKey + "&callback=" + loadMapsCallback;
+        DojoPortletHelper.contributeScript(response, "JavaScript", 
"text/javascript", googleMapsSourceUrl, null);
+        
         DojoPortletHelper.contributeDojoRequire(response, "dojo.lang.*");
         DojoPortletHelper.contributeDojoRequire(response, "dojo.event.*");
         DojoPortletHelper.contributeDojoRequire(response, "dojo.io.*");


Reply via email to