48
48
49
49
@ Component
50
50
public class KmlOlsResponseConverter extends AbstractHttpMessageConverter <OlsResponse > {
51
-
51
+
52
52
private static final String GEOCODED = "geocoded" ;
53
53
private static final String REVERSE = "reverse" ;
54
-
54
+
55
55
@ Autowired
56
56
private IGeocoder geocoder ;
57
57
private OlsResponse response ;
58
-
58
+
59
59
public KmlOlsResponseConverter () {
60
60
super (new MediaType ("application" , "vnd.google-earth.kml+xml" ,
61
61
Charset .forName ("UTF-8" )));
62
62
}
63
-
63
+
64
64
@ Override
65
65
protected boolean supports (Class <?> clazz ) {
66
66
return OlsResponse .class .isAssignableFrom (clazz );
67
67
}
68
-
68
+
69
69
@ Override
70
70
public boolean canRead (Class <?> clazz , MediaType mediaType ) {
71
71
return false ;
72
72
}
73
-
73
+
74
74
@ Override
75
75
protected OlsResponse readInternal (Class <? extends OlsResponse > clazz ,
76
76
HttpInputMessage inputMessage ) throws IOException , HttpMessageNotReadableException {
77
77
return null ;
78
78
}
79
-
79
+
80
80
@ Override
81
81
protected void writeInternal (OlsResponse response , HttpOutputMessage outputMessage )
82
82
throws IOException , HttpMessageNotWritableException {
@@ -113,7 +113,7 @@ protected void writeInternal(OlsResponse response, HttpOutputMessage outputMessa
113
113
out .write (("</Document>\r \n </kml>" ));
114
114
out .flush ();
115
115
}
116
-
116
+
117
117
String singleSiteDocHeader (SiteAddress addr , GeocoderConfig config , OlsResponse response ) {
118
118
return "<Document>\r \n "
119
119
+ "<name>Results for " + escape (addr .getAddressString ()) + "</name>\r \n "
@@ -134,12 +134,12 @@ String singleSiteDocHeader(SiteAddress addr, GeocoderConfig config, OlsResponse
134
134
+ escape (config .getCopyrightLicense ())
135
135
+ "</value></Data>\r \n "
136
136
+ "</ExtendedData>\r \n "
137
- + "<styleUrl>"
138
- + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
139
- config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
137
+ + "<styleUrl>"
138
+ + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
139
+ config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
140
140
+ "#reverse_results_heading</styleUrl>\r \n " ;
141
141
}
142
-
142
+
143
143
String singleIntersectionDocHeader (StreetIntersectionAddress intersection ,
144
144
GeocoderConfig config , OlsResponse response ) {
145
145
return "<Document>\r \n "
@@ -168,7 +168,7 @@ String singleIntersectionDocHeader(StreetIntersectionAddress intersection,
168
168
+ "<styleUrl>" + config .getKmlStylesUrl ()
169
169
+ "#reverse_intersection_results_heading</styleUrl>\r \n " ;
170
170
}
171
-
171
+
172
172
String searchResultsToKML (SearchResults results , GeocoderConfig config ,
173
173
OlsResponse response ) {
174
174
// TODO need to handle date formatting
@@ -209,9 +209,9 @@ String searchResultsToKML(SearchResults results, GeocoderConfig config,
209
209
+ escape (config .getCopyrightLicense ())
210
210
+ "</value></Data>\r \n "
211
211
+ "</ExtendedData>\r \n "
212
- + "<styleUrl>"
213
- + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
214
- config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
212
+ + "<styleUrl>"
213
+ + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
214
+ config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
215
215
+ "#results_heading</styleUrl>\r \n " );
216
216
Iterator <GeocodeMatch > it = results .getMatches ().iterator ();
217
217
while (it .hasNext ()) {
@@ -220,7 +220,7 @@ String searchResultsToKML(SearchResults results, GeocoderConfig config,
220
220
buf .append ("" );
221
221
return buf .toString ();
222
222
}
223
-
223
+
224
224
String geocodeMatchToKML (GeocodeMatch match , GeocoderConfig config ) {
225
225
if (match instanceof AddressMatch ) {
226
226
return addressMatchToKML ((AddressMatch )match , config );
@@ -229,7 +229,7 @@ String geocodeMatchToKML(GeocodeMatch match, GeocoderConfig config) {
229
229
}
230
230
return "" ;
231
231
}
232
-
232
+
233
233
String addressMatchToKML (AddressMatch match , GeocoderConfig config ) {
234
234
SiteAddress addr = match .getAddress ();
235
235
String occupantStr = "" ;
@@ -360,7 +360,7 @@ String addressMatchToKML(AddressMatch match, GeocoderConfig config) {
360
360
+ "</Placemark>" ;
361
361
return result ;
362
362
}
363
-
363
+
364
364
private String getStyleUrl (GeocoderConfig config , String type ,
365
365
GeocoderAddress addr ) {
366
366
if (addr instanceof OccupantAddress ) {
@@ -374,7 +374,7 @@ private String getStyleUrl(GeocoderConfig config, String type,
374
374
return config .getKmlStylesUrl () + "#" + type + "_" + addr .getLocationDescriptor () + "_"
375
375
+ addr .getLocationPositionalAccuracy ().toString ();
376
376
}
377
-
377
+
378
378
private String getLookAt (GeocoderAddress addr , GeocoderConfig config ) {
379
379
if (addr .getLocation () == null ) {
380
380
return "" ;
@@ -383,9 +383,9 @@ private String getLookAt(GeocoderAddress addr, GeocoderConfig config) {
383
383
"<latitude>" + addr .getLocation ().getY () + "</latitude>" +
384
384
"<altitude>0</altitude><heading>0</heading><tilt>0</tilt>" +
385
385
"<range>" + config .getDefaultLookAtRange () + "</range>" + "</LookAt>\r \n " ;
386
-
386
+
387
387
}
388
-
388
+
389
389
private String getPoint (ILocation loc ) {
390
390
if (loc .getLocation () == null ) {
391
391
return "" ;
@@ -434,7 +434,7 @@ String intersectionMatchToKML(IntersectionMatch match, GeocoderConfig config) {
434
434
+ getPoint (addr )
435
435
+ "</Placemark>\r \n " ;
436
436
}
437
-
437
+
438
438
String siteAddressesToKML (SiteAddress [] addrs , GeocoderConfig config ,
439
439
OlsResponse response ) {
440
440
StringBuilder buf = new StringBuilder ("<Document>\r \n "
@@ -450,8 +450,9 @@ String siteAddressesToKML(SiteAddress[] addrs, GeocoderConfig config,
450
450
+ "</value></Data>\r \n "
451
451
+ "<Data name=\" executionTime\" ><value>" + response .getExtraInfo ("executionTime" )
452
452
+ "</value></Data>\r \n "
453
- + (response .getExtraInfo ("tags" ).isEmpty () ? "" : "<Data name=\" tags\" ><value>"
453
+ + (response .getExtraInfo ("tags" ).isEmpty () ? "" : "<Data name=\" tags\" ><value>"
454
454
+ response .getExtraInfo ("tags" ) + "</value></Data>\r \n " )
455
+ + "<Data name=\" disclaimer\" ><value>"
455
456
+ escape (config .getDisclaimer ()) + "</value></Data>\r \n "
456
457
+ "<Data name=\" privacyStatement\" ><value>"
457
458
+ escape (config .getPrivacyStatement ()) + "</value></Data>\r \n "
@@ -462,16 +463,16 @@ String siteAddressesToKML(SiteAddress[] addrs, GeocoderConfig config,
462
463
+ escape (config .getCopyrightLicense ())
463
464
+ "</value></Data>\r \n "
464
465
+ "</ExtendedData>\r \n "
465
- + "<styleUrl>"
466
- + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
467
- config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
466
+ + "<styleUrl>"
467
+ + (response .getExtraInfo ("occupantQuery" ).equals ("true" ) ?
468
+ config .getOccupantCategoryKmlStyleUrl () : config .getKmlStylesUrl ())
468
469
+ "#reverse_results_heading</styleUrl>\r \n " );
469
470
for (SiteAddress addr : addrs ) {
470
471
buf .append (siteAddressToKML (addr , config ));
471
472
}
472
473
return buf .toString ();
473
474
}
474
-
475
+
475
476
String siteAddressToKML (SiteAddress addr , GeocoderConfig config ) {
476
477
String occupantStr = "" ;
477
478
if (addr instanceof OccupantAddress ) {
@@ -580,7 +581,7 @@ String siteAddressToKML(SiteAddress addr, GeocoderConfig config) {
580
581
+ getPoint (addr )
581
582
+ "</Placemark>" ;
582
583
}
583
-
584
+
584
585
String streetIntersectionAddressesToKML (StreetIntersectionAddress [] addrs ,
585
586
GeocoderConfig config , OlsResponse response ) {
586
587
StringBuilder buf = new StringBuilder ("<Document>\r \n "
@@ -615,7 +616,7 @@ String streetIntersectionAddressesToKML(StreetIntersectionAddress[] addrs,
615
616
}
616
617
return buf .toString ();
617
618
}
618
-
619
+
619
620
String streetIntersectionAddressToKML (StreetIntersectionAddress addr ,
620
621
GeocoderConfig config ) {
621
622
return "<Placemark>\r \n "
@@ -647,7 +648,7 @@ String streetIntersectionAddressToKML(StreetIntersectionAddress addr,
647
648
+ getPoint (addr )
648
649
+ "</Placemark>" ;
649
650
}
650
-
651
+
651
652
652
653
String escape (Object field ) {
653
654
if (field == null ) {
@@ -656,5 +657,5 @@ String escape(Object field) {
656
657
field = OlsResponseWriter .formatDate (field );
657
658
return StringEscapeUtils .escapeXml10 (field .toString ());
658
659
}
659
-
660
+
660
661
}
0 commit comments