portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r412210 - in /portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps: ./ GoogleMapsPortlet.java YahooGeocodeProxyServlet.java
Date Tue, 06 Jun 2006 20:48:57 GMT
Author: taylor
Date: Tue Jun  6 13:48:56 2006
New Revision: 412210

URL: http://svn.apache.org/viewvc?rev=412210&view=rev
Log:
start of GoogleMaps portlet 
contributed by Jonathan Phillips

Added:
    portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/
    portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
    portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/YahooGeocodeProxyServlet.java

Added: portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java?rev=412210&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
(added)
+++ portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
Tue Jun  6 13:48:56 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.gems.googlemaps;
+
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+/**
+ * This is a simple class used to override processAction
+ * to save location form submission value to location preference
+ *
+ * @version $Id: GoogleMapsPortlet.java 393251 2006-04-22 15:50:52Z jdp $
+ */
+public class GoogleMapsPortlet extends GenericVelocityPortlet
+{
+    
+    /**
+     * no change
+     */
+    public GoogleMapsPortlet()
+    {
+        super();
+    }
+
+    /**
+     * save submitted value
+     *
+     * @see javax.portlet.GenericPortlet#processActions
+     *
+     */
+    public void processAction(ActionRequest request, ActionResponse actionResponse)
+    throws PortletException, IOException
+    {
+	String location = request.getParameter("location");
+	PortletPreferences preferences = request.getPreferences();
+	preferences.setValue("Location",location);
+	preferences.store();
+    }
+}
+
+
+
+
+
+
+
+
+
+
+

Added: portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/YahooGeocodeProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/YahooGeocodeProxyServlet.java?rev=412210&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/YahooGeocodeProxyServlet.java
(added)
+++ portals/jetspeed-2/trunk/applications/gems/src/java/org/apache/portals/gems/googlemaps/YahooGeocodeProxyServlet.java
Tue Jun  6 13:48:56 2006
@@ -0,0 +1,98 @@
+/* Copyright 2004 Apache Software Foundation
+ *
+ * Licensed 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.gems.googlemaps;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpException;
+
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * YahooGeocodeProxyServlet
+ * 
+ * 
+ * @author jonathan david phillips
+ * @version $Id: YahooGeocodeProxyServlet.java 000001 2006-04-25 00:57:00Z jdp $
+ */
+
+public class YahooGeocodeProxyServlet extends HttpServlet
+{
+    /**
+     * Configuration 
+     */
+     private static final String YAHOO_REQUEST = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=";
+
+    /**
+     * doGet() override doGet
+     */
+     protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+		throws ServletException, java.io.IOException {
+		String location = req.getParameter("location");
+		String url = YAHOO_REQUEST + location;
+		String content = "<error/>";
+		
+		// get content from yahoo, code from http://jakarta.apache.org/commons/httpclient/tutorial.html
+		HttpClient client = new HttpClient();
+		GetMethod method = new GetMethod(url);
+		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
+    			new DefaultHttpMethodRetryHandler(3, false));
+		try {
+			int statusCode = client.executeMethod(method);
+			if (statusCode != HttpStatus.SC_OK) {
+				System.err.println("Method failed: " + method.getStatusLine());
+			}
+			// set content
+			content = method.getResponseBodyAsString();
+
+		} catch (HttpException e) {
+			System.err.println("Fatal protocol violation: " + e.getMessage());
+			e.printStackTrace();
+		} catch (IOException e) {
+			System.err.println("Fatal transport error: " + e.getMessage());
+			e.printStackTrace();
+		} finally {
+			method.releaseConnection();
+		}
+					
+		//  return content
+		resp.setContentType("text/xml");
+		PrintWriter out = resp.getWriter();
+		out.print(content);
+		out.close();
+	}
+}
+
+
+
+
+
+
+
+
+
+
+



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message