/* * Copyright (c) 2006, msb0b.com * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the msb0b.com nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.msb0b.jspwiki.plugin; import org.apache.log4j.Logger; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.plugin.*; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.StringReader; import java.io.IOException; import java.util.Map; import java.util.Properties; public class GoogleMapsPlugin implements WikiPlugin { public static final String KEY_PROPERTY = "jspwiki.Google.maps.key"; public static final String PARAM_KEY = "key"; public static final String PARAM_LNG = "lng"; public static final String PARAM_LAT = "lat"; public static final String PARAM_ZOOM = "zoom"; /* * Parameters needed for Google Maps The very first beta version supports * only 1 point and no features key: the google maps api key. Go to * http://www.google.com/apis/maps/ to sign up for one the key should really * be stored in a properties file lat: latitude lng: longitude @param * context @param params */ public String execute(WikiContext context, Map params) { WikiEngine engine = context.getEngine(); WikiPage page = context.getPage(); StringBuffer sb = new StringBuffer(); Properties props = engine.getWikiProperties(); String key = props.getProperty(KEY_PROPERTY); String param_key = (String) params.get(PARAM_KEY); String lng = (String) params.get(PARAM_LNG); float lngv = 0; if (lng != null) { try { lngv = Float.parseFloat(lng); if(lngv < -180) lngv = -180; if(lngv > 180) lngv = 180; } catch(Exception e) { } } String lat = (String) params.get(PARAM_LAT); float latv = 0; if (lat != null) { try { latv = Float.parseFloat(lat); if(latv < -90) latv = -90; if(latv > 90) latv = 90; } catch(Exception e) { } } String zoom = (String) params.get(PARAM_ZOOM); int zoomv = 15; if (zoom != null) { try { zoomv = Integer.parseInt(zoom); if(zoomv < 0) zoomv = 0; if(zoomv > 19) zoomv = 19; } catch(Exception e) { } } if (param_key != null) key = param_key; if (key == null) key = ""; sb .append("\n"); sb.append("
\n"); sb .append("\n"); sb.append("\n"); return sb.toString(); } /** * @param args */ public static void main(String[] args) { } }