weather_service.weatherprovider
Class Weather_20_XMLParser

java.lang.Object
  extended by weather_service.weatherprovider.Weather_20_XMLParser

public class Weather_20_XMLParser
extends java.lang.Object

Parser for WeatherChannel 2.0 weather service. This class parses responses for "local" queries only and not for:

  1. "search" responses (for location lookups)
  2. "error" responses (in response to "local")


Field Summary
static java.lang.String BAROMETRIC_PRESSURE
           
static java.lang.String CURRENT_CONDITIONS
           
static java.lang.String DAY
           
static java.lang.String DAY_DATE
           
static java.lang.String DAY_INDEX
           
static java.lang.String DAY_OF_WEEK
           
static java.lang.String DAY_OR_NIGHT
           
static java.lang.String DAY_PART
           
static java.lang.String DAY_PART_DAY
           
static java.lang.String DAY_PART_NIGHT
           
static java.lang.String DESCRIPTION
           
static java.lang.String DEWPOINT
           
static java.lang.String DISPLAY_NAME
           
static java.lang.String DISTANCE_UNIT
           
static java.lang.String ERROR
           
static java.lang.String ERROR_ROOT
           
static java.lang.String ERROR_TYPE_ATTRIB
           
static java.lang.String FEELS_LIKE_TEMP
           
static java.lang.String FORECAST
           
static java.lang.String FORM
           
static java.lang.String HEAD
           
static java.lang.String HIGH_TEMP
           
static java.lang.String HUMIDITY
           
static java.lang.String ICON
           
static java.lang.String INVALID_LICENSE_KEY
           
static java.lang.String INVALID_LOCATION_PROVIDED_ERROR
           
static java.lang.String INVALID_PARTNERID_ERROR
           
static java.lang.String INVALID_PRODUCT_CODE
           
static java.lang.String LAST_UPDATED
           
static java.lang.String LATITUDE
           
static java.lang.String LOCAL_TIME
           
static java.lang.String LOCALE
           
static java.lang.String LOCATION
           
static java.lang.String LOCATION_ID
           
static java.lang.String LONGITUDE
           
static java.lang.String LOW_TEMP
           
static java.lang.String NO_ERROR_TYPE_SET
           
static java.lang.String NO_LOCATION_PROVIDED_ERROR
           
static java.lang.String OBSERVATION_STATION
           
static java.lang.String PRECIPITATION_CHANCE
           
static java.lang.String PRECIPITATION_UNIT
           
static java.lang.String PRESSURE
           
static java.lang.String PRESSURE_TREND
           
static java.lang.String PRESSURE_UNIT
           
static java.lang.String SEARCH_LOCATION_ATTRIBUTE_ID
           
static java.lang.String SEARCH_LOCATION_ATTRIBUTE_TYPE
           
static java.lang.String SEARCH_LOCATION_ELEMENT
           
static java.lang.String SEARCH_ROOT
           
static java.lang.String SEARCH_VERSION_ATTRIBUTE
           
static java.lang.String SEARCH_VERSION_ATTRIBUTE_VALUE
           
static java.lang.String SPEED_UNIT
           
static java.lang.String SUNRISE_TIME
           
static java.lang.String SUNSET_TIME
           
static java.lang.String TEMPERATURE
           
static java.lang.String TEMPERATURE_UNIT
           
static java.lang.String TIMEZONE
           
static java.lang.String UNKNOWN_ERROR
           
static java.lang.String UV
           
static java.lang.String UV_DESCRIPTION
           
static java.lang.String UV_INDEX
           
static java.lang.String VERSION
           
static java.lang.String VISIBILITY
           
static java.lang.String WEATHER_RESPONSE_VERSION
           
static java.lang.String WEATHER_ROOT
           
static java.lang.String WIND
           
static java.lang.String WIND_DEGREES
           
static java.lang.String WIND_DIRECTION
           
static java.lang.String WIND_GUST_SPEED
           
static java.lang.String WIND_SPEED
           
 
Constructor Summary
Weather_20_XMLParser()
           
 
Method Summary
 java.lang.String getType()
           
 boolean isMyType(org.jdom.Document document)
          run this method only on documents returned by the "local" method (of Weather.com).
protected  BarometricPressure parseBarometricPressure(org.jdom.Element root)
           
protected  CurrentConditions parseCurrentConditions(org.jdom.Element root)
          Parses the root element of a WeatherChannel looking for Current Conditions.
protected  Day parseDay(org.jdom.Element dayRoot)
           
protected  DayPart parseDayPart(org.jdom.Element dayPartRoot)
           
protected  void parseError(org.jdom.Element root)
          In case of an error, throw WeatherError exception.
protected  Forecast parseForecast(org.jdom.Element weatherRoot)
          Parses the root element of a WeatherChannel looking for the Forecast.
protected  Header parseHeader(org.jdom.Element weatherRoot)
          Parses the root element of a WeatherChannel looking for the Header.
protected  Location parseLocation(org.jdom.Element weatherRoot)
          Parses the root element of a WeatherChannel looking for the Location.
protected  SearchLocation parseSearchLocation(org.jdom.Element locationElement)
           
protected  SearchLocations parseSearchQuery(org.jdom.Document document)
           
protected  UltraViolet parseUV(org.jdom.Element root)
           
 WeatherReport parseWeatherQuery(org.jdom.Document document, boolean validate)
          this method actually parses the "local" query's response document into a WeatherReport object.
protected  WeatherReport parseWeatherResponse(org.jdom.Element root)
          Parses the root element of a JDOM document into a WeatherChannel bean.
protected  Wind parseWind(org.jdom.Element windRoot)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEATHER_ROOT

public static final java.lang.String WEATHER_ROOT
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

WEATHER_RESPONSE_VERSION

public static final java.lang.String WEATHER_RESPONSE_VERSION
See Also:
Constant Field Values

HEAD

public static final java.lang.String HEAD
See Also:
Constant Field Values

LOCALE

public static final java.lang.String LOCALE
See Also:
Constant Field Values

FORM

public static final java.lang.String FORM
See Also:
Constant Field Values

TEMPERATURE_UNIT

public static final java.lang.String TEMPERATURE_UNIT
See Also:
Constant Field Values

DISTANCE_UNIT

public static final java.lang.String DISTANCE_UNIT
See Also:
Constant Field Values

SPEED_UNIT

public static final java.lang.String SPEED_UNIT
See Also:
Constant Field Values

PRECIPITATION_UNIT

public static final java.lang.String PRECIPITATION_UNIT
See Also:
Constant Field Values

PRESSURE_UNIT

public static final java.lang.String PRESSURE_UNIT
See Also:
Constant Field Values

LOCATION

public static final java.lang.String LOCATION
See Also:
Constant Field Values

LOCATION_ID

public static final java.lang.String LOCATION_ID
See Also:
Constant Field Values

DISPLAY_NAME

public static final java.lang.String DISPLAY_NAME
See Also:
Constant Field Values

LOCAL_TIME

public static final java.lang.String LOCAL_TIME
See Also:
Constant Field Values

LATITUDE

public static final java.lang.String LATITUDE
See Also:
Constant Field Values

LONGITUDE

public static final java.lang.String LONGITUDE
See Also:
Constant Field Values

SUNRISE_TIME

public static final java.lang.String SUNRISE_TIME
See Also:
Constant Field Values

SUNSET_TIME

public static final java.lang.String SUNSET_TIME
See Also:
Constant Field Values

TIMEZONE

public static final java.lang.String TIMEZONE
See Also:
Constant Field Values

CURRENT_CONDITIONS

public static final java.lang.String CURRENT_CONDITIONS
See Also:
Constant Field Values

LAST_UPDATED

public static final java.lang.String LAST_UPDATED
See Also:
Constant Field Values

OBSERVATION_STATION

public static final java.lang.String OBSERVATION_STATION
See Also:
Constant Field Values

TEMPERATURE

public static final java.lang.String TEMPERATURE
See Also:
Constant Field Values

FEELS_LIKE_TEMP

public static final java.lang.String FEELS_LIKE_TEMP
See Also:
Constant Field Values

DESCRIPTION

public static final java.lang.String DESCRIPTION
See Also:
Constant Field Values

ICON

public static final java.lang.String ICON
See Also:
Constant Field Values

BAROMETRIC_PRESSURE

public static final java.lang.String BAROMETRIC_PRESSURE
See Also:
Constant Field Values

PRESSURE

public static final java.lang.String PRESSURE
See Also:
Constant Field Values

PRESSURE_TREND

public static final java.lang.String PRESSURE_TREND
See Also:
Constant Field Values

WIND

public static final java.lang.String WIND
See Also:
Constant Field Values

WIND_SPEED

public static final java.lang.String WIND_SPEED
See Also:
Constant Field Values

WIND_GUST_SPEED

public static final java.lang.String WIND_GUST_SPEED
See Also:
Constant Field Values

WIND_DEGREES

public static final java.lang.String WIND_DEGREES
See Also:
Constant Field Values

WIND_DIRECTION

public static final java.lang.String WIND_DIRECTION
See Also:
Constant Field Values

HUMIDITY

public static final java.lang.String HUMIDITY
See Also:
Constant Field Values

VISIBILITY

public static final java.lang.String VISIBILITY
See Also:
Constant Field Values

UV

public static final java.lang.String UV
See Also:
Constant Field Values

UV_INDEX

public static final java.lang.String UV_INDEX
See Also:
Constant Field Values

UV_DESCRIPTION

public static final java.lang.String UV_DESCRIPTION
See Also:
Constant Field Values

DEWPOINT

public static final java.lang.String DEWPOINT
See Also:
Constant Field Values

FORECAST

public static final java.lang.String FORECAST
See Also:
Constant Field Values

DAY

public static final java.lang.String DAY
See Also:
Constant Field Values

DAY_PART

public static final java.lang.String DAY_PART
See Also:
Constant Field Values

DAY_OR_NIGHT

public static final java.lang.String DAY_OR_NIGHT
See Also:
Constant Field Values

DAY_PART_DAY

public static final java.lang.String DAY_PART_DAY
See Also:
Constant Field Values

DAY_PART_NIGHT

public static final java.lang.String DAY_PART_NIGHT
See Also:
Constant Field Values

HIGH_TEMP

public static final java.lang.String HIGH_TEMP
See Also:
Constant Field Values

LOW_TEMP

public static final java.lang.String LOW_TEMP
See Also:
Constant Field Values

PRECIPITATION_CHANCE

public static final java.lang.String PRECIPITATION_CHANCE
See Also:
Constant Field Values

DAY_INDEX

public static final java.lang.String DAY_INDEX
See Also:
Constant Field Values

DAY_OF_WEEK

public static final java.lang.String DAY_OF_WEEK
See Also:
Constant Field Values

DAY_DATE

public static final java.lang.String DAY_DATE
See Also:
Constant Field Values

ERROR_ROOT

public static final java.lang.String ERROR_ROOT
See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
See Also:
Constant Field Values

ERROR_TYPE_ATTRIB

public static final java.lang.String ERROR_TYPE_ATTRIB
See Also:
Constant Field Values

NO_ERROR_TYPE_SET

public static final java.lang.String NO_ERROR_TYPE_SET
See Also:
Constant Field Values

UNKNOWN_ERROR

public static final java.lang.String UNKNOWN_ERROR
See Also:
Constant Field Values

NO_LOCATION_PROVIDED_ERROR

public static final java.lang.String NO_LOCATION_PROVIDED_ERROR
See Also:
Constant Field Values

INVALID_LOCATION_PROVIDED_ERROR

public static final java.lang.String INVALID_LOCATION_PROVIDED_ERROR
See Also:
Constant Field Values

INVALID_PARTNERID_ERROR

public static final java.lang.String INVALID_PARTNERID_ERROR
See Also:
Constant Field Values

INVALID_PRODUCT_CODE

public static final java.lang.String INVALID_PRODUCT_CODE
See Also:
Constant Field Values

INVALID_LICENSE_KEY

public static final java.lang.String INVALID_LICENSE_KEY
See Also:
Constant Field Values

SEARCH_ROOT

public static final java.lang.String SEARCH_ROOT
See Also:
Constant Field Values

SEARCH_VERSION_ATTRIBUTE

public static final java.lang.String SEARCH_VERSION_ATTRIBUTE
See Also:
Constant Field Values

SEARCH_VERSION_ATTRIBUTE_VALUE

public static final java.lang.String SEARCH_VERSION_ATTRIBUTE_VALUE
See Also:
Constant Field Values

SEARCH_LOCATION_ELEMENT

public static final java.lang.String SEARCH_LOCATION_ELEMENT
See Also:
Constant Field Values

SEARCH_LOCATION_ATTRIBUTE_ID

public static final java.lang.String SEARCH_LOCATION_ATTRIBUTE_ID
See Also:
Constant Field Values

SEARCH_LOCATION_ATTRIBUTE_TYPE

public static final java.lang.String SEARCH_LOCATION_ATTRIBUTE_TYPE
See Also:
Constant Field Values
Constructor Detail

Weather_20_XMLParser

public Weather_20_XMLParser()
Method Detail

parseSearchQuery

protected SearchLocations parseSearchQuery(org.jdom.Document document)
                                    throws WeatherError,
                                           java.lang.NullPointerException
Parameters:
document -
Returns:
the SearchLocations object may be empty, so be sure to check the size before using it
Throws:
WeatherError
java.lang.NullPointerException - - if some of the elements or attributes are not found, then this exception can be thrown, which implies there is a parsing issue (which will be thrown by the caller of this method)

parseSearchLocation

protected SearchLocation parseSearchLocation(org.jdom.Element locationElement)

isMyType

public boolean isMyType(org.jdom.Document document)
                 throws WeatherError
run this method only on documents returned by the "local" method (of Weather.com). if you run this on the "search" responses or "error" responses, it will not work!

Parameters:
document - - only pass it documents that contain responses from the "local" method; no not pass "error" or "search" responses
Returns:
Throws:
WeatherError - - if there is some problem parsing the document then it throws a WeatherError.WEATHER_PARSING_ERROR

parseWeatherQuery

public WeatherReport parseWeatherQuery(org.jdom.Document document,
                                       boolean validate)
                                throws WeatherError
this method actually parses the "local" query's response document into a WeatherReport object.

Parameters:
document -
validate -
Returns:
Throws:
WeatherError

getType

public java.lang.String getType()

parseWeatherResponse

protected WeatherReport parseWeatherResponse(org.jdom.Element root)
Parses the root element of a JDOM document into a WeatherChannel bean. No exceptions are thrown - these methods try their best to fill the bean up with data, and just leave properties empty when they can't.

Parameters:
root - the root element of the JDOM document to parse.
Returns:
the parsed WeatherChannel bean.

parseHeader

protected Header parseHeader(org.jdom.Element weatherRoot)
Parses the root element of a WeatherChannel looking for the Header.

Parameters:
weatherRoot - the root element of the document to parse for the Header.
Returns:
the parsed Header bean.

parseLocation

protected Location parseLocation(org.jdom.Element weatherRoot)
Parses the root element of a WeatherChannel looking for the Location.

Parameters:
weatherRoot - the root element of the document to parse for the Location.
Returns:
the parsed Location bean.

parseForecast

protected Forecast parseForecast(org.jdom.Element weatherRoot)
Parses the root element of a WeatherChannel looking for the Forecast.

Parameters:
weatherRoot - the root element of the document to parse for the Forecast.
Returns:
the parsed Forecast bean.

parseCurrentConditions

protected CurrentConditions parseCurrentConditions(org.jdom.Element root)
Parses the root element of a WeatherChannel looking for Current Conditions.

Parameters:
root - the root element of the document to parse for Current Conditions.
Returns:
the parsed CurrentConditions bean.

parseDay

protected Day parseDay(org.jdom.Element dayRoot)

parseDayPart

protected DayPart parseDayPart(org.jdom.Element dayPartRoot)

parseWind

protected Wind parseWind(org.jdom.Element windRoot)

parseBarometricPressure

protected BarometricPressure parseBarometricPressure(org.jdom.Element root)

parseUV

protected UltraViolet parseUV(org.jdom.Element root)

parseError

protected void parseError(org.jdom.Element root)
                   throws WeatherError
In case of an error, throw WeatherError exception. This reports application exceptions, not protocol exceptions. Application exceptions are: parsing exceptions, or error conditions reported by weather.com

Parameters:
root - the root element of the document to parse for the weather.
Throws:
WeatherError - - this exception is thrown if a problem is found while parsing the document