cz.cvut.fel.uherjir2
Class WeatherUtil

java.lang.Object
  extended by cz.cvut.fel.uherjir2.WeatherUtil
All Implemented Interfaces:
java.lang.Runnable

public class WeatherUtil
extends java.lang.Object
implements java.lang.Runnable

Class WeatherUtil contains all needed methods for downloading and parsing weather forecasts for specified locations. It also manages AIML files containing these information.
All information is downloaded from www.weather-forecast.com

Author:
Jirka Uher

Field Summary
(package private) static java.lang.String AIML_FOOTER
           
(package private) static java.lang.String AIML_HEADER
          AIML file header.
(package private) static java.lang.String AIMLS_PATH
          Path to AIML files.
(package private) static java.util.TreeSet<java.io.File> FILES_TO_FIX
          Files that need to be updated.
(package private) static java.util.TreeSet<java.io.File> FIXED_FILES
          Files that were already updated.
(package private) static java.lang.String LINE_SEPARATOR
          Line separator.
(package private) static java.util.TreeSet<java.lang.String> LOCATIONS
          List of supported locations.
(package private) static java.lang.String LOCATIONS_PATH
          Path to locations file.
private static GUIConsole parentGuiConsole
          Connection to parent gui console to load AIML files.
static boolean SHUTDOWN
          Indicates if shutdown was requested
private static java.lang.Thread thisThread
          Reference to this thread.
(package private) static int TIMEOUT
          Timeout for connection.
(package private) static java.lang.String URL_END
          Url postfix.
(package private) static java.lang.String URL_START
          Url prefix.
(package private) static java.lang.String USER_AGENT
          Sent user agent.
 
Constructor Summary
WeatherUtil(GUIConsole guiConsole)
          Starts this class in a daemon thread in a background.
 
Method Summary
static void FetchFilesToFix()
          Fetches files that dont exist yet or are too old and need update.
static java.util.Vector<DayWeatherInfo> FetchWeather(java.lang.String location)
          Grabs and parse html code for given location.
static void FixFiles()
          Cycles throught files to fix and does all necesary actions like fetching weather information and saving aiml files to disk.
static java.lang.String GrabHTML(java.lang.String urlString)
          Grabs raw html code from given urlString.
static void LoadLocations()
          Loads supported locations from locations file.
 void run()
           
static boolean SaveWeatherFileToDisk(java.io.File file, java.util.Vector<DayWeatherInfo> weatherInfos)
          Saves weather information to aiml files on disk.
static void shutdown()
          Shutdowns WeatherUtils
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

static final int TIMEOUT
Timeout for connection.

See Also:
Constant Field Values

URL_START

static final java.lang.String URL_START
Url prefix.

See Also:
Constant Field Values

URL_END

static final java.lang.String URL_END
Url postfix.

See Also:
Constant Field Values

USER_AGENT

static final java.lang.String USER_AGENT
Sent user agent.

See Also:
Constant Field Values

LINE_SEPARATOR

static final java.lang.String LINE_SEPARATOR
Line separator.


AIML_HEADER

static final java.lang.String AIML_HEADER
AIML file header.

See Also:
Constant Field Values

AIML_FOOTER

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

LOCATIONS_PATH

static final java.lang.String LOCATIONS_PATH
Path to locations file.

See Also:
Constant Field Values

AIMLS_PATH

static final java.lang.String AIMLS_PATH
Path to AIML files.

See Also:
Constant Field Values

LOCATIONS

static java.util.TreeSet<java.lang.String> LOCATIONS
List of supported locations.


FILES_TO_FIX

static java.util.TreeSet<java.io.File> FILES_TO_FIX
Files that need to be updated.


FIXED_FILES

static java.util.TreeSet<java.io.File> FIXED_FILES
Files that were already updated.


SHUTDOWN

public static boolean SHUTDOWN
Indicates if shutdown was requested


parentGuiConsole

private static GUIConsole parentGuiConsole
Connection to parent gui console to load AIML files.


thisThread

private static java.lang.Thread thisThread
Reference to this thread.

Constructor Detail

WeatherUtil

public WeatherUtil(GUIConsole guiConsole)
Starts this class in a daemon thread in a background.

Parameters:
guiConsole -
Method Detail

GrabHTML

public static java.lang.String GrabHTML(java.lang.String urlString)
Grabs raw html code from given urlString.

Parameters:
urlString - Given url to be downloaded.
Returns:
Raw html code for url

FetchWeather

public static java.util.Vector<DayWeatherInfo> FetchWeather(java.lang.String location)
Grabs and parse html code for given location.

Parameters:
location - Location to download information about.
Returns:
Vector of DayWeatherInfo, last element is current weather info.
Null if either url doesnt exist or there was an connection error.

LoadLocations

public static void LoadLocations()
Loads supported locations from locations file.


FetchFilesToFix

public static void FetchFilesToFix()
Fetches files that dont exist yet or are too old and need update.


FixFiles

public static void FixFiles()
Cycles throught files to fix and does all necesary actions like fetching weather information and saving aiml files to disk.


SaveWeatherFileToDisk

public static boolean SaveWeatherFileToDisk(java.io.File file,
                                            java.util.Vector<DayWeatherInfo> weatherInfos)
Saves weather information to aiml files on disk.

Parameters:
file - File where to save
weatherInfos - Weather information to save
Returns:
true if everything was successfull

run

public void run()
Specified by:
run in interface java.lang.Runnable

shutdown

public static void shutdown()
Shutdowns WeatherUtils