}
}
PersistenceManager pm = PMF.get().getPersistenceManager();
MarketXML m = null;
Key k = KeyFactory.createKey(MarketXML.class.getSimpleName(), url);
try {
// Check if the file is fetched already
resp.getWriter().println("Checking if URL is fetched: " + url);
m = pm.getObjectById(MarketXML.class, k);
resp.getWriter().println("It is fetched...");
resp.getWriter().println("----------------------------------------------------");
resp.getWriter().println("Current timestamp:" + DateFormat.getDateTimeInstance().format(m.getTimestamp()));
resp.getWriter().println("Last retrieved:" + DateFormat.getDateTimeInstance().format(m.getLastretrieved()));
resp.getWriter().println("----------------------------------------------------");
Long last = m.getLastretrieved();
// It is fetched. Refresh it.
resp.getWriter().print("Refreshing...");
resp.getWriter().flush();
m.refresh();
if (m.getLastretrieved() == last) {
resp.getWriter().println(
"Not enough time passed since last retrieval. Current limit is " + MarketXML.time_threshold_minutes
+ " minutes");
} else {
resp.getWriter().println("Got new copy");
}
resp.getWriter().println("----------------------------------------------------");
resp.getWriter().println("New timestamp:" + DateFormat.getDateTimeInstance().format(m.getTimestamp()));
resp.getWriter().println("New retrieval:" + DateFormat.getDateTimeInstance().format(m.getLastretrieved()));
resp.getWriter().println("----------------------------------------------------");
} catch (Exception e) {
// URL not fetched before
// Create object
resp.getWriter().println("It is not fetched...fetching");
resp.getWriter().flush();
m = new MarketXML(url);
System.out.println("Start fetching");
m.fetch();
resp.getWriter().println("New timestamp:" + DateFormat.getDateTimeInstance().format(m.getTimestamp()));
resp.getWriter().println("Storing...");
resp.getWriter().flush();
pm.makePersistent(m);
}
pm.close();
Document d = m.getXML();
Queue queue = QueueFactory.getDefaultQueue();
NodeList n = d.getElementsByTagName("EventClass");
for (int i = 0; i < n.getLength(); i++) {
Node nd = n.item(i);