private void collectBookMark(IPersonalBookMark pPBookMark) {
String lInfo = "";
// CB TODO mLog.info("collectInfo(), instruction: " +
// pPBookMark.getInstruction());
IFeed lFeed = pPBookMark.getFeedLinkReference().resolve();
// CB TODO if (pPBookMark.getInstruction().isCollect()) {
int newEnclosures = 0;
try {
// Perform an HTTP HEAD INFO to determine the last modified
// date against the modified date.
URL url = lFeed.getLink().toURL();
if (url != null) {
HTTPHEADInfo hi = null;
// Perform some checks to decide if the feed should
// be recollected.
// Check the modified date against the currently stored
// modified date.
//
boolean lCollect = true;
// Check for the protocol first.
String protocol = url.getProtocol();
if (protocol.equals("http")) {
try {
hi = org.rssowl.contrib.podcast.core.net.NetTask
.getHeadInfo(lFeed, url);
} catch (NetworkException e) {
lCollect = false;
}
} else {
// The HEAD information is irrelevant for non-HTTP
// protocol.
// CB TODO LOG mLog.info("Protocol not supported" + protocol);
return;
}
// We do NOT collect if the the modified date hasn't
// changed.
if (pPBookMark.getHeaderInfo() != null
&& pPBookMark.getHeaderInfo().getModifiedString() != null
&& pPBookMark.getHeaderInfo().getModifiedString()
.equals(hi.getModifiedString())) {
lCollect = false;
}
// collect, if the file is not present.
// CB TODO We don't have file support in the current model.
// if (pFeed.getFile() == null
// || !pFeed.getFile().exists()) {
// collect = true;
// } else {
// }
if (!lCollect) {
// This pFeed has not changed. The RSS file will not
// be collected again. We do parse it to set the
// model.
// CB TODO
// newEnclosures = pFeed.updateEnclosures(pFeed
// .getFile());
// CB TODO LOG mLog.info("The feed " + pPBookMark
// + " is up to date (Will not parse it)");
// CB TODO migrate instruction
// pPBookMark.getInstruction().setCollectEnclosure(false);
pPBookMark.setQuality(IPersonalBookMark.GOOD_QUALITY);
pPBookMark.setQualityDescription("");
// pFeed.getInstruction().setMark(false);
// mLog.info("The bookmark " + pPBookMark
// + " has been marked (Will not Mark)");
// Rewrite the instruction if was previously
// inspected.
// CB TODO INSTRUCTION MIG.
// BookMarkHistory.BookMarkHistoryEvent event = pPBookMark
// .getHistory().getLatestEvent();
// if (event != null) {
// Object eventObject = event.getEventObject();
// if (eventObject instanceof IInstruction) {
// if (((IInstruction) eventObject).isInspect()) {
//
// }
// CB FIXME, there is a bug, inspection
// is overriden.
// pFeed.getInstruction()
// .setInspect(false);
// mLog
// .info("The feed "
// + pPBookMark
// + " has been inspected (Will not Inspect)");
// }
// }
lInfo = (lFeed.getTitle().length() > 35 ? lFeed.getTitle()
.substring(0, 35)
+ "..." : lFeed.getTitle())
+ " " + Messages.getString("tasks.upToDate");
// CB TODO INSTRUCTION MIGRATE.
// mNotifier
// .notifyInstructionSucceeded(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_COLLECT,
// lFeed, (InstructionException) null));
} else {
// Here It's a totaly new or modified Feed.
// The Feed is parsed. If it's not totally new, we
// copy the enclosure settings from the previous
// settings.
// CB TODO LOG mLog.info(pPBookMark + " is modified, parse it");
Reader stream = NetTask.getReader(lFeed, url, pPBookMark
.getHeaderInfo());
// Save the stream in a temporary file first.
File lFile = DownloadUtil.saveTempFeedFile(stream);
// CB TODO, this a merge activity for the model.
// newEnclosures = pFeed.updateEnclosures(lFile);
pPBookMark.setHeaderInfo(hi);
pPBookMark.setQuality(IPersonalBookMark.GOOD_QUALITY);
pPBookMark.setQualityDescription(Messages
.getString("feed.quality.good"));
lInfo = (lFeed.getTitle().length() > 35 ? lFeed.getTitle()
.substring(0, 35)
+ "..." : lFeed.getTitle())
+ " "
+ newEnclosures
+ " "
+ (newEnclosures == 1 ? Messages
.getString("tasks.newEnclosure") : Messages
.getString("tasks.newEnclosures"));
// CB TODO INSTRUCTION MIGRATE.
// mNotifier
// .notifyInstructionSucceeded(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_COLLECT,
// lFeed, (InstructionException) null));
}
} else { // The URL off the pFeed is unknown.
// CB TODO INSTRUCTION MIGRATE.
// mNotifier.notifyInstructionFailed(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_COLLECT, lFeed,
// new InstructionException("Empty URL")));
}
// CB TODO INSTRUCTION MIGRATE.
// mNotifier
// .notifyInstuctionInfo(new InstructionEvent(pPBookMark
// .getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_COLLECT,
// pPBookMark, lInfo));
} catch (Exception ie) {
// Something wrong in either accessing the pFeed URL or
// parsing
// the XML RSS 2.0 pFeed.
// The pFeed quality is set to bad, but it could be that no
// networks exists at all. (Need to include check on
// network.
// mLog.error("Error collecting feed " + pFeed);
pPBookMark.setQuality(IPersonalBookMark.BAD_QUALITY);
pPBookMark.setQualityDescription(ie.getMessage());
// CB TODO INSTRUCTION MIGRATE.
// mNotifier.notifyInstructionFailed(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_COLLECT, pPBookMark, ie));
} finally {
// We now set the folder after regardless.
// If no network or bad feed we would set it.
// CB TODO, Token handling migration later on.
String lDefaultFolder = DownloadUtil.getPodcastFolder()
+ File.separator + "unknown";
// String lDefaultFolder = DownloadUtil.getPodcastFolder()
// + File.separator + TokenHandler.RSS_ITEM_TITLE;
if (pPBookMark.getLocalFolder().length() == 0
|| pPBookMark.getLocalFolder().equals(lDefaultFolder)) {
pPBookMark.setLocalFolder(DownloadUtil.getBookMarkFolder(lFeed
.getTitle()));
}
}
// }