1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40 private static final String DEFAULT_LONGITUDE = "139.74135441";
41 private static final String DEFAULT_LATITUDE = "35.6580992";
42
43
44
45
46
47
48
49
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
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 }