View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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  
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          // add google maps api script tag
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