Skip to content

Commit

Permalink
add disclaimer opening tag (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolyachevets authored May 12, 2022
1 parent bd9519c commit 4bf564f
Showing 1 changed file with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@

@Component
public class KmlOlsResponseConverter extends AbstractHttpMessageConverter<OlsResponse> {

private static final String GEOCODED = "geocoded";
private static final String REVERSE = "reverse";

@Autowired
private IGeocoder geocoder;
private OlsResponse response;

public KmlOlsResponseConverter() {
super(new MediaType("application", "vnd.google-earth.kml+xml",
Charset.forName("UTF-8")));
}

@Override
protected boolean supports(Class<?> clazz) {
return OlsResponse.class.isAssignableFrom(clazz);
}

@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected OlsResponse readInternal(Class<? extends OlsResponse> clazz,
HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return null;
}

@Override
protected void writeInternal(OlsResponse response, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
Expand Down Expand Up @@ -113,7 +113,7 @@ protected void writeInternal(OlsResponse response, HttpOutputMessage outputMessa
out.write(("</Document>\r\n</kml>"));
out.flush();
}

String singleSiteDocHeader(SiteAddress addr, GeocoderConfig config, OlsResponse response) {
return "<Document>\r\n"
+ "<name>Results for " + escape(addr.getAddressString()) + "</name>\r\n"
Expand All @@ -134,12 +134,12 @@ String singleSiteDocHeader(SiteAddress addr, GeocoderConfig config, OlsResponse
+ escape(config.getCopyrightLicense())
+ "</value></Data>\r\n"
+ "</ExtendedData>\r\n"
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "#reverse_results_heading</styleUrl>\r\n";
}

String singleIntersectionDocHeader(StreetIntersectionAddress intersection,
GeocoderConfig config, OlsResponse response) {
return "<Document>\r\n"
Expand Down Expand Up @@ -168,7 +168,7 @@ String singleIntersectionDocHeader(StreetIntersectionAddress intersection,
+ "<styleUrl>" + config.getKmlStylesUrl()
+ "#reverse_intersection_results_heading</styleUrl>\r\n";
}

String searchResultsToKML(SearchResults results, GeocoderConfig config,
OlsResponse response) {
// TODO need to handle date formatting
Expand Down Expand Up @@ -209,9 +209,9 @@ String searchResultsToKML(SearchResults results, GeocoderConfig config,
+ escape(config.getCopyrightLicense())
+ "</value></Data>\r\n"
+ "</ExtendedData>\r\n"
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "#results_heading</styleUrl>\r\n");
Iterator<GeocodeMatch> it = results.getMatches().iterator();
while(it.hasNext()) {
Expand All @@ -220,7 +220,7 @@ String searchResultsToKML(SearchResults results, GeocoderConfig config,
buf.append("");
return buf.toString();
}

String geocodeMatchToKML(GeocodeMatch match, GeocoderConfig config) {
if(match instanceof AddressMatch) {
return addressMatchToKML((AddressMatch)match, config);
Expand All @@ -229,7 +229,7 @@ String geocodeMatchToKML(GeocodeMatch match, GeocoderConfig config) {
}
return "";
}

String addressMatchToKML(AddressMatch match, GeocoderConfig config) {
SiteAddress addr = match.getAddress();
String occupantStr = "";
Expand Down Expand Up @@ -360,7 +360,7 @@ String addressMatchToKML(AddressMatch match, GeocoderConfig config) {
+ "</Placemark>";
return result;
}

private String getStyleUrl(GeocoderConfig config, String type,
GeocoderAddress addr) {
if(addr instanceof OccupantAddress) {
Expand All @@ -374,7 +374,7 @@ private String getStyleUrl(GeocoderConfig config, String type,
return config.getKmlStylesUrl() + "#" + type + "_" + addr.getLocationDescriptor() + "_"
+ addr.getLocationPositionalAccuracy().toString();
}

private String getLookAt(GeocoderAddress addr, GeocoderConfig config) {
if(addr.getLocation() == null) {
return "";
Expand All @@ -383,9 +383,9 @@ private String getLookAt(GeocoderAddress addr, GeocoderConfig config) {
"<latitude>" + addr.getLocation().getY() + "</latitude>" +
"<altitude>0</altitude><heading>0</heading><tilt>0</tilt>" +
"<range>" + config.getDefaultLookAtRange() + "</range>" + "</LookAt>\r\n";

}

private String getPoint(ILocation loc) {
if(loc.getLocation() == null) {
return "";
Expand Down Expand Up @@ -434,7 +434,7 @@ String intersectionMatchToKML(IntersectionMatch match, GeocoderConfig config) {
+ getPoint(addr)
+ "</Placemark>\r\n";
}

String siteAddressesToKML(SiteAddress[] addrs, GeocoderConfig config,
OlsResponse response) {
StringBuilder buf = new StringBuilder("<Document>\r\n"
Expand All @@ -450,8 +450,9 @@ String siteAddressesToKML(SiteAddress[] addrs, GeocoderConfig config,
+ "</value></Data>\r\n"
+ "<Data name=\"executionTime\"><value>" + response.getExtraInfo("executionTime")
+ "</value></Data>\r\n"
+ (response.getExtraInfo("tags").isEmpty() ? "" : "<Data name=\"tags\"><value>"
+ (response.getExtraInfo("tags").isEmpty() ? "" : "<Data name=\"tags\"><value>"
+ response.getExtraInfo("tags") + "</value></Data>\r\n")
+ "<Data name=\"disclaimer\"><value>"
+ escape(config.getDisclaimer()) + "</value></Data>\r\n"
+ "<Data name=\"privacyStatement\"><value>"
+ escape(config.getPrivacyStatement()) + "</value></Data>\r\n"
Expand All @@ -462,16 +463,16 @@ String siteAddressesToKML(SiteAddress[] addrs, GeocoderConfig config,
+ escape(config.getCopyrightLicense())
+ "</value></Data>\r\n"
+ "</ExtendedData>\r\n"
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "<styleUrl>"
+ (response.getExtraInfo("occupantQuery").equals("true") ?
config.getOccupantCategoryKmlStyleUrl() : config.getKmlStylesUrl())
+ "#reverse_results_heading</styleUrl>\r\n");
for(SiteAddress addr : addrs) {
buf.append(siteAddressToKML(addr, config));
}
return buf.toString();
}

String siteAddressToKML(SiteAddress addr, GeocoderConfig config) {
String occupantStr = "";
if(addr instanceof OccupantAddress) {
Expand Down Expand Up @@ -580,7 +581,7 @@ String siteAddressToKML(SiteAddress addr, GeocoderConfig config) {
+ getPoint(addr)
+ "</Placemark>";
}

String streetIntersectionAddressesToKML(StreetIntersectionAddress[] addrs,
GeocoderConfig config, OlsResponse response) {
StringBuilder buf = new StringBuilder("<Document>\r\n"
Expand Down Expand Up @@ -615,7 +616,7 @@ String streetIntersectionAddressesToKML(StreetIntersectionAddress[] addrs,
}
return buf.toString();
}

String streetIntersectionAddressToKML(StreetIntersectionAddress addr,
GeocoderConfig config) {
return "<Placemark>\r\n"
Expand Down Expand Up @@ -647,7 +648,7 @@ String streetIntersectionAddressToKML(StreetIntersectionAddress addr,
+ getPoint(addr)
+ "</Placemark>";
}


String escape(Object field) {
if(field == null) {
Expand All @@ -656,5 +657,5 @@ String escape(Object field) {
field = OlsResponseWriter.formatDate(field);
return StringEscapeUtils.escapeXml10(field.toString());
}

}

0 comments on commit 4bf564f

Please sign in to comment.