String mensaShortName = req.getParameter("mensa");
msg = "mensaShortName: " + mensaShortName;
logger.info(msg);
respBuilder.append(msg);
Mensa mensa = Mensa.getById(mensaShortName);
//URL url = new URL("http://www.peacei.de/foodsupplier/uniessen.txt");
URL url = new URL(mensa.getUrl());
try {
String agent = "Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16,gzip(gfe)";
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", agent);
connection.addRequestProperty("Cache-Control", "no-cache,max-age=0");
connection.setReadTimeout(10000);
connection.setConnectTimeout(10000);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "ISO-8859-1"));
String line;
StringBuilder builder = new StringBuilder();
while ((line = reader.readLine()) != null) {
builder.append(line);
}
reader.close();
content = builder.toString();
//content = new String(content.getBytes("ISO-8859-1"), "UTF-8");
} catch (Exception e) {
//Queue queue = QueueFactory.getDefaultQueue();
//queue.deleteTask(mensaShortName);
respBuilder.append("<br><br>Exception: "+e.getMessage());
Version.writeHTML(resp, respBuilder.toString());
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
// content = new String(content.getBytes("ISO-8859-1"), "UTF-8");
//logger.info(content);
if (content != null && !content.isEmpty()) {
try {
Date now = new Date();
int week = CalendarUtil.getWeek(now);
int year = CalendarUtil.getYear(now);
Weekplan weekplan = mensaParserService.readCurrentWeekplanForMensaWeekAndYear(mensa, week, year, content);
weekplan.setYear(year);
mensaDAO.deleteWeekplansByMensaWeekAndYear(mensa, week, year);
weekplanCache.removeFromCache(Finals.FORMAT_JSON, mensa.getId(), week, year);
weekplanCache.removeFromCache(Finals.FORMAT_XML, mensa.getId(), week, year);
mensaDAO.saveWeekplan(weekplan);
logger.info("data parsed and written");
respBuilder.append("<br>data parsed");