aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/DataManager.java
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-01-30 14:51:29 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-01-30 14:51:29 +0000
commit7d6d2399e3e750a215f191c2f0d77319e3eb46f2 (patch)
treebe5928dc8d36cacfb96592ab6c4ecef041e84368 /src/net/cbaines/suma/DataManager.java
parente78d1fa40d32a97018e2831fd0592d6b6c1b3d7e (diff)
downloadsouthamptonuniversitymap-7d6d2399e3e750a215f191c2f0d77319e3eb46f2.tar
southamptonuniversitymap-7d6d2399e3e750a215f191c2f0d77319e3eb46f2.tar.gz
More data for users regarding errors when fetching timetables.
Diffstat (limited to 'src/net/cbaines/suma/DataManager.java')
-rw-r--r--src/net/cbaines/suma/DataManager.java81
1 files changed, 37 insertions, 44 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index bc82b59..9fd08c1 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -37,6 +37,7 @@ import javax.xml.parsers.SAXParserFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -545,7 +546,8 @@ public class DataManager {
}
- public static Timetable getTimetable(Context context, String busStop, boolean onlyUniLink) throws SQLException {
+ public static Timetable getTimetable(Context context, String busStop, boolean onlyUniLink) throws SQLException, ClientProtocolException, IOException,
+ JSONException {
if (helper == null)
helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
@@ -558,42 +560,36 @@ public class DataManager {
String file = getFileFromServer(busStopUrl + busStop + ".json");
- try {
- JSONObject data = new JSONObject(file);
+ JSONObject data = new JSONObject(file);
- JSONArray stopsArray = data.getJSONArray("stops");
+ JSONArray stopsArray = data.getJSONArray("stops");
- Log.i(TAG, "Number of entries " + data.length());
+ Log.i(TAG, "Number of entries " + data.length());
- Log.i(TAG, "Stops: " + data.getJSONArray("stops"));
+ Log.i(TAG, "Stops: " + data.getJSONArray("stops"));
- for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
- JSONObject stopObj = stopsArray.getJSONObject(stopNum);
+ for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
+ JSONObject stopObj = stopsArray.getJSONObject(stopNum);
- if (onlyUniLink && !stopObj.getString("name").startsWith("U")) {
- continue;
- }
+ if (onlyUniLink && !stopObj.getString("name").startsWith("U")) {
+ continue;
+ }
- BusStop busStopObj = busStopDao.queryForId(busStop);
- if (busStopObj == null) {
- Log.e(TAG, "BusStopObj == null");
- }
+ BusStop busStopObj = busStopDao.queryForId(busStop);
+ if (busStopObj == null) {
+ Log.e(TAG, "BusStopObj == null");
+ }
- Stop stop = getStop(context, stopObj, busStopObj);
+ Stop stop = getStop(context, stopObj, busStopObj);
- if (stop == null) {
- Log.w(TAG, "Null stop, skiping");
- continue;
- }
+ if (stop == null) {
+ Log.w(TAG, "Null stop, skiping");
+ continue;
+ }
- Log.i(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + stop.arivalTime);
+ Log.i(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + stop.arivalTime);
- timetable.add(stop);
- }
- } catch (JSONException ex) {
- Log.e(TAG, "", ex);
- Log.e(TAG, "File: " + file);
- return null;
+ timetable.add(stop);
}
timetable.fetchTime = new Date(System.currentTimeMillis());
@@ -628,28 +624,25 @@ public class DataManager {
return data;
}
- public static String getFileFromServer(String request) {
+ public static String getFileFromServer(String request) throws ClientProtocolException, IOException {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(request);
Log.i("Util.getFileFromServer", "Request used: " + request);
- try {
- HttpResponse response = client.execute(httpGet);
- StatusLine statusLine = response.getStatusLine();
- int statusCode = statusLine.getStatusCode();
- if (statusCode == 200) {
- HttpEntity entity = response.getEntity();
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- String line;
- while ((line = reader.readLine()) != null) {
- builder.append(line);
- }
- } else {
- Log.e("", "Failed to download file");
+
+ HttpResponse response = client.execute(httpGet);
+ StatusLine statusLine = response.getStatusLine();
+ int statusCode = statusLine.getStatusCode();
+ if (statusCode == 200) {
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line);
}
- } catch (Exception ex) {
- Log.e("Util.getFileFromServer", ex.getClass().toString() + " " + ex.getMessage());
+ } else {
+ Log.e("", "Failed to download file");
}
return builder.toString();