import name.gumartinm.weather.information.model.DatabaseQueries;
import name.gumartinm.weather.information.model.WeatherLocation;
import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.parser.JPOSWeatherParser;
+import name.gumartinm.weather.information.parser.JPOSCurrentParser;
import name.gumartinm.weather.information.service.IconsList;
import name.gumartinm.weather.information.service.PermanentStorage;
-import name.gumartinm.weather.information.service.ServiceParser;
+import name.gumartinm.weather.information.service.ServiceCurrentParser;
import name.gumartinm.weather.information.widget.WidgetProvider;
public class CurrentFragment extends Fragment {
final CurrentTask task = new CurrentTask(
this.getActivity().getApplicationContext(),
new CustomHTTPClient(AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent")),
- new ServiceParser(new JPOSWeatherParser()));
+ new ServiceCurrentParser(new JPOSCurrentParser()));
task.execute(weatherLocation.getLatitude(), weatherLocation.getLongitude());
}
// Store the context passed to the AsyncTask when the system instantiates it.
private final Context localContext;
final CustomHTTPClient HTTPClient;
- final ServiceParser weatherService;
+ final ServiceCurrentParser weatherService;
public CurrentTask(final Context context, final CustomHTTPClient HTTPClient,
- final ServiceParser weatherService) {
+ final ServiceCurrentParser weatherService) {
this.localContext = context;
this.HTTPClient = HTTPClient;
this.weatherService = weatherService;
import name.gumartinm.weather.information.model.DatabaseQueries;
import name.gumartinm.weather.information.model.WeatherLocation;
import name.gumartinm.weather.information.model.forecastweather.Forecast;
-import name.gumartinm.weather.information.parser.JPOSWeatherParser;
+import name.gumartinm.weather.information.parser.JPOSForecastParser;
import name.gumartinm.weather.information.service.IconsList;
import name.gumartinm.weather.information.service.PermanentStorage;
-import name.gumartinm.weather.information.service.ServiceParser;
+import name.gumartinm.weather.information.service.ServiceForecastParser;
public class OverviewFragment extends ListFragment {
private static final String TAG = "OverviewFragment";
final OverviewTask task = new OverviewTask(
this.getActivity().getApplicationContext(),
new CustomHTTPClient(AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent")),
- new ServiceParser(new JPOSWeatherParser()));
+ new ServiceForecastParser(new JPOSForecastParser()));
task.execute(weatherLocation.getLatitude(), weatherLocation.getLongitude());
}
// Store the context passed to the AsyncTask when the system instantiates it.
private final Context localContext;
private final CustomHTTPClient HTTPClient;
- private final ServiceParser weatherService;
+ private final ServiceForecastParser weatherService;
public OverviewTask(final Context context, final CustomHTTPClient HTTPClient,
- final ServiceParser weatherService) {
+ final ServiceForecastParser weatherService) {
this.localContext = context;
this.HTTPClient = HTTPClient;
this.weatherService = weatherService;
import name.gumartinm.weather.information.model.DatabaseQueries;
import name.gumartinm.weather.information.model.WeatherLocation;
import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.parser.JPOSWeatherParser;
+import name.gumartinm.weather.information.parser.JPOSCurrentParser;
import name.gumartinm.weather.information.service.IconsList;
-import name.gumartinm.weather.information.service.ServiceParser;
+import name.gumartinm.weather.information.service.ServiceCurrentParser;
public class NotificationIntentService extends IntentService {
final WeatherLocation weatherLocation = query.queryDataBase();
if (weatherLocation != null) {
- final ServiceParser weatherService = new ServiceParser(new JPOSWeatherParser());
+ final ServiceCurrentParser weatherService = new ServiceCurrentParser(new JPOSCurrentParser());
final CustomHTTPClient HTTPClient = new CustomHTTPClient(
AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent"));
}
private Current doInBackgroundThrowable(final WeatherLocation weatherLocation,
- final CustomHTTPClient HTTPClient, final ServiceParser weatherService)
+ final CustomHTTPClient HTTPClient, final ServiceCurrentParser weatherService)
throws ClientProtocolException, MalformedURLException, URISyntaxException,
JsonParseException, IOException {
+++ /dev/null
-package name.gumartinm.weather.information.parser;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.model.forecastweather.Forecast;
-
-import java.io.IOException;
-
-
-public interface IJPOSParser {
-
- public Current retrieveCurrenFromJPOS(final String jsonData)
- throws JsonParseException, IOException;
-
- public Forecast retrieveForecastFromJPOS(final String jsonData)
- throws JsonParseException, IOException;
-}
--- /dev/null
+package name.gumartinm.weather.information.parser;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import name.gumartinm.weather.information.model.currentweather.Clouds;
+import name.gumartinm.weather.information.model.currentweather.Coord;
+import name.gumartinm.weather.information.model.currentweather.Current;
+import name.gumartinm.weather.information.model.currentweather.Main;
+import name.gumartinm.weather.information.model.currentweather.Rain;
+import name.gumartinm.weather.information.model.currentweather.Snow;
+import name.gumartinm.weather.information.model.currentweather.Sys;
+import name.gumartinm.weather.information.model.currentweather.Weather;
+import name.gumartinm.weather.information.model.currentweather.Wind;
+
+public class JPOSCurrentParser {
+
+ public Current retrieveCurrenFromJPOS(final String jsonData)
+ throws JsonParseException, IOException {
+ final JsonFactory f = new JsonFactory();
+
+ final Current currentWeatherData = new Current();
+ currentWeatherData.setClouds(new Clouds());
+ currentWeatherData.setCoord(new Coord());
+ currentWeatherData.setMain(new Main());
+ currentWeatherData.setRain(new Rain());
+ currentWeatherData.setSys(new Sys());
+ currentWeatherData.setSnow(new Snow());
+ currentWeatherData
+ .setWeather(new ArrayList<Weather>());
+ currentWeatherData.setWind(new Wind());
+ final JsonParser jParser = f.createParser(jsonData);
+
+ this.getCurrentWeatherData(currentWeatherData, jParser);
+
+ return currentWeatherData;
+ }
+
+ private void getCurrentWeatherData(final Current currentWeatherData,
+ final JsonParser jParser) throws JsonParseException, IOException {
+ if (jParser.nextToken() == JsonToken.START_OBJECT) {
+
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String fieldname = jParser.getCurrentName();
+ final JsonToken nextToken = jParser.nextToken();
+ if (nextToken == JsonToken.START_OBJECT) {
+ this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
+ }
+ if (nextToken == JsonToken.START_ARRAY) {
+ JsonToken tokenNext = jParser.nextToken();
+ while (tokenNext != JsonToken.END_ARRAY) {
+ if (tokenNext == JsonToken.START_OBJECT) {
+ this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
+ }
+ tokenNext = jParser.nextToken();
+ }
+ }
+ if ((nextToken == JsonToken.VALUE_NUMBER_INT)
+ || (nextToken == JsonToken.VALUE_STRING)) {
+ this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
+ }
+ }
+ }
+ }
+
+ private void getCurrentWeatherDataObjects(final Current currentWeatherData,
+ final JsonParser jParser, final String fieldname) throws JsonParseException,
+ IOException {
+ if ("coord".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("lon".equals(namefield)) {
+ currentWeatherData.getCoord().setLon(jParser.getDoubleValue());
+ }
+ if ("lat".equals(namefield)) {
+ currentWeatherData.getCoord().setLat(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("sys".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("message".equals(namefield)) {
+ currentWeatherData.getSys().setMessage(jParser.getDoubleValue());
+ }
+ if ("country".equals(namefield)) {
+ currentWeatherData.getSys().setCountry(jParser.getValueAsString());
+ }
+ if ("sunrise".equals(namefield)) {
+ currentWeatherData.getSys().setSunrise(jParser.getValueAsLong());
+ }
+ if ("sunset".equals(namefield)) {
+ currentWeatherData.getSys().setSunset(jParser.getValueAsLong());
+ }
+ }
+ }
+ if ("weather".equals(fieldname)) {
+ final Weather weather = new Weather();
+ currentWeatherData.getWeather().add(weather);
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("id".equals(namefield)) {
+ weather.setId(jParser.getIntValue());
+ }
+ if ("main".equals(namefield)) {
+ weather.setMain(jParser.getText());
+ }
+ if ("description".equals(namefield)) {
+ weather.setDescription(jParser.getText());
+ }
+ if ("icon".equals(namefield)) {
+ weather.setIcon(jParser.getText());
+ }
+
+ }
+ }
+ if ("base".equals(fieldname)) {
+ currentWeatherData.setBase(jParser.getText());
+ }
+ if ("main".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("temp".equals(namefield)) {
+ currentWeatherData.getMain().setTemp(jParser.getDoubleValue());
+ }
+ if ("temp_min".equals(namefield)) {
+ currentWeatherData.getMain().setTemp_min(jParser.getDoubleValue());
+ }
+ if ("temp_max".equals(namefield)) {
+ currentWeatherData.getMain().setTemp_max(jParser.getDoubleValue());
+ }
+ if ("pressure".equals(namefield)) {
+ currentWeatherData.getMain().setPressure(jParser.getDoubleValue());
+ }
+ if ("sea_level".equals(namefield)) {
+ currentWeatherData.getMain().setSea_level(jParser.getDoubleValue());
+ }
+ if ("grnd_level".equals(namefield)) {
+ currentWeatherData.getMain().setGrnd_level(jParser.getDoubleValue());
+ }
+ if ("humidity".equals(namefield)) {
+ currentWeatherData.getMain().setHumidity(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("wind".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("speed".equals(namefield)) {
+ currentWeatherData.getWind().setSpeed(jParser.getDoubleValue());
+ }
+ if ("deg".equals(namefield)) {
+ currentWeatherData.getWind().setDeg(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("clouds".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("all".equals(namefield)) {
+ currentWeatherData.getClouds().setAll(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("dt".equals(fieldname)) {
+ currentWeatherData.setDt(jParser.getLongValue());
+ }
+ if ("rain".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("3h".equals(namefield)) {
+ currentWeatherData.getRain().set3h(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("snow".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("3h".equals(namefield)) {
+ currentWeatherData.getSnow().set3h(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("id".equals(fieldname)) {
+ currentWeatherData.setId(jParser.getLongValue());
+ }
+ if ("name".equals(fieldname)) {
+ currentWeatherData.setName(jParser.getText());
+ }
+ if ("cod".equals(fieldname)) {
+ currentWeatherData.setCod(jParser.getIntValue());
+ }
+ }
+}
--- /dev/null
+package name.gumartinm.weather.information.parser;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import name.gumartinm.weather.information.model.forecastweather.City;
+import name.gumartinm.weather.information.model.forecastweather.Coord;
+import name.gumartinm.weather.information.model.forecastweather.Forecast;
+import name.gumartinm.weather.information.model.forecastweather.List;
+import name.gumartinm.weather.information.model.forecastweather.Temp;
+import name.gumartinm.weather.information.model.forecastweather.Weather;
+
+public class JPOSForecastParser {
+
+ public Forecast retrieveForecastFromJPOS(final String jsonData)
+ throws JsonParseException, IOException {
+ final JsonFactory f = new JsonFactory();
+
+ final Forecast forecastWeatherData = new Forecast();
+ forecastWeatherData
+ .setList(new ArrayList<List>(15));
+ final City city = new City();
+ city.setCoord(new Coord());
+ forecastWeatherData.setCity(city);
+ final JsonParser jParser = f.createParser(jsonData);
+
+ this.getForecastWeatherData(forecastWeatherData, jParser);
+
+ return forecastWeatherData;
+ }
+
+ private void getForecastWeatherData(final Forecast forecastWeatherData,
+ final JsonParser jParser) throws JsonParseException, IOException {
+ if (jParser.nextToken() == JsonToken.START_OBJECT) {
+
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String fieldname = jParser.getCurrentName();
+ final JsonToken nextToken = jParser.nextToken();
+ if (nextToken == JsonToken.START_OBJECT) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
+ }
+ if (nextToken == JsonToken.START_ARRAY) {
+ JsonToken tokenNext = jParser.nextToken();
+ while (tokenNext != JsonToken.END_ARRAY) {
+ if (tokenNext == JsonToken.START_OBJECT) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
+ }
+ tokenNext = jParser.nextToken();
+ }
+ }
+ if ((nextToken == JsonToken.VALUE_NUMBER_INT)
+ || (nextToken == JsonToken.VALUE_STRING)) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
+ }
+ }
+ }
+ }
+
+ private void getForecastWeatherDataObjects(final Forecast forecastWeatherData,
+ final JsonParser jParser, final String fieldname) throws JsonParseException,
+ IOException {
+
+ if ("cod".equals(fieldname)) {
+ final String stringCod = jParser.getText();
+ forecastWeatherData.setCod(Long.valueOf(stringCod));
+ }
+ if ("message".equals(fieldname)) {
+ forecastWeatherData.setMessage(jParser.getDoubleValue());
+ }
+ if ("city".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ final JsonToken nextToken = jParser.nextToken(); // move to
+ // value
+ if ("id".equals(namefield)) {
+ forecastWeatherData.getCity().setId(jParser.getLongValue());
+ }
+ if ("name".equals(namefield)) {
+ forecastWeatherData.getCity().setName(jParser.getText());
+ }
+ if ("coord".equals(namefield)) {
+ if (nextToken == JsonToken.START_OBJECT) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser, namefield);
+ }
+ }
+ if ("country".equals(namefield)) {
+ forecastWeatherData.getCity().setCountry(jParser.getText());
+ }
+ if ("population".equals(namefield)) {
+ forecastWeatherData.getCity().setPopulation(jParser.getLongValue());
+ }
+ }
+ }
+ if ("cnt".equals(fieldname)) {
+ forecastWeatherData.setCnt(jParser.getIntValue());
+ }
+ if ("coord".equals(fieldname)) {
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("lon".equals(namefield)) {
+ forecastWeatherData.getCity().getCoord().setLon(jParser.getDoubleValue());
+ }
+ if ("lat".equals(namefield)) {
+ forecastWeatherData.getCity().getCoord().setLat(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("list".equals(fieldname)) {
+ final name.gumartinm.weather.information.model.forecastweather.List list = new name.gumartinm.weather.information.model.forecastweather.List();
+ list.setTemp(new Temp());
+ list.setWeather(new ArrayList<Weather>());
+ forecastWeatherData.getList().add(list);
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ final JsonToken nextToken = jParser.nextToken(); // move to
+ // value
+ if ("dt".equals(namefield)) {
+ list.setDt(jParser.getLongValue());
+ }
+ if ("temp".equals(namefield)) {
+ if (nextToken == JsonToken.START_OBJECT) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser, namefield);
+ }
+ }
+ if ("pressure".equals(namefield)) {
+ list.setPressure(jParser.getDoubleValue());
+ }
+ if ("humidity".equals(namefield)) {
+ list.setHumidity(jParser.getDoubleValue());
+ }
+ if ("weather".equals(namefield)) {
+ if (nextToken == JsonToken.START_ARRAY) {
+ JsonToken tokenNext = jParser.nextToken();
+ while (tokenNext != JsonToken.END_ARRAY) {
+ if (tokenNext == JsonToken.START_OBJECT) {
+ this.getForecastWeatherDataObjects(forecastWeatherData, jParser,
+ namefield);
+ }
+ tokenNext = jParser.nextToken();
+ }
+ }
+ }
+ if ("speed".equals(namefield)) {
+ list.setSpeed(jParser.getDoubleValue());
+ }
+ if ("deg".equals(namefield)) {
+ list.setDeg(jParser.getDoubleValue());
+ }
+ if ("clouds".equals(namefield)) {
+ list.setClouds(jParser.getDoubleValue());
+ }
+ if ("rain".equals(namefield)) {
+ list.setRain(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("temp".equals(fieldname)) {
+ final name.gumartinm.weather.information.model.forecastweather.List list =
+ forecastWeatherData.getList().get((forecastWeatherData.getList().size() - 1));
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+ if ("day".equals(namefield)) {
+ list.getTemp().setDay(jParser.getDoubleValue());
+ }
+ if ("min".equals(namefield)) {
+ list.getTemp().setMin(jParser.getDoubleValue());
+ }
+ if ("max".equals(namefield)) {
+ list.getTemp().setMax(jParser.getDoubleValue());
+ }
+ if ("night".equals(namefield)) {
+ list.getTemp().setNight(jParser.getDoubleValue());
+ }
+ if ("eve".equals(namefield)) {
+ list.getTemp().setEve(jParser.getDoubleValue());
+ }
+ if ("morn".equals(namefield)) {
+ list.getTemp().setMorn(jParser.getDoubleValue());
+ }
+ }
+ }
+ if ("weather".equals(fieldname)) {
+ final name.gumartinm.weather.information.model.forecastweather.List list =
+ forecastWeatherData.getList().get((forecastWeatherData.getList().size() - 1));
+ final Weather weather = new Weather();
+ while (jParser.nextToken() != JsonToken.END_OBJECT) {
+ final String namefield = jParser.getCurrentName();
+ jParser.nextToken(); // move to value
+
+ if ("id".equals(namefield)) {
+ weather.setId(jParser.getIntValue());
+ }
+ if ("main".equals(namefield)) {
+ weather.setMain(jParser.getText());
+ }
+ if ("description".equals(namefield)) {
+ weather.setDescription(jParser.getText());
+ }
+ if ("icon".equals(namefield)) {
+ weather.setIcon(jParser.getText());
+ }
+ }
+ list.getWeather().add(weather);
+ }
+ }
+}
+++ /dev/null
-package name.gumartinm.weather.information.parser;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-import name.gumartinm.weather.information.model.currentweather.Clouds;
-import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.model.currentweather.Main;
-import name.gumartinm.weather.information.model.currentweather.Rain;
-import name.gumartinm.weather.information.model.currentweather.Snow;
-import name.gumartinm.weather.information.model.currentweather.Sys;
-import name.gumartinm.weather.information.model.currentweather.Wind;
-import name.gumartinm.weather.information.model.forecastweather.City;
-import name.gumartinm.weather.information.model.forecastweather.Forecast;
-import name.gumartinm.weather.information.model.forecastweather.Temp;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-public class JPOSWeatherParser implements IJPOSParser {
-
- @Override
- public Current retrieveCurrenFromJPOS(final String jsonData)
- throws JsonParseException, IOException {
- final JsonFactory f = new JsonFactory();
-
- final Current currentWeatherData = new Current();
- currentWeatherData.setClouds(new Clouds());
- currentWeatherData.setCoord(new name.gumartinm.weather.information.model.currentweather.Coord());
- currentWeatherData.setMain(new Main());
- currentWeatherData.setRain(new Rain());
- currentWeatherData.setSys(new Sys());
- currentWeatherData.setSnow(new Snow());
- currentWeatherData
- .setWeather(new ArrayList<name.gumartinm.weather.information.model.currentweather.Weather>());
- currentWeatherData.setWind(new Wind());
- final JsonParser jParser = f.createParser(jsonData);
-
- this.getCurrentWeatherData(currentWeatherData, jParser);
-
- return currentWeatherData;
- }
-
- @Override
- public Forecast retrieveForecastFromJPOS(final String jsonData)
- throws JsonParseException, IOException {
- final JsonFactory f = new JsonFactory();
-
- final Forecast forecastWeatherData = new Forecast();
- forecastWeatherData
- .setList(new ArrayList<name.gumartinm.weather.information.model.forecastweather.List>(15));
- final City city = new City();
- city.setCoord(new name.gumartinm.weather.information.model.forecastweather.Coord());
- forecastWeatherData.setCity(city);
- final JsonParser jParser = f.createParser(jsonData);
-
- this.getForecastWeatherData(forecastWeatherData, jParser);
-
- return forecastWeatherData;
- }
-
- private void getCurrentWeatherData(final Current currentWeatherData,
- final JsonParser jParser) throws JsonParseException, IOException {
- if (jParser.nextToken() == JsonToken.START_OBJECT) {
-
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String fieldname = jParser.getCurrentName();
- final JsonToken nextToken = jParser.nextToken();
- if (nextToken == JsonToken.START_OBJECT) {
- this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
- }
- if (nextToken == JsonToken.START_ARRAY) {
- JsonToken tokenNext = jParser.nextToken();
- while (tokenNext != JsonToken.END_ARRAY) {
- if (tokenNext == JsonToken.START_OBJECT) {
- this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
- }
- tokenNext = jParser.nextToken();
- }
- }
- if ((nextToken == JsonToken.VALUE_NUMBER_INT)
- || (nextToken == JsonToken.VALUE_STRING)) {
- this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname);
- }
- }
- }
- }
-
- private void getCurrentWeatherDataObjects(final Current currentWeatherData,
- final JsonParser jParser, final String fieldname) throws JsonParseException,
- IOException {
- if ("coord".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("lon".equals(namefield)) {
- currentWeatherData.getCoord().setLon(jParser.getDoubleValue());
- }
- if ("lat".equals(namefield)) {
- currentWeatherData.getCoord().setLat(jParser.getDoubleValue());
- }
- }
- }
- if ("sys".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("message".equals(namefield)) {
- currentWeatherData.getSys().setMessage(jParser.getDoubleValue());
- }
- if ("country".equals(namefield)) {
- currentWeatherData.getSys().setCountry(jParser.getValueAsString());
- }
- if ("sunrise".equals(namefield)) {
- currentWeatherData.getSys().setSunrise(jParser.getValueAsLong());
- }
- if ("sunset".equals(namefield)) {
- currentWeatherData.getSys().setSunset(jParser.getValueAsLong());
- }
- }
- }
- if ("weather".equals(fieldname)) {
- final name.gumartinm.weather.information.model.currentweather.Weather weather = new name.gumartinm.weather.information.model.currentweather.Weather();
- currentWeatherData.getWeather().add(weather);
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("id".equals(namefield)) {
- weather.setId(jParser.getIntValue());
- }
- if ("main".equals(namefield)) {
- weather.setMain(jParser.getText());
- }
- if ("description".equals(namefield)) {
- weather.setDescription(jParser.getText());
- }
- if ("icon".equals(namefield)) {
- weather.setIcon(jParser.getText());
- }
-
- }
- }
- if ("base".equals(fieldname)) {
- currentWeatherData.setBase(jParser.getText());
- }
- if ("main".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("temp".equals(namefield)) {
- currentWeatherData.getMain().setTemp(jParser.getDoubleValue());
- }
- if ("temp_min".equals(namefield)) {
- currentWeatherData.getMain().setTemp_min(jParser.getDoubleValue());
- }
- if ("temp_max".equals(namefield)) {
- currentWeatherData.getMain().setTemp_max(jParser.getDoubleValue());
- }
- if ("pressure".equals(namefield)) {
- currentWeatherData.getMain().setPressure(jParser.getDoubleValue());
- }
- if ("sea_level".equals(namefield)) {
- currentWeatherData.getMain().setSea_level(jParser.getDoubleValue());
- }
- if ("grnd_level".equals(namefield)) {
- currentWeatherData.getMain().setGrnd_level(jParser.getDoubleValue());
- }
- if ("humidity".equals(namefield)) {
- currentWeatherData.getMain().setHumidity(jParser.getDoubleValue());
- }
- }
- }
- if ("wind".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("speed".equals(namefield)) {
- currentWeatherData.getWind().setSpeed(jParser.getDoubleValue());
- }
- if ("deg".equals(namefield)) {
- currentWeatherData.getWind().setDeg(jParser.getDoubleValue());
- }
- }
- }
- if ("clouds".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("all".equals(namefield)) {
- currentWeatherData.getClouds().setAll(jParser.getDoubleValue());
- }
- }
- }
- if ("dt".equals(fieldname)) {
- currentWeatherData.setDt(jParser.getLongValue());
- }
- if ("rain".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("3h".equals(namefield)) {
- currentWeatherData.getRain().set3h(jParser.getDoubleValue());
- }
- }
- }
- if ("snow".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("3h".equals(namefield)) {
- currentWeatherData.getSnow().set3h(jParser.getDoubleValue());
- }
- }
- }
- if ("id".equals(fieldname)) {
- currentWeatherData.setId(jParser.getLongValue());
- }
- if ("name".equals(fieldname)) {
- currentWeatherData.setName(jParser.getText());
- }
- if ("cod".equals(fieldname)) {
- currentWeatherData.setCod(jParser.getIntValue());
- }
- }
-
- private void getForecastWeatherData(final Forecast forecastWeatherData,
- final JsonParser jParser) throws JsonParseException, IOException {
- if (jParser.nextToken() == JsonToken.START_OBJECT) {
-
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String fieldname = jParser.getCurrentName();
- final JsonToken nextToken = jParser.nextToken();
- if (nextToken == JsonToken.START_OBJECT) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
- }
- if (nextToken == JsonToken.START_ARRAY) {
- JsonToken tokenNext = jParser.nextToken();
- while (tokenNext != JsonToken.END_ARRAY) {
- if (tokenNext == JsonToken.START_OBJECT) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
- }
- tokenNext = jParser.nextToken();
- }
- }
- if ((nextToken == JsonToken.VALUE_NUMBER_INT)
- || (nextToken == JsonToken.VALUE_STRING)) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
- }
- }
- }
- }
-
- private void getForecastWeatherDataObjects(final Forecast forecastWeatherData,
- final JsonParser jParser, final String fieldname) throws JsonParseException,
- IOException {
-
- if ("cod".equals(fieldname)) {
- final String stringCod = jParser.getText();
- forecastWeatherData.setCod(Long.valueOf(stringCod));
- }
- if ("message".equals(fieldname)) {
- forecastWeatherData.setMessage(jParser.getDoubleValue());
- }
- if ("city".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- final JsonToken nextToken = jParser.nextToken(); // move to
- // value
- if ("id".equals(namefield)) {
- forecastWeatherData.getCity().setId(jParser.getLongValue());
- }
- if ("name".equals(namefield)) {
- forecastWeatherData.getCity().setName(jParser.getText());
- }
- if ("coord".equals(namefield)) {
- if (nextToken == JsonToken.START_OBJECT) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser, namefield);
- }
- }
- if ("country".equals(namefield)) {
- forecastWeatherData.getCity().setCountry(jParser.getText());
- }
- if ("population".equals(namefield)) {
- forecastWeatherData.getCity().setPopulation(jParser.getLongValue());
- }
- }
- }
- if ("cnt".equals(fieldname)) {
- forecastWeatherData.setCnt(jParser.getIntValue());
- }
- if ("coord".equals(fieldname)) {
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("lon".equals(namefield)) {
- forecastWeatherData.getCity().getCoord().setLon(jParser.getDoubleValue());
- }
- if ("lat".equals(namefield)) {
- forecastWeatherData.getCity().getCoord().setLat(jParser.getDoubleValue());
- }
- }
- }
- if ("list".equals(fieldname)) {
- final name.gumartinm.weather.information.model.forecastweather.List list = new name.gumartinm.weather.information.model.forecastweather.List();
- list.setTemp(new Temp());
- list.setWeather(new ArrayList<name.gumartinm.weather.information.model.forecastweather.Weather>());
- forecastWeatherData.getList().add(list);
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- final JsonToken nextToken = jParser.nextToken(); // move to
- // value
- if ("dt".equals(namefield)) {
- list.setDt(jParser.getLongValue());
- }
- if ("temp".equals(namefield)) {
- if (nextToken == JsonToken.START_OBJECT) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser, namefield);
- }
- }
- if ("pressure".equals(namefield)) {
- list.setPressure(jParser.getDoubleValue());
- }
- if ("humidity".equals(namefield)) {
- list.setHumidity(jParser.getDoubleValue());
- }
- if ("weather".equals(namefield)) {
- if (nextToken == JsonToken.START_ARRAY) {
- JsonToken tokenNext = jParser.nextToken();
- while (tokenNext != JsonToken.END_ARRAY) {
- if (tokenNext == JsonToken.START_OBJECT) {
- this.getForecastWeatherDataObjects(forecastWeatherData, jParser,
- namefield);
- }
- tokenNext = jParser.nextToken();
- }
- }
- }
- if ("speed".equals(namefield)) {
- list.setSpeed(jParser.getDoubleValue());
- }
- if ("deg".equals(namefield)) {
- list.setDeg(jParser.getDoubleValue());
- }
- if ("clouds".equals(namefield)) {
- list.setClouds(jParser.getDoubleValue());
- }
- if ("rain".equals(namefield)) {
- list.setRain(jParser.getDoubleValue());
- }
- }
- }
- if ("temp".equals(fieldname)) {
- final name.gumartinm.weather.information.model.forecastweather.List list = forecastWeatherData
- .getList().get(
- (forecastWeatherData.getList().size() - 1));
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
- if ("day".equals(namefield)) {
- list.getTemp().setDay(jParser.getDoubleValue());
- }
- if ("min".equals(namefield)) {
- list.getTemp().setMin(jParser.getDoubleValue());
- }
- if ("max".equals(namefield)) {
- list.getTemp().setMax(jParser.getDoubleValue());
- }
- if ("night".equals(namefield)) {
- list.getTemp().setNight(jParser.getDoubleValue());
- }
- if ("eve".equals(namefield)) {
- list.getTemp().setEve(jParser.getDoubleValue());
- }
- if ("morn".equals(namefield)) {
- list.getTemp().setMorn(jParser.getDoubleValue());
- }
- }
- }
- if ("weather".equals(fieldname)) {
- final name.gumartinm.weather.information.model.forecastweather.List list = forecastWeatherData
- .getList().get(
- (forecastWeatherData.getList().size() - 1));
- final name.gumartinm.weather.information.model.forecastweather.Weather weather = new name.gumartinm.weather.information.model.forecastweather.Weather();
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- final String namefield = jParser.getCurrentName();
- jParser.nextToken(); // move to value
-
- if ("id".equals(namefield)) {
- weather.setId(jParser.getIntValue());
- }
- if ("main".equals(namefield)) {
- weather.setMain(jParser.getText());
- }
- if ("description".equals(namefield)) {
- weather.setDescription(jParser.getText());
- }
- if ("icon".equals(namefield)) {
- weather.setIcon(jParser.getText());
- }
- }
- list.getWeather().add(weather);
- }
- }
-}
--- /dev/null
+package name.gumartinm.weather.information.service;
+
+import com.fasterxml.jackson.core.JsonParseException;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import name.gumartinm.weather.information.model.currentweather.Current;
+import name.gumartinm.weather.information.parser.JPOSCurrentParser;
+
+public class ServiceCurrentParser {
+ private final JPOSCurrentParser JPOSParser;
+
+ public ServiceCurrentParser(final JPOSCurrentParser jposParser) {
+ this.JPOSParser = jposParser;
+ }
+
+ public Current retrieveCurrentFromJPOS(final String jsonData)
+ throws JsonParseException, IOException {
+ return this.JPOSParser.retrieveCurrenFromJPOS(jsonData);
+ }
+
+ public String createURIAPICurrent(final String urlAPI, final String APIVersion,
+ final double latitude, final double longitude) {
+
+ final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
+ final Object[] values = new Object[3];
+ values[0] = APIVersion;
+ values[1] = latitude;
+ values[2] = longitude;
+
+ return formatURIAPI.format(values);
+ }
+}
--- /dev/null
+package name.gumartinm.weather.information.service;
+
+import com.fasterxml.jackson.core.JsonParseException;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import name.gumartinm.weather.information.model.forecastweather.Forecast;
+import name.gumartinm.weather.information.parser.JPOSForecastParser;
+
+public class ServiceForecastParser {
+ private final JPOSForecastParser JPOSParser;
+
+ public ServiceForecastParser(final JPOSForecastParser jposParser) {
+ this.JPOSParser = jposParser;
+ }
+
+ public Forecast retrieveForecastFromJPOS(final String jsonData)
+ throws JsonParseException, IOException {
+ return this.JPOSParser.retrieveForecastFromJPOS(jsonData);
+ }
+
+ public String createURIAPIForecast(final String urlAPI, final String APIVersion,
+ final double latitude, final double longitude, final String resultsNumber) {
+
+ final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
+ final Object[] values = new Object[4];
+ values[0] = APIVersion;
+ values[1] = latitude;
+ values[2] = longitude;
+ values[3] = resultsNumber;
+
+ return formatURIAPI.format(values);
+ }
+}
+++ /dev/null
-package name.gumartinm.weather.information.service;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.model.forecastweather.Forecast;
-import name.gumartinm.weather.information.parser.IJPOSParser;
-
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.Locale;
-
-
-public class ServiceParser {
- private final IJPOSParser JPOSParser;
-
- public ServiceParser(final IJPOSParser JPOSWeatherParser) {
- this.JPOSParser = JPOSWeatherParser;
- }
-
- public Current retrieveCurrentFromJPOS(final String jsonData)
- throws JsonParseException, IOException {
- return this.JPOSParser.retrieveCurrenFromJPOS(jsonData);
- }
-
- public Forecast retrieveForecastFromJPOS(final String jsonData)
- throws JsonParseException, IOException {
- return this.JPOSParser.retrieveForecastFromJPOS(jsonData);
- }
-
- public String createURIAPIForecast(final String urlAPI, final String APIVersion,
- final double latitude, final double longitude, final String resultsNumber) {
-
- final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
- final Object[] values = new Object[4];
- values[0] = APIVersion;
- values[1] = latitude;
- values[2] = longitude;
- values[3] = resultsNumber;
-
- return formatURIAPI.format(values);
- }
-
- public String createURIAPICurrent(final String urlAPI, final String APIVersion,
- final double latitude, final double longitude) {
-
- final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
- final Object[] values = new Object[3];
- values[0] = APIVersion;
- values[1] = latitude;
- values[2] = longitude;
-
- return formatURIAPI.format(values);
- }
-
- public String createURIAPIicon(final String icon, final String urlAPI) {
-
- final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
- final Object[] values = new Object[1];
- values[0] = icon;
-
- return formatURIAPI.format(values);
- }
-
-}
import name.gumartinm.weather.information.model.DatabaseQueries;
import name.gumartinm.weather.information.model.WeatherLocation;
import name.gumartinm.weather.information.model.currentweather.Current;
-import name.gumartinm.weather.information.parser.JPOSWeatherParser;
+import name.gumartinm.weather.information.parser.JPOSCurrentParser;
import name.gumartinm.weather.information.service.IconsList;
import name.gumartinm.weather.information.service.PermanentStorage;
-import name.gumartinm.weather.information.service.ServiceParser;
+import name.gumartinm.weather.information.service.ServiceCurrentParser;
import name.gumartinm.weather.information.widget.WidgetConfigure;
import org.apache.http.client.ClientProtocolException;
private Current getRemoteCurrent(final WeatherLocation weatherLocation) {
- final ServiceParser weatherService = new ServiceParser(new JPOSWeatherParser());
+ final ServiceCurrentParser weatherService = new ServiceCurrentParser(new JPOSCurrentParser());
final CustomHTTPClient HTTPClient = new CustomHTTPClient(
AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent"));
}
private Current getRemoteCurrentThrowable(final WeatherLocation weatherLocation,
- final CustomHTTPClient HTTPClient, final ServiceParser weatherService)
+ final CustomHTTPClient HTTPClient, final ServiceCurrentParser weatherService)
throws ClientProtocolException, MalformedURLException, URISyntaxException,
JsonParseException, IOException {
</pre>
<ul>
+ <li>Consts.java</li>
<li>ContentType.java</li>
</ul>
<a href="http://hc.apache.org/httpclient-3.x/license.html">http://hc.apache.org/httpclient-3.x/license.html</a>