/** * Save extracted data to the XML database * * @param m Mensa which will be used */ public void saveToDatabase(Mensa m) { for (int i = 0; i < foodDayList.size(); i++) { // Save date if (foodDayList.get(i).getDate() != null) { xmlHandler.addDateToNode(m.getMensaName(), days[i], foodDayList.get(i).getDate()); } else { Log.v(TAG, "Warning in saveToDatabase() : null data"); } // Save ESSEN 1 DESC & PRICE if (foodDayList.get(i).getEssen1Desc() != null && foodDayList.get(i).getEssen1Price() != null) { xmlHandler.addDataToNode( m.getMensaName(), days[i], "ESSEN1", "DESC", foodDayList.get(i).getEssen1Desc(), "PRICE", foodDayList.get(i).getEssen1Price()); } else { Log.v(TAG, "Warning in saveToDatabase() : null data"); } // Save ESSEN 2 DESC & PRICE if (foodDayList.get(i).getEssen2Desc() != null && foodDayList.get(i).getEssen2Price() != null) { xmlHandler.addDataToNode( m.getMensaName(), days[i], "ESSEN2", "DESC", foodDayList.get(i).getEssen2Desc(), "PRICE", foodDayList.get(i).getEssen2Price()); } else { Log.v(TAG, "Warning in saveToDatabase() : null data"); } } // reinitialize foodDayList initFoodDayList(); }
public void updateDatabase() { // Check connection try { URL u = new URL("http://www.studentenwerk.bremen.de/"); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); huc.connect(); server_down = false; } catch (Exception e) { Log.v(TAG, "Warning in init(): Server down. Switching to test server..."); server_down = true; } // Initialize the mensaList if (server_down == false) { // mensaList.add(new Mensa("UNI_GW2", UNI_GW2, 0)); mensaList.add(new Mensa("UNI_BOULEVARD", UNI_BOULEVARD, 1)); mensaList.add(new Mensa("HSB_NEUSTADTSWALL", HSB_NEUSTADTSWALL, 2)); mensaList.add(new Mensa("HSB_WERDERSTR", HSB_WERDERSTR, 3)); mensaList.add(new Mensa("HSB_AIRPORT", HSB_AIRPORT, 4)); mensaList.add(new Mensa("BHV", BHV, 5)); } else { mensaList.add(new Mensa("UNI_BOULEVARD", UNI_BOULEVARD_cache, 1)); mensaList.add(new Mensa("HSB_NEUSTADTSWALL", HSB_NEUSTADTSWALL_cache, 2)); mensaList.add(new Mensa("HSB_WERDERSTR", HSB_WERDERSTR_cache, 3)); mensaList.add(new Mensa("HSB_AIRPORT", HSB_AIRPORT_cache, 4)); mensaList.add(new Mensa("BHV", BHV_cache, 5)); } initFoodDayList(); // Create XML database with the XML template xmlHandler = new XMLHandler(mensaList); for (Mensa mensa : mensaList) { parsingHTML(mensa.getURL()); saveToDatabase(mensa); } // Save XML database to file // writeDatabaseToInternalStorage(); writeDatabaseToExternalStorage(); }