public void generate(Module module, Element element) {
if(!(module instanceof YWeatherModuleImpl)) {
return;
}
YWeatherModuleImpl weather = (YWeatherModuleImpl) module;
if(weather.getAstronomy() != null) {
Element astro = new Element("astronomy", WeatherModuleGenerator.NS);
if(weather.getAstronomy().getSunrise() != null) {
astro.setAttribute("sunrise",
TIME_ONLY.format(weather.getAstronomy().getSunrise())
.toLowerCase());
}
if(weather.getAstronomy().getSunrise() != null) {
astro.setAttribute("sunset",
TIME_ONLY.format(weather.getAstronomy().getSunset())
.toLowerCase());
}
element.addContent(astro);
}
if(weather.getAtmosphere() != null) {
Element atmos = new Element("atmosphere", WeatherModuleGenerator.NS);
atmos.setAttribute("humidity",
Integer.toString(weather.getAtmosphere().getHumidity()));
atmos.setAttribute("visibility",
Integer.toString(
(int) (weather.getAtmosphere().getVisibility() * 100d)));
atmos.setAttribute("pressure",
Double.toString(weather.getAtmosphere().getPressure()));
if(weather.getAtmosphere().getChange() != null) {
atmos.setAttribute("rising",
Integer.toString(weather.getAtmosphere().getChange()
.getCode()));
}
element.addContent(atmos);
}
if(weather.getCondition() != null) {
Element condition = new Element("condition",
WeatherModuleGenerator.NS);
if(weather.getCondition().getText() != null) {
condition.setAttribute("text", weather.getCondition().getText());
}
if(weather.getCondition().getCode() != null) {
condition.setAttribute("code",
Integer.toString(weather.getCondition().getCode().getCode()));
}
if(weather.getCondition().getDate() != null) {
condition.setAttribute("date",
LONG_DATE.format(weather.getCondition().getDate())
.replaceAll("AM", "am").replaceAll("PM", "pm"));
}
condition.setAttribute("temp",
Integer.toString(weather.getCondition().getTemperature()));
element.addContent(condition);
}
if(weather.getLocation() != null) {
Element location = new Element("location", WeatherModuleGenerator.NS);
if(weather.getLocation().getCity() != null) {
location.setAttribute("city", weather.getLocation().getCity());
}
if(weather.getLocation().getRegion() != null) {
location.setAttribute("region",
weather.getLocation().getRegion());
}
if(weather.getLocation().getCountry() != null) {
location.setAttribute("country",
weather.getLocation().getCountry());
}
element.addContent(location);
}
if(weather.getUnits() != null) {
Element units = new Element("units", WeatherModuleGenerator.NS);
if(weather.getUnits().getDistance() != null) {
units.setAttribute("distance", weather.getUnits().getDistance());
}
if(weather.getUnits().getPressure() != null) {
units.setAttribute("pressure", weather.getUnits().getPressure());
}
if(weather.getUnits().getSpeed() != null) {
units.setAttribute("speed", weather.getUnits().getSpeed());
}
if(weather.getUnits().getTemperature() != null) {
units.setAttribute("temperature",
weather.getUnits().getTemperature());
}
element.addContent(units);
}
if(weather.getWind() != null) {
Element wind = new Element("wind", WeatherModuleGenerator.NS);
wind.setAttribute("chill",
Integer.toString(weather.getWind().getChill()));
wind.setAttribute("direction",
Integer.toString(weather.getWind().getDirection()));
wind.setAttribute("speed",
Integer.toString(weather.getWind().getSpeed()));
element.addContent(wind);
}
if(weather.getForecasts() != null) {
for(int i = 0; i < weather.getForecasts().length; i++) {
Element forecast = new Element("forecast",
WeatherModuleGenerator.NS);
Forecast f = weather.getForecasts()[i];
if(f.getCode() != null) {
forecast.setAttribute("code",
Integer.toString(f.getCode().getCode()));
}