1 package tim.prune.function;
3 import java.util.ArrayList;
5 import org.xml.sax.Attributes;
6 import org.xml.sax.SAXException;
7 import org.xml.sax.helpers.DefaultHandler;
9 import tim.prune.function.search.SearchResult;
12 * XML handler for dealing with XML returned from the OSM Overpass api,
13 * specially for the OSM Poi service
15 public class SearchOsmPoisXmlHandler extends DefaultHandler
17 private ArrayList<SearchResult> _pointList = null;
18 private SearchResult _currPoint = null;
19 private String _errorMessage = null;
23 * React to the start of an XML tag
25 public void startElement(String inUri, String inLocalName, String inTagName,
26 Attributes inAttributes) throws SAXException
28 if (inTagName.equals("osm")) {
29 _pointList = new ArrayList<SearchResult>();
31 else if (inTagName.equals("node"))
33 _currPoint = new SearchResult();
34 _currPoint.setLatitude(inAttributes.getValue("lat"));
35 _currPoint.setLongitude(inAttributes.getValue("lon"));
37 else if (inTagName.equals("tag") && _currPoint != null) {
38 processTag(inAttributes);
40 super.startElement(inUri, inLocalName, inTagName, inAttributes);
44 * @param inAttributes attributes to process
46 private void processTag(Attributes inAttributes)
48 String key = inAttributes.getValue("k");
51 String value = inAttributes.getValue("v");
52 if (key.equals("name"))
54 _currPoint.setTrackName(value);
56 else if (key.equals("amenity") || key.equals("highway") || key.equals("railway"))
58 _currPoint.setPointType(value);
64 * React to the end of an XML tag
66 public void endElement(String inUri, String inLocalName, String inTagName)
69 if (inTagName.equals("node"))
72 if (_currPoint.getTrackName() != null && !_currPoint.getTrackName().equals(""))
73 _pointList.add(_currPoint);
75 super.endElement(inUri, inLocalName, inTagName);
79 * @return the list of points
81 public ArrayList<SearchResult> getPointList()
87 * @return error message, if any
89 public String getErrorMessage() {