01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.portals.gems.googlemaps;
18:
19: import java.io.IOException;
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import javax.portlet.ActionRequest;
24: import javax.portlet.ActionResponse;
25: import javax.portlet.PortletException;
26: import javax.portlet.PortletPreferences;
27:
28: import org.apache.jetspeed.headerresource.HeaderResource;
29: import org.apache.jetspeed.portlet.PortletHeaderRequest;
30: import org.apache.jetspeed.portlet.PortletHeaderResponse;
31: import org.apache.portals.gems.dojo.AbstractDojoVelocityPortlet;
32:
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: * no change
43: */
44: public GoogleMapsPortlet() {
45: super ();
46: }
47:
48: /**
49: * save submitted value
50: *
51: * @see javax.portlet.GenericPortlet#processActions
52: *
53: */
54: public void processAction(ActionRequest request,
55: ActionResponse actionResponse) throws PortletException,
56: IOException {
57: String location = request.getParameter("location");
58: String mapHeight = request.getParameter("mapheight");
59: String apiKey = request.getParameter("apikey");
60: PortletPreferences preferences = request.getPreferences();
61: if (location != null)
62: preferences.setValue("Location", location);
63: if (mapHeight != null)
64: preferences.setValue("MapHeight", mapHeight);
65: if (apiKey != null)
66: preferences.setValue("APIKey", apiKey);
67: preferences.store();
68: }
69:
70: public void doHeader(PortletHeaderRequest request,
71: PortletHeaderResponse response) throws PortletException {
72: StringBuffer headerInfoText = new StringBuffer();
73: Map headerInfoMap = null;
74:
75: // add google maps api script tag
76: headerInfoText.setLength(0);
77: headerInfoMap = new HashMap(8);
78: headerInfoMap.put("language", "JavaScript");
79: headerInfoMap.put("src",
80: "http://maps.google.com/maps?file=api&v=2&key="
81: + request.getPreferences().getValue("APIKey",
82: ""));
83: headerInfoMap.put("type", "text/javascript");
84: response.getHeaderResource().addHeaderInfo("script",
85: headerInfoMap, headerInfoText.toString());
86:
87: super .doHeader(request, response);
88: }
89:
90: protected void includeHeaderContent(HeaderResource headerResource) {
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: }
|