Package org.sonatype.mavenbook.weather.model

Examples of org.sonatype.mavenbook.weather.model.Weather


  public Main(String zip) {
    this.zip = zip;
  }

  public void getWeather() throws Exception {
    Weather weather = weatherService.retrieveForecast(zip);
    weatherDAO.save( weather );
    System.out.print(new WeatherFormatter().formatWeather(weather));
  }
View Full Code Here


  public Weather retrieveForecast(String zip) throws Exception {
    // Retrieve Data
    InputStream dataIn = yahooRetriever.retrieve(zip);

    // Parse DataS
    Weather weather = yahooParser.parse(zip, dataIn);

    return weather;
  }
View Full Code Here

  public ModelAndView handleRequest(HttpServletRequest request,
      HttpServletResponse response) throws Exception {

    String zip = request.getParameter("zip");
    Weather weather = weatherService.retrieveForecast(zip);
    weatherDAO.save(weather);
    return new ModelAndView("weather", "weather", weather);
  }
View Full Code Here

public class YahooParser {

    private static Logger log = Logger.getLogger(YahooParser.class);
   
    public Weather parse(String zip, InputStream inputStream) throws Exception {
  Weather weather = new Weather();
 
  log.info( "Creating XML Reader" );
  SAXReader xmlReader = createXmlReader();
  Document doc = xmlReader.read( inputStream );
 
  log.info( "Parsing XML Response" );
  Location location = new Location();
  location.setCity( doc.valueOf("/rss/channel/y:location/@city") );
  location.setRegion( doc.valueOf("/rss/channel/y:location/@region") );
  location.setCountry( doc.valueOf("/rss/channel/y:location/@country") );
  location.setZip( zip );
  weather.setLocation( location );

  Condition condition = new Condition();
  condition.setText( doc.valueOf("/rss/channel/item/y:condition/@text") );
  condition.setTemp( doc.valueOf("/rss/channel/item/y:condition/@temp") );
  condition.setCode( doc.valueOf("/rss/channel/item/y:condition/@code") );
  condition.setDate( doc.valueOf("/rss/channel/item/y:condition/@date") );
  condition.setWeather( weather );
  weather.setCondition( condition );

  Atmosphere atmosphere = new Atmosphere();
  atmosphere.setHumidity( doc.valueOf("/rss/channel/y:atmosphere/@humidity") );
  atmosphere.setVisibility( doc.valueOf("/rss/channel/y:atmosphere/@visibility") );
  atmosphere.setPressure( doc.valueOf("/rss/channel/y:atmosphere/@pressure") );
  atmosphere.setRising( doc.valueOf("/rss/channel/y:atmosphere/@rising") );
  atmosphere.setWeather( weather );
  weather.setAtmosphere( atmosphere );

  Wind wind = new Wind();
  wind.setChill( doc.valueOf("/rss/channel/y:wind/@chill") );
  wind.setDirection( doc.valueOf("/rss/channel/y:wind/@direction") );
  wind.setSpeed( doc.valueOf("/rss/channel/y:wind/@speed") );
  wind.setWeather( weather );
  weather.setWind( wind );

  weather.setDate( new Date() );
 
  return weather;
    }
View Full Code Here

  }
 
  public void testParser() throws Exception {
    InputStream nyData =
      getClass().getClassLoader().getResourceAsStream("ny-weather.xml");
    Weather weather = new YahooParser().parse( "10002", nyData );
    assertEquals( "New York", weather.getLocation().getCity() );
    assertEquals( "NY", weather.getLocation().getRegion() );
    assertEquals( "US", weather.getLocation().getCountry() );
    assertEquals( "39", weather.getCondition().getTemp() );
    assertEquals( "Fair", weather.getCondition().getText() );
    assertEquals( "39", weather.getWind().getChill() );
    assertEquals( "67", weather.getAtmosphere().getHumidity() );
  }
View Full Code Here

TOP

Related Classes of org.sonatype.mavenbook.weather.model.Weather

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.