1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.portals.gems.googlemaps;
18
19
20 import java.io.IOException;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import javax.portlet.ActionRequest;
25 import javax.portlet.ActionResponse;
26 import javax.portlet.PortletException;
27 import javax.portlet.PortletPreferences;
28
29 import org.apache.jetspeed.headerresource.HeaderResource;
30 import org.apache.jetspeed.portlet.PortletHeaderRequest;
31 import org.apache.jetspeed.portlet.PortletHeaderResponse;
32 import org.apache.portals.gems.dojo.AbstractDojoVelocityPortlet;
33 /***
34 * This is a simple class used to override processAction
35 * to save location form submission value to location preference
36 *
37 * @version $Id: GoogleMapsPortlet.java 393251 2006-04-22 15:50:52Z jdp $
38 */
39 public class GoogleMapsPortlet extends AbstractDojoVelocityPortlet
40 {
41
42 /***
43 * no change
44 */
45 public GoogleMapsPortlet()
46 {
47 super();
48 }
49
50 /***
51 * save submitted value
52 *
53 * @see javax.portlet.GenericPortlet#processActions
54 *
55 */
56 public void processAction(ActionRequest request, ActionResponse actionResponse)
57 throws PortletException, IOException
58 {
59 String location = request.getParameter( "location" );
60 String mapHeight = request.getParameter( "mapheight" );
61 String apiKey = request.getParameter( "apikey" );
62 PortletPreferences preferences = request.getPreferences();
63 if ( location != null )
64 preferences.setValue( "Location", location );
65 if ( mapHeight != null )
66 preferences.setValue( "MapHeight", mapHeight );
67 if ( apiKey != null )
68 preferences.setValue( "APIKey", apiKey );
69 preferences.store();
70 }
71
72 public void doHeader(PortletHeaderRequest request, PortletHeaderResponse response)
73 throws PortletException
74 {
75 StringBuffer headerInfoText = new StringBuffer();
76 Map headerInfoMap = null;
77
78
79 headerInfoText.setLength(0);
80 headerInfoMap = new HashMap(8);
81 headerInfoMap.put("language", "JavaScript");
82 headerInfoMap.put("src", "http://maps.google.com/maps?file=api&v=2&key=" + request.getPreferences().getValue("APIKey","") );
83 headerInfoMap.put("type", "text/javascript");
84 response.getHeaderResource().addHeaderInfo("script", headerInfoMap, headerInfoText.toString());
85
86 super.doHeader(request, response);
87 }
88
89 protected void includeHeaderContent( HeaderResource headerResource )
90 {
91 headerResource.dojoAddCoreLibraryRequire( "dojo.lang.*" );
92 headerResource.dojoAddCoreLibraryRequire( "dojo.event.*" );
93 headerResource.dojoAddCoreLibraryRequire( "dojo.io.*" );
94 headerResource.dojoAddCoreLibraryRequire( "dojo.widget.*" );
95 headerResource.dojoAddCoreLibraryRequire( "dojo.widget.Button" );
96 }
97 }
98
99
100
101
102
103
104
105
106
107
108