Skip to content

Commit

Permalink
Better handle missing elements of Place data. Fix #144
Browse files Browse the repository at this point in the history
  • Loading branch information
boncey committed Aug 2, 2015
1 parent 4c00988 commit cc269ff
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -898,29 +898,27 @@ private Location parseLocation(Element locationElement) {
location.setWoeName(locationElement.getAttribute("woe_name"));
location.setIsHasShapeData("1".equals(locationElement.getAttribute("has_shapedata")));
location.setPlaceType(stringPlaceTypeToInt(locationElement.getAttribute("place_type")));
try {
location.setLocality(parseLocationPlace(localityElement, Place.TYPE_LOCALITY));
} catch (NullPointerException ex) {
}
try {
location.setCounty(parseLocationPlace(countyElement, Place.TYPE_COUNTY));
} catch (NullPointerException ex) {
}
location.setLocality(parseLocationPlace(localityElement, Place.TYPE_LOCALITY));
location.setCounty(parseLocationPlace(countyElement, Place.TYPE_COUNTY));
location.setRegion(parseLocationPlace(regionElement, Place.TYPE_REGION));
location.setCountry(parseLocationPlace(countryElement, Place.TYPE_COUNTRY));

return location;
}

private Place parseLocationPlace(Element element, int type) {
Place place = new Place();
place.setName(XMLUtilities.getValue(element));
place.setPlaceId(element.getAttribute("place_id"));
place.setPlaceUrl(element.getAttribute("place_url"));
place.setWoeId(element.getAttribute("woeid"));
place.setLatitude(element.getAttribute("latitude"));
place.setLongitude(element.getAttribute("longitude"));
place.setPlaceType(type);
Place place = null;
if (element != null) {
place = new Place();
place.setName(XMLUtilities.getValue(element));
place.setPlaceId(element.getAttribute("place_id"));
place.setPlaceUrl(element.getAttribute("place_url"));
place.setWoeId(element.getAttribute("woeid"));
place.setLatitude(element.getAttribute("latitude"));
place.setLongitude(element.getAttribute("longitude"));
place.setPlaceType(type);
}

return place;
}

Expand Down

0 comments on commit cc269ff

Please sign in to comment.