1 6 14 15 package com.sun.javaee.blueprints.mapviewer; 16 17 import com.sun.j2ee.blueprints.ui.geocoder.GeoCoder; 18 import com.sun.j2ee.blueprints.ui.geocoder.GeoPoint; 19 import com.sun.j2ee.blueprints.ui.mapviewer.MapMarker; 20 import com.sun.j2ee.blueprints.ui.mapviewer.MapPoint; 21 import javax.faces.component.UICommand; 22 import javax.faces.component.UIInput; 23 import javax.faces.component.UIForm; 24 25 29 public class MapBean { 30 31 private MapMarker mapMarker=new MapMarker(); 32 private MapPoint mapPoint=new MapPoint(); 33 private String location="4150 Network Circle, Santa Clara, CA 95054", foundLocation="", info="Sun's Santa Clara Campus"; 34 private String mapReady="true", proxyHost=""; 35 private double foundLatitude=0.0d, foundLongitude=0.0d; 36 private int proxyPort=0; 37 38 39 public MapBean() { 40 } 41 42 43 44 public void setProxyHost(String proxyHost) { 46 this.proxyHost=proxyHost; 47 } 48 public String getProxyHost() { 49 return this.proxyHost; 50 } 51 52 public void setProxyPort(int proxyPort) { 53 this.proxyPort=proxyPort; 54 } 55 public int getProxyPort() { 56 return this.proxyPort; 57 } 58 59 public void setMapReady(String mapReady) { 60 this.mapReady=mapReady; 61 } 62 public String getMapReady() { 63 return this.mapReady; 64 } 65 66 public void setInfo(String info) { 67 this.info=info; 68 } 69 public String getInfo() { 70 return this.info; 71 } 72 73 public void setLocation(String location) { 74 this.location=location; 75 } 76 public String getLocation() { 77 return this.location; 78 } 79 80 public void setFoundLocation(String foundLocation) { 81 this.foundLocation=foundLocation; 82 } 83 public String getFoundLocation() { 84 return this.foundLocation; 85 } 86 87 public void setFoundLatitude(double foundLatitude) { 88 this.foundLatitude=foundLatitude; 89 } 90 public double getFoundLatitude() { 91 return this.foundLatitude; 92 } 93 94 public void setFoundLongitude(double foundLongitude) { 95 this.foundLongitude=foundLongitude; 96 } 97 public double getFoundLongitude() { 98 return this.foundLongitude; 99 } 100 101 102 103 104 public void setMapMarker(MapMarker mapMarker) { 106 this.mapMarker=mapMarker; 107 } 108 public MapMarker getMapMarker() { 109 return this.mapMarker; 110 } 111 112 public void setMapPoint(MapPoint mapPoint) { 113 this.mapPoint=mapPoint; 114 } 115 public MapPoint getMapPoint() { 116 return this.mapPoint; 117 } 118 119 public MapMarker[] getLocations() { 120 return new MapMarker[]{this.mapMarker}; 121 } 122 123 124 125 public String findAction() { 126 System.out.println("in findAction - " + getLocation()); 127 GeoCoder geoCoder=new GeoCoder(); 130 if(!getProxyHost().equals("")) { 131 System.out.println("Setting proxy to " + getProxyHost() + ":" + getProxyPort() + ". Make sure server.policy is updated to allow setting System Properties"); 134 geoCoder.setProxyHost(getProxyHost()); 135 geoCoder.setProxyPort(getProxyPort()); 136 } 137 138 GeoPoint points[]=geoCoder.geoCode(location); 140 if ((points == null) || (points.length < 1)) { 141 setFoundLocation("No geographic points matched this location OR the Yahoo server can't be reached, please try again"); 142 return null; 143 } 144 145 if (points.length > 1) { 147 System.out.println("Matched " + points.length + " locations, taking the first one"); 148 } 149 150 setFoundLocation(points[0].toString()); 152 setFoundLatitude(points[0].getLatitude()); 153 setFoundLongitude(points[0].getLongitude()); 154 155 mapMarker.setLatitude(points[0].getLatitude()); 157 mapMarker.setLongitude(points[0].getLongitude()); 158 mapMarker.setMarkup(changeSpaces(points[0].toString()) + "<br>" + changeSpaces(getInfo())); 159 160 mapPoint.setLatitude(points[0].getLatitude()); 162 mapPoint.setLongitude(points[0].getLongitude()); 163 164 mapReady="false"; 166 167 return null; 169 } 170 171 172 public String mapAction() { 173 return "map"; 175 } 176 177 public String changeSpaces(String text) { 178 return text.replaceAll(" ", " "); 179 } 180 181 } 182 | Popular Tags |