package com.raysweather.android;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class ConditionXMLHandler extends DefaultHandler {
Boolean currentElement = false;
String currentValue = null;
public static ConditionList conditionList = null;
public static ConditionList getSitesList() {
return conditionList;
}
public static void setSitesList(ConditionList sitesList) {
ConditionXMLHandler.conditionList = sitesList;
}
/** Called when tag starts ( ex:- <name>AndroidPeople</name>
* -- <name> )*/
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equals("conditions"))
{
/** Start */
conditionList = new ConditionList();
}
}
/** Called when tag closing ( ex:- <name>AndroidPeople</name>
* -- </name> )*/
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
/** set value */
if (localName.equalsIgnoreCase("station_id"))
conditionList.setId(currentValue);
else if (localName.equalsIgnoreCase("time"))
conditionList.setTime(currentValue);
else if (localName.equalsIgnoreCase("wind_direction"))
conditionList.setWindDirection(currentValue);
else if (localName.equalsIgnoreCase("wind_speed"))
conditionList.setWindSpeed(currentValue);
else if (localName.equalsIgnoreCase("wind_gust"))
conditionList.setWindGust(currentValue);
else if (localName.equalsIgnoreCase("humidity"))
conditionList.setHumidity(currentValue);
else if (localName.equalsIgnoreCase("temperature"))
conditionList.setTemp(currentValue);
else if (localName.equalsIgnoreCase("hi_temp"))
conditionList.setHi(currentValue);
else if (localName.equalsIgnoreCase("lo_temp"))
conditionList.setLo(currentValue);
else if (localName.equalsIgnoreCase("barometer"))
conditionList.setBarometer(currentValue);
else if (localName.equalsIgnoreCase("barotrend"))
conditionList.setBaroTrend(currentValue);
else if (localName.equalsIgnoreCase("wind_chill"))
conditionList.setWindChill(currentValue);
else if (localName.equalsIgnoreCase("heat_index"))
conditionList.setHeatIndex(currentValue);
else if (localName.equalsIgnoreCase("dew_point"))
conditionList.setDewPoint(currentValue);
else if (localName.equalsIgnoreCase("condition_icon"))
conditionList.setConditionIcon(currentValue);
else if (localName.equalsIgnoreCase("rain_today"))
conditionList.setRainToday(currentValue);
}
/** Called to get tag characters ( ex:- <name>AndroidPeople</name>
* -- to get AndroidPeople Character ) */
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
}
|