View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.plugin.misc;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.seasar.tuigwaa.cms.core.CmsRequest;
22  import org.seasar.tuigwaa.cms.core.CmsResponse;
23  import org.seasar.tuigwaa.plugin.AbstractTgwPlugin;
24  import org.seasar.tuigwaa.plugin.PluginException;
25  import org.seasar.tuigwaa.plugin.PluginRequest;
26  
27  import com.isenshi.util.CharUtil;
28  import com.isenshi.util.HtmlBuffer;
29  
30  /***
31   * @author someda
32   * @see <a href="http://www.google.co.jp/apis/maps/documentation/">Google Maps API Documentation</a>
33   */
34  public class GmapPlugin extends AbstractTgwPlugin {
35  	
36  	private static final String GMAP_URL = "http://maps.google.com/maps?file=api&v=1&key=";
37  	private static final String GMAP_KEY = getMessage("gmap.api.keys");
38  	
39  	// origin-point
40  	private static final String DEFAULT_LONGITUDE = "139.74135441"; // keido 
41  	private static final String DEFAULT_LATITUDE = "35.6580992";  // ido
42  	
43  	//  tokyo - tower (^^;)
44  	//	"139.748647213";  keido 
45  	//	"35.6554830135";   ido		
46  	
47  	// keio-shinagawa building
48  	// 139.73934531211853; keido 
49  	// 35.624799984031526;
50  	
51  	public String doHTMLView(CmsRequest request, CmsResponse response,
52  			PluginRequest prequest) throws PluginException {
53  				
54  		String[] args = prequest.getArgs();
55  		
56  		String latitude = DEFAULT_LATITUDE;
57  		String longitude = DEFAULT_LONGITUDE;
58  		String comment = "";
59  				
60  		if(args != null){
61  			if(args.length >= 2){
62  				longitude = args[0];
63  				latitude = args[1];
64  			}			
65  			if(args.length >= 3){
66  				comment = args[2];
67  			}									
68  		}
69  				
70  		HtmlBuffer buf = new HtmlBuffer();
71  		buf.setNewline(false);
72  		buf.setTab(false);
73  		buf.appendStartTag("script");
74  		buf.appendAttribute("src",GMAP_URL + GMAP_KEY);
75  		buf.appendAttribute("type","text/javascript");
76  		buf.appendAttribute("charset","UTF-8");
77  		buf.appendBody("");
78  		buf.setNewline(true);
79  		buf.endTag();
80  		
81  		buf.setNewline(false);
82  		buf.appendStartTag("div");
83  		buf.appendAttribute("id","map");
84  		buf.appendAttribute("style","width:400px;height:300px;");
85  		buf.appendBody("");
86  		buf.setNewline(true);
87  		buf.endTag();
88  
89  		// should be modified...
90  		buf.appendStartTag("script");
91  		buf.appendAttribute("type","text/javascript");
92  		buf.appendBody("<!--");
93  		buf.appendBody(getScript(latitude,longitude,comment));		
94  		buf.appendBody("//-->");
95  		buf.endTag();
96  				
97  		return buf.toString();
98  	}
99  	
100 	private static String getScript(String latitude, String longitude, String comment){		
101 		StringBuffer buf = new StringBuffer();		
102 		String template = getJavascriptTemplate("gmapLoad");
103 		Map map = new HashMap();
104 		map.put("mapid","map");
105 		map.put("lon",longitude);
106 		map.put("lat",latitude);
107 		map.put("msg",comment);
108 		buf.append(CharUtil.replace(template,map));
109 		buf.append("addInitFunction(gmapLoad);");						
110 		return buf.toString();
111 	}	
112 	
113 }