// RSS 1.0 Administration Module support
// 0..1 generator element
Element elGenerator = channel.getChild("generatorAgent", adminNS);
if (elGenerator != null) {
Attribute generator = elGenerator.getAttribute("resource", ParserUtils
.getNamespace(elGenerator, "rdf"));
if (generator != null) {
chnl.setGenerator(generator.getValue());
}
}
// RSS 1.0 Syndication Module support
// 0..1 update period element
Element updatePeriod = channel.getChild("updatePeriod", syNS);
if (updatePeriod != null) {
try {
ChannelUpdatePeriod channelUpdatePeriod = ChannelUpdatePeriod
.valueFromText(updatePeriod.getTextTrim());
chnl.setUpdatePeriod(channelUpdatePeriod);
} catch (IllegalArgumentException ex) {
logger.warn(updatePeriod.getTextTrim(), ex);
}
}
// 0..1 update frequency element
Element updateFrequency = channel.getChild("updateFrequency", syNS);
if (updateFrequency != null) {
chnl.setUpdateFrequency((new Integer(updateFrequency.getTextTrim()))
.intValue());
}
// 0..1 update base element
Element updateBase = channel.getChild("updateBase", syNS);
if (updateBase != null) {
chnl.setUpdateBase(ParserUtils.getDate(updateBase.getTextTrim()));
}
if ((updatePeriod != null) && updateFrequency != null) {
int ttl = getTTL(chnl.getUpdatePeriod(), chnl.getUpdateFrequency());
chnl.setTtl(ttl);
}
// item elements
List items = root.getChildren("item", defNS);
Iterator i = items.iterator();
while (i.hasNext()) {
Element item = (Element) i.next();
ParserUtils.matchCaseOfChildren(item, new String[] { "title", "link",
"encoded", "description", "creator", "subject", "date", "sourceURL",
"source", "timestamp", "reference" });
// get title element
Element elTitle = item.getChild("title", defNS);
String strTitle = "<No Title>";
if (elTitle != null) {
strTitle = elTitle.getTextTrim();
}
if (logger.isDebugEnabled()) {
logger.debug("Item element found (" + strTitle + ").");
}
// get link element
Element elLink = item.getChild("link", defNS);
String strLink = "";
if (elLink != null) {
strLink = elLink.getTextTrim();
}
// get description element
Element elDesc = item.getChild("encoded", contentNS);
if (elDesc == null) {
elDesc = item.getChild("description", defNS);
}
if (elDesc == null) {
elDesc = item.getChild("description", dcNS);
}
String strDesc = "";
if (elDesc != null) {
strDesc = elDesc.getTextTrim();
}
// generate new RSS item (link to article)
ItemIF rssItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
ParserUtils.getURL(strLink));
rssItem.setFound(dateParsed);
// get creator element
Element elCreator = item.getChild("creator", dcNS);
if (elCreator != null) {
rssItem.setCreator(elCreator.getTextTrim());
}
// get subject element
Element elSubject = item.getChild("subject", dcNS);
if (elSubject != null) {
// TODO: Mulitple subject elements not handled currently
rssItem.setSubject(elSubject.getTextTrim());
}
// get date element
Element elDate = item.getChild("date", dcNS);
if (elDate != null) {
rssItem.setDate(ParserUtils.getDate(elDate.getTextTrim()));
}
// get source element - default to Aggregation module, then try Dublin Core
String sourceName = null;
String sourceLocation = null;
Date sourceTimestamp = null;
Element elSourceURL = item.getChild("sourceURL", agNS);
if (elSourceURL == null) { // No Aggregation module - try Dublin Core
elSourceURL = item.getChild("source", dcNS);
if (elSourceURL != null) {
sourceLocation = elSourceURL.getTextTrim();
sourceName = "Source";
}
} else { // Aggregation module
sourceLocation = elSourceURL.getTextTrim();
Element elSourceName = item.getChild("source", agNS);
if (elSourceName != null) {
sourceName = elSourceName.getTextTrim();
}
Element elSourceTimestamp = item.getChild("timestamp", agNS);
if (elSourceTimestamp != null) {
sourceTimestamp = ParserUtils
.getDate(elSourceTimestamp.getTextTrim());
}
}
if (sourceLocation != null) {
ItemSourceIF itemSource = cBuilder.createItemSource(rssItem,
sourceName, sourceLocation, sourceTimestamp);
rssItem.setSource(itemSource);
}
// comments element - use Annotation module
Element elReference = item.getChild("reference", annotateNS);
if (elReference != null) {
Attribute resource = elReference.getAttribute("resource", ParserUtils
.getNamespace(elReference, "rdf"));
if (resource != null) {
URL resourceURL = ParserUtils.getURL(resource.getValue());
if (resourceURL != null) {
rssItem.setComments(resourceURL);
}
}
}