Example #1
0
 /** Detect ending elements. */
 @Override
 public void endElement(String namespaceURI, String localName, String qName)
     throws SAXException {
   if ("description".equals(qName) && description != null) {
     currentResult.description = description.toString();
     description = null;
   }
   depth--;
 }
Example #2
0
 /** Detect starting elements. */
 @Override
 public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
     throws SAXException {
   depth++;
   try {
     if (qName.equals("searchresults")) {
       // do nothing
     } else if (qName.equals("named") && (depth == 2)) {
       currentResult = new PlaceSelection.SearchResult();
       currentResult.name = atts.getValue("name");
       currentResult.info = atts.getValue("info");
       if (currentResult.info != null) {
         currentResult.info = tr(currentResult.info);
       }
       currentResult.lat = Double.parseDouble(atts.getValue("lat"));
       currentResult.lon = Double.parseDouble(atts.getValue("lon"));
       currentResult.zoom = Integer.parseInt(atts.getValue("zoom"));
       data.add(currentResult);
     } else if (qName.equals("description") && (depth == 3)) {
       description = new StringBuffer();
     } else if (qName.equals("named") && (depth == 4)) {
       // this is a "named" place in the nearest places list.
       String info = atts.getValue("info");
       if ("city".equals(info) || "town".equals(info) || "village".equals(info)) {
         currentResult.nearestPlace = atts.getValue("name");
       }
     } else if (qName.equals("place") && atts.getValue("lat") != null) {
       currentResult = new PlaceSelection.SearchResult();
       currentResult.name = atts.getValue("display_name");
       currentResult.description = currentResult.name;
       currentResult.info = atts.getValue("class");
       if (currentResult.info != null) {
         currentResult.info = tr(currentResult.info);
       }
       currentResult.nearestPlace = tr(atts.getValue("type"));
       currentResult.lat = Double.parseDouble(atts.getValue("lat"));
       currentResult.lon = Double.parseDouble(atts.getValue("lon"));
       String[] bbox = atts.getValue("boundingbox").split(",");
       currentResult.bounds =
           new Bounds(
               Double.parseDouble(bbox[0]), Double.parseDouble(bbox[2]),
               Double.parseDouble(bbox[1]), Double.parseDouble(bbox[3]));
       data.add(currentResult);
     }
   } catch (NumberFormatException x) {
     x.printStackTrace(); // SAXException does not chain correctly
     throw new SAXException(x.getMessage(), x);
   } catch (NullPointerException x) {
     x.printStackTrace(); // SAXException does not chain correctly
     throw new SAXException(tr("Null pointer exception, possibly some missing tags."), x);
   }
 }