1 package com.lamatek.tags.google.beans; 2 3 import java.io.InputStream ; 4 import java.net.URL ; 5 import java.net.URLConnection ; 6 7 import javax.xml.parsers.DocumentBuilder ; 8 import javax.xml.parsers.DocumentBuilderFactory ; 9 10 import org.w3c.dom.Document ; 11 import org.w3c.dom.NamedNodeMap ; 12 import org.w3c.dom.Node ; 13 import org.w3c.dom.NodeList ; 14 15 import com.lamatek.tags.google.GoogleMapBlowupTag; 16 import com.lamatek.tags.google.GoogleMapBoxTag; 17 import com.lamatek.tags.google.GoogleMapCircleTag; 18 import com.lamatek.tags.google.GoogleMapClusterTag; 19 import com.lamatek.tags.google.GoogleMapCoordinatesTag; 20 import com.lamatek.tags.google.GoogleMapEventTag; 21 import com.lamatek.tags.google.GoogleMapIconTag; 22 import com.lamatek.tags.google.GoogleMapImageOverlayTag; 23 import com.lamatek.tags.google.GoogleMapInfoWindowTabbedTag; 24 import com.lamatek.tags.google.GoogleMapInfoWindowTag; 25 import com.lamatek.tags.google.GoogleMapInsertTag; 26 import com.lamatek.tags.google.GoogleMapKeyTag; 27 import com.lamatek.tags.google.GoogleMapLabelTag; 28 import com.lamatek.tags.google.GoogleMapMapTypeTag; 29 import com.lamatek.tags.google.GoogleMapMarkerTag; 30 import com.lamatek.tags.google.GoogleMapMessageTag; 31 import com.lamatek.tags.google.GoogleMapOverviewTag; 32 import com.lamatek.tags.google.GoogleMapPanControlTag; 33 import com.lamatek.tags.google.GoogleMapPointTag; 34 import com.lamatek.tags.google.GoogleMapPolygonTag; 35 import com.lamatek.tags.google.GoogleMapPolylineTag; 36 import com.lamatek.tags.google.GoogleMapScaleControlTag; 37 import com.lamatek.tags.google.GoogleMapTabTag; 38 import com.lamatek.tags.google.GoogleMapTag; 39 import com.lamatek.tags.google.GoogleMapTrafficTag; 40 import com.lamatek.tags.google.GoogleMapTypeControlTag; 41 import com.lamatek.tags.google.GoogleMapWMSTag; 42 import com.lamatek.tags.google.GoogleMapWheelControlTag; 43 import com.lamatek.tags.google.GoogleMapZoomControlTag; 44 45 54 public class XMLParser { 55 56 62 public static boolean parseXML(String url, GoogleMapTag mapTag) { 63 boolean parsed = true; 64 if (url == null) { 65 parsed = false; 66 } 67 else { 68 try { 69 URLConnection con = new URL (url).openConnection(); 70 if (con != null) { 71 InputStream input = con.getInputStream(); 72 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 73 factory.setValidating(true); 74 DocumentBuilder parser = factory.newDocumentBuilder(); 75 Document elements = parser.parse(input); 76 NodeList maps = elements.getElementsByTagName("map"); 77 for (int i = 0; i < maps.getLength(); i++) { 78 Node map = maps.item(i); 79 NamedNodeMap attributes = map.getAttributes(); 81 if (attributes != null) { 82 if (attributes.getNamedItem("type") != null) { 83 mapTag.setType(attributes.getNamedItem("type").getNodeValue()); 84 } 85 if (attributes.getNamedItem("headless") != null) { 86 mapTag.setHeadless(Boolean.parseBoolean(attributes.getNamedItem("headless").getNodeValue())); 87 } 88 if (attributes.getNamedItem("version") != null) { 89 mapTag.setVersion(attributes.getNamedItem("version").getNodeValue()); 90 } 91 if (attributes.getNamedItem("language") != null) { 92 mapTag.setLanguage(attributes.getNamedItem("language").getNodeValue()); 93 } 94 if (attributes.getNamedItem("debug") != null) { 95 mapTag.setDebug(Boolean.parseBoolean(attributes.getNamedItem("debug").getNodeValue())); 96 } 97 if (attributes.getNamedItem("showDaylight") != null) { 98 mapTag.setShowDaylight(Boolean.parseBoolean(attributes.getNamedItem("showDaylight").getNodeValue())); 99 } 100 if (attributes.getNamedItem("zoom") != null) { 101 try { 102 mapTag.setZoom(Integer.parseInt(attributes.getNamedItem("zoom").getNodeValue())); 103 } 104 catch(NumberFormatException nfe) {} 105 } 106 if (attributes.getNamedItem("minZoom") != null) { 107 try { 108 mapTag.setMinZoom(Integer.parseInt(attributes.getNamedItem("minZoom").getNodeValue())); 109 } 110 catch(NumberFormatException nfe) {} 111 } 112 if (attributes.getNamedItem("maxZoom") != null) { 113 try { 114 mapTag.setMaxZoom(Integer.parseInt(attributes.getNamedItem("maxZoom").getNodeValue())); 115 } 116 catch(NumberFormatException nfe) {} 117 } 118 if (attributes.getNamedItem("bound") != null) { 119 try { 120 mapTag.setBound(Boolean.parseBoolean(attributes.getNamedItem("bound").getNodeValue())); 121 } 122 catch(Exception ex) {} 123 } 124 if (attributes.getNamedItem("scope") != null) { 125 mapTag.setScope(attributes.getNamedItem("scope").getNodeValue()); 126 } 127 if (attributes.getNamedItem("width") != null) { 128 try { 129 mapTag.setWidth(attributes.getNamedItem("width").getNodeValue()); 130 } 131 catch(NumberFormatException nfe) {} 132 } 133 if (attributes.getNamedItem("height") != null) { 134 try { 135 mapTag.setHeight(attributes.getNamedItem("height").getNodeValue()); 136 } 137 catch(NumberFormatException nfe) {} 138 } 139 if (attributes.getNamedItem("centerLatitude") != null) { 140 try { 141 mapTag.setCenterLatitude(Double.parseDouble(attributes.getNamedItem("centerLatitude").getNodeValue())); 142 } 143 catch(NumberFormatException nfe) {} 144 } 145 if (attributes.getNamedItem("centerLongitude") != null) { 146 try { 147 mapTag.setCenterLongitude(Double.parseDouble(attributes.getNamedItem("centerLongitude").getNodeValue())); 148 } 149 catch(NumberFormatException nfe) {} 150 } 151 } 152 NodeList children = map.getChildNodes(); 154 for (int j = 0; j < children.getLength(); j++) { 155 Node child = children.item(j); 156 attributes = child.getAttributes(); 157 if (child.getNodeName().equals("key")) { 158 GoogleMapKeyTag key = new GoogleMapKeyTag(); 159 if (attributes != null) { 160 if (attributes.getNamedItem("domain") != null) { 161 key.setDomain(attributes.getNamedItem("domain").getNodeValue()); 162 } 163 if (attributes.getNamedItem("key") != null) { 164 key.setKey(attributes.getNamedItem("key").getNodeValue()); 165 } 166 } 167 mapTag.addKey(key); 168 } 169 else if (child.getNodeName().equals("cluster")) { 170 GoogleMapClusterTag cluster = new GoogleMapClusterTag(); 171 if (attributes != null) { 172 if (attributes.getNamedItem("pathToScript") != null) { 173 cluster.setPathToScript(attributes.getNamedItem("pathToScript").getNodeValue()); 174 } 175 if (attributes.getNamedItem("maxVisibleMarkers") != null) { 176 cluster.setMaxVisibleMarkers(Integer.parseInt(attributes.getNamedItem("maxVisibleMarkers").getNodeValue())); 177 } 178 if (attributes.getNamedItem("markersPerCluster") != null) { 179 cluster.setMaxVisibleMarkers(Integer.parseInt(attributes.getNamedItem("markersPerCluster").getNodeValue())); 180 } 181 if (attributes.getNamedItem("gridSize") != null) { 182 cluster.setGridSize(Integer.parseInt(attributes.getNamedItem("gridSize").getNodeValue())); 183 } 184 if (child.getChildNodes() != null) { 185 NodeList subs = child.getChildNodes(); 186 for (int k = 0; k < subs.getLength(); k++) { 187 Node sub = subs.item(k); 188 attributes = sub.getAttributes(); 189 if (sub.getNodeName().equals("icon")) { 190 GoogleMapIconTag icon = new GoogleMapIconTag(); 191 if (attributes != null) { 192 if (attributes.getNamedItem("icon") != null) { 193 icon.setIcon(attributes.getNamedItem("icon").getNodeValue()); 194 } 195 if (attributes.getNamedItem("shadow") != null) { 196 icon.setShadow(attributes.getNamedItem("shadow").getNodeValue()); 197 } 198 if (attributes.getNamedItem("iconWidth") != null) { 199 icon.setIconWidth(Integer.parseInt(attributes.getNamedItem("iconWidth").getNodeValue())); 200 } 201 if (attributes.getNamedItem("iconHeight") != null) { 202 icon.setIconHeight(Integer.parseInt(attributes.getNamedItem("iconHeight").getNodeValue())); 203 } 204 if (attributes.getNamedItem("shadowWidth") != null) { 205 icon.setShadowWidth(Integer.parseInt(attributes.getNamedItem("shadowWidth").getNodeValue())); 206 } 207 if (attributes.getNamedItem("shadowHeight") != null) { 208 icon.setShadowHeight(Integer.parseInt(attributes.getNamedItem("shadowHeight").getNodeValue())); 209 } 210 if (attributes.getNamedItem("anchorX") != null) { 211 icon.setAnchorX(Integer.parseInt(attributes.getNamedItem("anchorX").getNodeValue())); 212 } 213 if (attributes.getNamedItem("anchorY") != null) { 214 icon.setAnchorY(Integer.parseInt(attributes.getNamedItem("anchorY").getNodeValue())); 215 } 216 if (attributes.getNamedItem("infoWindowAnchorX") != null) { 217 icon.setInfoWindowAnchorX(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorX").getNodeValue())); 218 } 219 if (attributes.getNamedItem("infoWindowAnchorY") != null) { 220 icon.setInfoWindowAnchorY(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorY").getNodeValue())); 221 } 222 } 223 cluster.setIcon(icon); 224 } 225 } 226 } 227 } 228 mapTag.setClusterer(cluster); 229 } 230 else if (child.getNodeName().equals("point")) { 231 GoogleMapPointTag point = new GoogleMapPointTag(); 232 if (attributes != null) { 233 if (attributes.getNamedItem("id") != null) { 234 point.setId(attributes.getNamedItem("id").getNodeValue()); 235 } 236 if (attributes.getNamedItem("address") != null) { 237 point.setAddress(attributes.getNamedItem("address").getNodeValue()); 238 } 239 if (attributes.getNamedItem("city") != null) { 240 point.setCity(attributes.getNamedItem("city").getNodeValue()); 241 } 242 if (attributes.getNamedItem("state") != null) { 243 point.setState(attributes.getNamedItem("state").getNodeValue()); 244 } 245 if (attributes.getNamedItem("country") != null) { 246 point.setCountry(attributes.getNamedItem("country").getNodeValue()); 247 } 248 if (attributes.getNamedItem("zip") != null) { 249 point.setZipcode(attributes.getNamedItem("zip").getNodeValue()); 250 } 251 if (attributes.getNamedItem("longitude") != null) { 252 point.setLongitude(Double.parseDouble(attributes.getNamedItem("longitude").getNodeValue())); 253 } 254 if (attributes.getNamedItem("latitude") != null) { 255 point.setLatitude(Double.parseDouble(attributes.getNamedItem("latitude").getNodeValue())); 256 } 257 } 258 point.geocode(); 259 mapTag.addPoint(point); 260 } 261 else if (child.getNodeName().equals("box")) { 262 GoogleMapBoxTag box = new GoogleMapBoxTag(); 263 if (attributes != null) { 264 String pointlist = ""; 265 int pointCount = 0; 266 if (attributes.getNamedItem("id") != null) { 267 box.setId(attributes.getNamedItem("id").getNodeValue()); 268 } 269 if (attributes.getNamedItem("color") != null) { 270 box.setColor(attributes.getNamedItem("color").getNodeValue()); 271 } 272 if (attributes.getNamedItem("opacity") != null) { 273 box.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 274 } 275 if (attributes.getNamedItem("weight") != null) { 276 box.setWeight(Integer.parseInt(attributes.getNamedItem("weight").getNodeValue())); 277 } 278 if (attributes.getNamedItem("point1") != null) { 279 if (pointCount > 1) 280 pointlist += ","; 281 pointlist += attributes.getNamedItem("point1").getNodeValue(); 282 pointCount++; 283 } 284 if (attributes.getNamedItem("point2") != null) { 285 if (pointCount > 0) 286 pointlist += ","; 287 pointlist += attributes.getNamedItem("point2").getNodeValue(); 288 } 289 box.setPointlist(pointlist); 290 } 291 mapTag.addBox(box); 292 } 293 else if (child.getNodeName().equals("circle")) { 294 GoogleMapCircleTag circle = new GoogleMapCircleTag(); 295 if (attributes != null) { 296 if (attributes.getNamedItem("id") != null) { 297 circle.setId(attributes.getNamedItem("id").getNodeValue()); 298 } 299 if (attributes.getNamedItem("color") != null) { 300 circle.setColor(attributes.getNamedItem("color").getNodeValue()); 301 } 302 if (attributes.getNamedItem("opacity") != null) { 303 circle.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 304 } 305 if (attributes.getNamedItem("weight") != null) { 306 circle.setWeight(Integer.parseInt(attributes.getNamedItem("weight").getNodeValue())); 307 } 308 if (attributes.getNamedItem("point") != null) { 309 circle.setPoint(attributes.getNamedItem("point").getNodeValue()); 310 } 311 if (attributes.getNamedItem("radius") != null) { 312 circle.setRadius(Double.parseDouble(attributes.getNamedItem("radius").getNodeValue())); 313 } 314 } 315 mapTag.addCircle(circle); 316 } 317 else if (child.getNodeName().equals("polyline")) { 318 GoogleMapPolylineTag line = new GoogleMapPolylineTag(); 319 if (attributes != null) { 320 if (attributes.getNamedItem("id") != null) { 321 line.setId(attributes.getNamedItem("id").getNodeValue()); 322 } 323 if (attributes.getNamedItem("color") != null) { 324 line.setColor(attributes.getNamedItem("color").getNodeValue()); 325 } 326 if (attributes.getNamedItem("opacity") != null) { 327 line.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 328 } 329 if (attributes.getNamedItem("weight") != null) { 330 line.setWeight(Integer.parseInt(attributes.getNamedItem("weight").getNodeValue())); 331 } 332 if (attributes.getNamedItem("pointlist") != null) { 333 line.setPointlist(attributes.getNamedItem("pointlist").getNodeValue().replaceAll(" ", ",")); 334 } 335 } 336 mapTag.addPolyline(line); 337 } 338 else if (child.getNodeName().equals("polygon")) { 339 GoogleMapPolygonTag polygon = new GoogleMapPolygonTag(); 340 if (attributes != null) { 341 if (attributes.getNamedItem("id") != null) { 342 polygon.setId(attributes.getNamedItem("id").getNodeValue()); 343 } 344 if (attributes.getNamedItem("color") != null) { 345 polygon.setColor(attributes.getNamedItem("color").getNodeValue()); 346 } 347 if (attributes.getNamedItem("opacity") != null) { 348 polygon.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 349 } 350 if (attributes.getNamedItem("weight") != null) { 351 polygon.setWeight(Integer.parseInt(attributes.getNamedItem("weight").getNodeValue())); 352 } 353 if (attributes.getNamedItem("pointlist") != null) { 354 polygon.setPointlist(attributes.getNamedItem("pointlist").getNodeValue().replaceAll(" ", ",")); 355 } 356 } 357 mapTag.addPolygon(polygon); 358 } 359 else if (child.getNodeName().equals("wms")) { 360 GoogleMapWMSTag maptype = new GoogleMapWMSTag(); 361 if (attributes != null) { 362 if (attributes.getNamedItem("id") != null) { 363 maptype.setId(attributes.getNamedItem("id").getNodeValue()); 364 } 365 if (attributes.getNamedItem("name") != null) { 366 maptype.setName(attributes.getNamedItem("name").getNodeValue()); 367 } 368 if (attributes.getNamedItem("url") != null) { 369 maptype.setUrl(attributes.getNamedItem("url").getNodeValue()); 370 } 371 if (attributes.getNamedItem("layers") != null) { 372 maptype.setLayers(attributes.getNamedItem("layers").getNodeValue()); 373 } 374 if (attributes.getNamedItem("pathToScript") != null) { 375 maptype.setPathToScript(attributes.getNamedItem("pathToScript").getNodeValue()); 376 } 377 if (attributes.getNamedItem("format") != null) { 378 maptype.setFormat(attributes.getNamedItem("format").getNodeValue()); 379 } 380 if (attributes.getNamedItem("srs") != null) { 381 maptype.setSrs(attributes.getNamedItem("srs").getNodeValue()); 382 } 383 if (attributes.getNamedItem("version") != null) { 384 maptype.setVersion(attributes.getNamedItem("version").getNodeValue()); 385 } 386 if (attributes.getNamedItem("showOnStartup") != null) { 387 maptype.setShowOnStartup(Boolean.parseBoolean(attributes.getNamedItem("showOnStartup").getNodeValue())); 388 } 389 if (attributes.getNamedItem("showOverlay") != null) { 390 maptype.setShowOverlay(Boolean.parseBoolean(attributes.getNamedItem("showOverlay").getNodeValue())); 391 } 392 } 393 mapTag.addWMSTag(maptype); 394 } 395 else if (child.getNodeName().equals("maptype")) { 396 GoogleMapMapTypeTag maptype = new GoogleMapMapTypeTag(); 397 if (attributes != null) { 398 if (attributes.getNamedItem("id") != null) { 399 maptype.setId(attributes.getNamedItem("id").getNodeValue()); 400 } 401 if (attributes.getNamedItem("name") != null) { 402 maptype.setName(attributes.getNamedItem("name").getNodeValue()); 403 } 404 if (attributes.getNamedItem("baseType") != null) { 405 maptype.setBaseType(attributes.getNamedItem("baseType").getNodeValue()); 406 } 407 if (attributes.getNamedItem("copyright") != null) { 408 maptype.setCopyright(attributes.getNamedItem("copyright").getNodeValue()); 409 } 410 if (attributes.getNamedItem("url") != null) { 411 maptype.setUrl(attributes.getNamedItem("url").getNodeValue()); 412 } 413 if (attributes.getNamedItem("lowResUrl") != null) { 414 maptype.setLowResUrl(attributes.getNamedItem("lowResUrl").getNodeValue()); 415 } 416 if (attributes.getNamedItem("overlayUrl") != null) { 417 maptype.setOverlayUrl(attributes.getNamedItem("overlayUrl").getNodeValue()); 418 } 419 if (attributes.getNamedItem("upperLeftBound") != null) { 420 maptype.setUpperLeftBound(attributes.getNamedItem("upperLeftBound").getNodeValue()); 421 } 422 if (attributes.getNamedItem("lowerRightBound") != null) { 423 maptype.setLowerRightBound(attributes.getNamedItem("lowerRightBound").getNodeValue()); 424 } 425 if (attributes.getNamedItem("maxZoom") != null) { 426 maptype.setMaxZoom(Integer.parseInt(attributes.getNamedItem("maxZoom").getNodeValue())); 427 } 428 if (attributes.getNamedItem("minZoom") != null) { 429 maptype.setMinZoom(Integer.parseInt(attributes.getNamedItem("minZoom").getNodeValue())); 430 } 431 if (attributes.getNamedItem("showOnStartup") != null) { 432 maptype.setShowOnStartup(Boolean.parseBoolean(attributes.getNamedItem("showOnStartup").getNodeValue())); 433 } 434 if (attributes.getNamedItem("png") != null) { 435 maptype.setPng(Boolean.parseBoolean(attributes.getNamedItem("png").getNodeValue())); 436 } 437 } 438 mapTag.addMapType(maptype); 439 } 440 else if (child.getNodeName().equals("imageoverlay")) { 441 GoogleMapImageOverlayTag image = new GoogleMapImageOverlayTag(); 442 if (attributes != null) { 443 if (attributes.getNamedItem("id") != null) { 444 image.setId(attributes.getNamedItem("id").getNodeValue()); 445 } 446 if (attributes.getNamedItem("url") != null) { 447 image.setUrl(attributes.getNamedItem("url").getNodeValue()); 448 } 449 if (attributes.getNamedItem("link") != null) { 450 image.setLink(attributes.getNamedItem("link").getNodeValue()); 451 } 452 if (attributes.getNamedItem("opacity") != null) { 453 image.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 454 } 455 if (attributes.getNamedItem("x") != null) { 456 image.setX(Integer.parseInt(attributes.getNamedItem("x").getNodeValue())); 457 } 458 if (attributes.getNamedItem("y") != null) { 459 image.setY(Integer.parseInt(attributes.getNamedItem("y").getNodeValue())); 460 } 461 } 462 mapTag.addImageOverlay(image); 463 } 464 else if (child.getNodeName().equals("panControl")) { 465 GoogleMapPanControlTag control = new GoogleMapPanControlTag(); 466 if (attributes != null) { 467 if (attributes.getNamedItem("enable") != null) { 468 control.setEnable(Boolean.parseBoolean(attributes.getNamedItem("enable").getNodeValue())); 469 } 470 } 471 mapTag.setPanControl(control); 472 } 473 else if (child.getNodeName().equals("scaleControl")) { 474 GoogleMapScaleControlTag control = new GoogleMapScaleControlTag(); 475 if (attributes != null) { 476 if (attributes.getNamedItem("enable") != null) { 477 control.setEnable(Boolean.parseBoolean(attributes.getNamedItem("enable").getNodeValue())); 478 } 479 } 480 mapTag.setScaleControl(control); 481 } 482 else if (child.getNodeName().equals("wheelControl")) { 483 GoogleMapWheelControlTag control = new GoogleMapWheelControlTag(); 484 if (attributes != null) { 485 if (attributes.getNamedItem("enable") != null) { 486 control.setEnable(Boolean.parseBoolean(attributes.getNamedItem("enable").getNodeValue())); 487 } 488 } 489 mapTag.setWheelControl(control); 490 } 491 else if (child.getNodeName().equals("typeControl")) { 492 GoogleMapTypeControlTag control = new GoogleMapTypeControlTag(); 493 if (attributes != null) { 494 if (attributes.getNamedItem("enable") != null) { 495 control.setEnable(Boolean.parseBoolean(attributes.getNamedItem("enable").getNodeValue())); 496 } 497 } 498 mapTag.setTypeControl(control); 499 } 500 else if (child.getNodeName().equals("zoomControl")) { 501 GoogleMapZoomControlTag control = new GoogleMapZoomControlTag(); 502 if (attributes != null) { 503 if (attributes.getNamedItem("enable") != null) { 504 control.setEnable(Boolean.parseBoolean(attributes.getNamedItem("enable").getNodeValue())); 505 } 506 if (attributes.getNamedItem("size") != null) { 507 control.setSize(attributes.getNamedItem("size").getNodeValue()); 508 } 509 } 510 mapTag.setZoomControl(control); 511 } 512 else if (child.getNodeName().equals("overviewControl")) { 513 GoogleMapOverviewTag control = new GoogleMapOverviewTag(); 514 if (attributes != null) { 515 if (attributes.getNamedItem("width") != null) { 516 control.setWidth(Integer.parseInt(attributes.getNamedItem("width").getNodeValue())); 517 } 518 if (attributes.getNamedItem("height") != null) { 519 control.setHeight(Integer.parseInt(attributes.getNamedItem("height").getNodeValue())); 520 } 521 if (attributes.getNamedItem("x") != null) { 522 control.setX(Integer.parseInt(attributes.getNamedItem("x").getNodeValue())); 523 } 524 if (attributes.getNamedItem("y") != null) { 525 control.setY(Integer.parseInt(attributes.getNamedItem("y").getNodeValue())); 526 } 527 } 528 mapTag.setOverviewControl(control); 529 } 530 else if (child.getNodeName().equals("message")) { 531 GoogleMapMessageTag message = new GoogleMapMessageTag(); 532 if (attributes != null) { 533 if (attributes.getNamedItem("style") != null) { 534 message.setStyle(attributes.getNamedItem("style").getNodeValue()); 535 } 536 } 537 if (child.getChildNodes() != null) { 538 NodeList subs = child.getChildNodes(); 539 for (int k = 0; k < subs.getLength(); k++) { 540 Node sub = subs.item(k); 541 if (sub.getNodeName().equals("#text")) { 542 message.setMessage(sub.getNodeValue()); 543 } 544 } 545 } 546 mapTag.setMessage(message); 547 } 548 else if (child.getNodeName().equals("coordinates")) { 549 GoogleMapCoordinatesTag coords = new GoogleMapCoordinatesTag(); 550 if (attributes != null) { 551 if (attributes.getNamedItem("x") != null) { 552 coords.setX(Integer.parseInt(attributes.getNamedItem("x").getNodeValue())); 553 } 554 if (attributes.getNamedItem("y") != null) { 555 coords.setY(Integer.parseInt(attributes.getNamedItem("y").getNodeValue())); 556 } 557 if (attributes.getNamedItem("style") != null) { 558 coords.setStyle(attributes.getNamedItem("style").getNodeValue()); 559 } 560 if (attributes.getNamedItem("css_class") != null) { 561 coords.setCss_class(attributes.getNamedItem("css_class").getNodeValue()); 562 } 563 } 564 mapTag.addCoordinates(coords); 565 } 566 else if (child.getNodeName().equals("insert")) { 567 GoogleMapInsertTag insert = new GoogleMapInsertTag(); 568 if (attributes != null) { 569 if (attributes.getNamedItem("id") != null) { 570 insert.setId(attributes.getNamedItem("id").getNodeValue()); 571 } 572 if (attributes.getNamedItem("mapTypes") != null) { 573 insert.setMapTypes(attributes.getNamedItem("mapTypes").getNodeValue()); 574 } 575 if (attributes.getNamedItem("point") != null) { 576 insert.setPoint(attributes.getNamedItem("point").getNodeValue()); 577 } 578 if (attributes.getNamedItem("url") != null) { 579 insert.setUrl(attributes.getNamedItem("url").getNodeValue()); 580 } 581 if (attributes.getNamedItem("baseZoom") != null) { 582 insert.setBaseZoom(Integer.parseInt(attributes.getNamedItem("baseZoom").getNodeValue())); 583 } 584 if (attributes.getNamedItem("width") != null) { 585 insert.setWidth(Integer.parseInt(attributes.getNamedItem("width").getNodeValue())); 586 } 587 if (attributes.getNamedItem("height") != null) { 588 insert.setHeight(Integer.parseInt(attributes.getNamedItem("height").getNodeValue())); 589 } 590 } 591 mapTag.addInsert(insert); 592 } 593 else if (child.getNodeName().equals("label")) { 594 GoogleMapLabelTag label = new GoogleMapLabelTag(); 595 if (attributes != null) { 596 if (attributes.getNamedItem("point") != null) { 597 label.setPoint(attributes.getNamedItem("point").getNodeValue()); 598 } 599 if (attributes.getNamedItem("css_class") != null) { 600 label.setCss_class(attributes.getNamedItem("css_class").getNodeValue()); 601 } 602 if (attributes.getNamedItem("content") != null) { 603 label.setContent(attributes.getNamedItem("content").getNodeValue()); 604 } 605 if (attributes.getNamedItem("html") != null) { 606 label.setHtml(Boolean.parseBoolean(attributes.getNamedItem("html").getNodeValue())); 607 } 608 if (attributes.getNamedItem("style") != null) { 609 label.setStyle(attributes.getNamedItem("style").getNodeValue()); 610 } 611 if (attributes.getNamedItem("opacity") != null) { 612 label.setOpacity(Float.parseFloat(attributes.getNamedItem("opacity").getNodeValue())); 613 } 614 if (attributes.getNamedItem("x_offset") != null) { 615 label.setX_offset(Integer.parseInt(attributes.getNamedItem("x_offset").getNodeValue())); 616 } 617 if (attributes.getNamedItem("y_offset") != null) { 618 label.setY_offset(Integer.parseInt(attributes.getNamedItem("y_offset").getNodeValue())); 619 } 620 } 621 if (child.getChildNodes() != null) { 622 NodeList subs = child.getChildNodes(); 623 for (int k = 0; k < subs.getLength(); k++) { 624 Node sub = subs.item(k); 625 if (sub.getNodeName().equals("#text")) { 626 label.setContent(sub.getNodeValue()); 627 } 628 } 629 } 630 mapTag.addLabel(label); 631 } 632 else if (child.getNodeName().equals("traffic")) { 633 GoogleMapTrafficTag traffic = new GoogleMapTrafficTag(); 634 if (attributes != null) { 635 if (attributes.getNamedItem("id") != null) { 636 traffic.setId(attributes.getNamedItem("id").getNodeValue()); 637 } 638 if (attributes.getNamedItem("point") != null) { 639 traffic.setPoint(attributes.getNamedItem("point").getNodeValue()); 640 } 641 if (attributes.getNamedItem("radius") != null) { 642 traffic.setRadius(Double.parseDouble(attributes.getNamedItem("radius").getNodeValue())); 643 } 644 if (attributes.getNamedItem("severity") != null) { 645 traffic.setSeverity(Integer.parseInt(attributes.getNamedItem("severity").getNodeValue())); 646 } 647 if (attributes.getNamedItem("type") != null) { 648 traffic.setType(attributes.getNamedItem("type").getNodeValue()); 649 } 650 } 651 if (child.getChildNodes() != null) { 652 NodeList subs = child.getChildNodes(); 653 for (int k = 0; k < subs.getLength(); k++) { 654 Node sub = subs.item(k); 655 attributes = sub.getAttributes(); 656 if (sub.getNodeName().equals("icon")) { 657 GoogleMapIconTag icon = new GoogleMapIconTag(); 658 if (attributes != null) { 659 if (attributes.getNamedItem("icon") != null) { 660 icon.setIcon(attributes.getNamedItem("icon").getNodeValue()); 661 } 662 if (attributes.getNamedItem("shadow") != null) { 663 icon.setShadow(attributes.getNamedItem("shadow").getNodeValue()); 664 } 665 if (attributes.getNamedItem("iconWidth") != null) { 666 icon.setIconWidth(Integer.parseInt(attributes.getNamedItem("iconWidth").getNodeValue())); 667 } 668 if (attributes.getNamedItem("iconHeight") != null) { 669 icon.setIconHeight(Integer.parseInt(attributes.getNamedItem("iconHeight").getNodeValue())); 670 } 671 if (attributes.getNamedItem("shadowWidth") != null) { 672 icon.setShadowWidth(Integer.parseInt(attributes.getNamedItem("shadowWidth").getNodeValue())); 673 } 674 if (attributes.getNamedItem("shadowHeight") != null) { 675 icon.setShadowHeight(Integer.parseInt(attributes.getNamedItem("shadowHeight").getNodeValue())); 676 } 677 if (attributes.getNamedItem("anchorX") != null) { 678 icon.setAnchorX(Integer.parseInt(attributes.getNamedItem("anchorX").getNodeValue())); 679 } 680 if (attributes.getNamedItem("anchorY") != null) { 681 icon.setAnchorY(Integer.parseInt(attributes.getNamedItem("anchorY").getNodeValue())); 682 } 683 if (attributes.getNamedItem("infoWindowAnchorX") != null) { 684 icon.setInfoWindowAnchorX(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorX").getNodeValue())); 685 } 686 if (attributes.getNamedItem("infoWindowAnchorY") != null) { 687 icon.setInfoWindowAnchorY(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorY").getNodeValue())); 688 } 689 } 690 traffic.setIcon(icon); 691 } 692 } 693 } 694 mapTag.addTraffic_tag(traffic); 695 } 696 else if (child.getNodeName().equals("marker")) { 697 GoogleMapMarkerTag marker = new GoogleMapMarkerTag(); 698 if (attributes != null) { 699 if (attributes.getNamedItem("id") != null) { 700 marker.setId(attributes.getNamedItem("id").getNodeValue()); 701 } 702 if (attributes.getNamedItem("point") != null) { 703 marker.setPoint(attributes.getNamedItem("point").getNodeValue()); 704 } 705 if (attributes.getNamedItem("draggable") != null) { 706 marker.setDraggable(Boolean.parseBoolean(attributes.getNamedItem("draggable").getNodeValue())); 707 } 708 } 709 if (child.getChildNodes() != null) { 710 NodeList subs = child.getChildNodes(); 711 for (int k = 0; k < subs.getLength(); k++) { 712 Node sub = subs.item(k); 713 attributes = sub.getAttributes(); 714 if (sub.getNodeName().equals("icon")) { 715 GoogleMapIconTag icon = new GoogleMapIconTag(); 716 if (attributes != null) { 717 if (attributes.getNamedItem("icon") != null) { 718 icon.setIcon(attributes.getNamedItem("icon").getNodeValue()); 719 } 720 if (attributes.getNamedItem("shadow") != null) { 721 icon.setShadow(attributes.getNamedItem("shadow").getNodeValue()); 722 } 723 if (attributes.getNamedItem("iconWidth") != null) { 724 icon.setIconWidth(Integer.parseInt(attributes.getNamedItem("iconWidth").getNodeValue())); 725 } 726 if (attributes.getNamedItem("iconHeight") != null) { 727 icon.setIconHeight(Integer.parseInt(attributes.getNamedItem("iconHeight").getNodeValue())); 728 } 729 if (attributes.getNamedItem("shadowWidth") != null) { 730 icon.setShadowWidth(Integer.parseInt(attributes.getNamedItem("shadowWidth").getNodeValue())); 731 } 732 if (attributes.getNamedItem("shadowHeight") != null) { 733 icon.setShadowHeight(Integer.parseInt(attributes.getNamedItem("shadowHeight").getNodeValue())); 734 } 735 if (attributes.getNamedItem("anchorX") != null) { 736 icon.setAnchorX(Integer.parseInt(attributes.getNamedItem("anchorX").getNodeValue())); 737 } 738 if (attributes.getNamedItem("anchorY") != null) { 739 icon.setAnchorY(Integer.parseInt(attributes.getNamedItem("anchorY").getNodeValue())); 740 } 741 if (attributes.getNamedItem("infoWindowAnchorX") != null) { 742 icon.setInfoWindowAnchorX(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorX").getNodeValue())); 743 } 744 if (attributes.getNamedItem("infoWindowAnchorY") != null) { 745 icon.setInfoWindowAnchorY(Integer.parseInt(attributes.getNamedItem("infoWindowAnchorY").getNodeValue())); 746 } 747 } 748 marker.setIcon(icon); 749 } 750 else if (sub.getNodeName().equals("blowup")) { 751 GoogleMapBlowupTag blowup = new GoogleMapBlowupTag(); 752 if (attributes != null) { 753 if (attributes.getNamedItem("display") != null) { 754 blowup.setDisplay(Boolean.parseBoolean(attributes.getNamedItem("display").getNodeValue())); 755 } 756 if (attributes.getNamedItem("maptype") != null) { 757 blowup.setMaptype(attributes.getNamedItem("maptype").getNodeValue()); 758 } 759 if (attributes.getNamedItem("zoom") != null) { 760 blowup.setZoom(Integer.parseInt(attributes.getNamedItem("zoom").getNodeValue())); 761 } 762 } 763 marker.setBlowup(blowup); 764 } 765 else if (sub.getNodeName().equals("infowindow")) { 766 GoogleMapInfoWindowTag info = new GoogleMapInfoWindowTag(); 767 if (attributes != null) { 768 if (attributes.getNamedItem("display") != null) { 769 info.setDisplay(Boolean.parseBoolean(attributes.getNamedItem("display").getNodeValue())); 770 } 771 if (attributes.getNamedItem("content") != null) { 772 info.setContent(attributes.getNamedItem("content").getNodeValue()); 773 } 774 if (attributes.getNamedItem("html") != null) { 775 info.setHtml(Boolean.parseBoolean(attributes.getNamedItem("html").getNodeValue())); 776 } 777 } 778 779 if (sub.getChildNodes() != null) { 780 NodeList subSubs = sub.getChildNodes(); 781 for (int l = 0; l < subSubs.getLength(); l++) { 782 Node subSub = subSubs.item(l); 783 if (subSub.getNodeName().equals("#text")) { 784 info.setContent(subSub.getNodeValue()); 785 } 786 } 787 } 788 marker.setInfoWindow(info); 789 } 790 else if (sub.getNodeName().equals("tabbedInfoWindow")) { 791 GoogleMapInfoWindowTabbedTag info = new GoogleMapInfoWindowTabbedTag(); 792 if (attributes != null) { 793 if (attributes.getNamedItem("display") != null) { 794 info.setDisplay(Boolean.parseBoolean(attributes.getNamedItem("display").getNodeValue())); 795 } 796 } 797 if (sub.getChildNodes() != null) { 798 NodeList subSubs = sub.getChildNodes(); 799 for (int l = 0; l < subSubs.getLength(); l++) { 800 Node subSub = subSubs.item(l); 801 if (subSub.getNodeName().equals("tab")) { 802 GoogleMapTabTag tab = new GoogleMapTabTag(); 803 attributes = subSub.getAttributes(); 804 if (attributes != null) { 805 if (attributes.getNamedItem("label") != null) { 806 tab.setLabel(attributes.getNamedItem("label").getNodeValue()); 807 } 808 if (attributes.getNamedItem("content") != null) { 809 tab.setContent(attributes.getNamedItem("content").getNodeValue()); 810 } 811 if (attributes.getNamedItem("html") != null) { 812 tab.setHtml(Boolean.parseBoolean(attributes.getNamedItem("html").getNodeValue())); 813 } 814 } 815 NodeList subSubSubs = subSub.getChildNodes(); 816 for (int m = 0; m < subSubSubs.getLength(); m++) { 817 Node subSubSub = subSubSubs.item(m); 818 if (subSubSub.getNodeName().equals("#text")) { 819 tab.setContent(subSubSub.getNodeValue()); 820 } 821 } 822 info.addTab(tab); 823 } 824 } 825 } 826 marker.setInfoWindow(info); 827 } 828 else if (sub.getNodeName().equals("event")) { 829 GoogleMapEventTag event = new GoogleMapEventTag(); 830 if (attributes != null) { 831 if (attributes.getNamedItem("action") != null) { 832 event.setAction(attributes.getNamedItem("action").getNodeValue()); 833 } 834 if (attributes.getNamedItem("url") != null) { 835 event.setUrl(attributes.getNamedItem("url").getNodeValue()); 836 } 837 if (attributes.getNamedItem("asynchronous") != null) { 838 event.setAsynchronous(Boolean.parseBoolean(attributes.getNamedItem("asynchronous").getNodeValue())); 839 } 840 } 841 marker.addEvent(event); 842 } 843 } 844 } 845 mapTag.addMarker(marker); 846 } 847 else if (child.getNodeName().equals("event")) { 848 GoogleMapEventTag event = new GoogleMapEventTag(); 849 if (attributes != null) { 850 if (attributes.getNamedItem("action") != null) { 851 event.setAction(attributes.getNamedItem("action").getNodeValue()); 852 } 853 if (attributes.getNamedItem("url") != null) { 854 event.setUrl(attributes.getNamedItem("url").getNodeValue()); 855 } 856 if (attributes.getNamedItem("asynchronous") != null) { 857 event.setAsynchronous(Boolean.parseBoolean(attributes.getNamedItem("asynchronous").getNodeValue())); 858 } 859 } 860 mapTag.addEvent(event); 861 } 862 } 863 } 864 } 865 } 866 catch(Exception ex) { 867 ex.printStackTrace(System.err); 868 parsed = false; 869 } 870 } 871 return parsed; 872 } 873 } 874 | Popular Tags |