"modified", "author", "generator",
"copyright", "link", "entry"
});
// title element
ChannelIF chnl = cBuilder.createChannel(channel,
channel.getChildTextTrim("title",
defNS));
// TODO: support attributes: type, mode
chnl.setFormat(ChannelFormat.ATOM_0_3);
// language
String language = channel.getAttributeValue("lang", Namespace.XML_NAMESPACE);
if (language != null) {
chnl.setLanguage(language);
}
// description element
if (channel.getChild("description") != null) {
chnl.setDescription(channel.getChildTextTrim("description", defNS));
} else {
// fallback
chnl.setDescription(channel.getChildTextTrim("tagline", defNS));
}
// ttl in dc namespace
Element ttl = channel.getChild("ttl", dcNS);
if (ttl != null) {
String ttlString = ttl.getTextTrim();
if (ttlString != null) {
chnl.setTtl(Integer.parseInt(ttlString));
}
}
// lastbuild element : modified ?
Element modified = channel.getChild("modified", defNS);
if (modified != null) {
chnl.setPubDate(ParserUtils.getDate(modified.getTextTrim()));
}
// TODO : issued value
/*
if (modified != null) {
modified = channel.getChild("issued", defNS);
chnl.setLastBuildDate (ParserUtils.getDate(modified.getTextTrim()));
}
*/
// author element
Element author = channel.getChild("author", defNS);
if (author != null) {
ParserUtils.matchCaseOfChildren(author, "name");
chnl.setCreator(author.getChildTextTrim("name", defNS));
}
// generator element
Element generator = channel.getChild("generator", defNS);
if (generator != null) {
chnl.setGenerator(generator.getTextTrim());
}
// copyright element
Element copyright = channel.getChild("copyright", defNS);
if (copyright != null) {
chnl.setCopyright(getCopyright(copyright));
}
// n link elements
// TODO : type attribut of link (text, application...)
List links = channel.getChildren("link", defNS);
Iterator i = links.iterator();
while (i.hasNext()) {
Element linkElement = (Element) i.next();
// use first 'alternate' link
String rel = linkElement.getAttributeValue("rel");
String href = linkElement.getAttributeValue("href");
if ((rel != null) && (href != null) && rel.equals("alternate")) {
URL linkURL = ParserUtils.getURL(href);
chnl.setSite(linkURL);
break;
}
// TODO: further extraction of link information
}
// 1..n entry elements
List items = channel.getChildren("entry", defNS);
i = items.iterator();
while (i.hasNext()) {
Element item = (Element) i.next();
// Lower the case of these tags to simulate case-insensitive parsing
ParserUtils.matchCaseOfChildren(item,
new String[] {
"title", "link", "content", "summary",
"issued", "subject"
});
// get title element
// TODO : deal with type attribut
Element elTitle = item.getChild("title", defNS);
String strTitle = "<No Title>";
if (elTitle != null) {
strTitle = getTitle(elTitle);
LOGGER.debug("Parsing title " + elTitle.getTextTrim() + "->" +
strTitle);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Entry element found (" + strTitle + ").");
}
// get link element
String strLink = AtomParserUtils.getItemLink(item, defNS);
// get description element
String strDesc = getDescription(item, defNS);
// generate new news item (link to article)
ItemIF curItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
ParserUtils.getURL(strLink));
curItem.setFound(dateParsed);
// get issued element (required)
Element elIssued = item.getChild("issued", defNS);
if (elIssued == null) {
// [adewale@gmail.com, 01-May-2005] Fix for blogs which have
// 'created' dates, but not 'issued' dates -- in clear contravention
// of the Atom 0.3 spec.
Element elCreated = item.getChild("created", defNS);
if (elCreated != null) {
curItem.setDate(ParserUtils.getDate(elCreated.getTextTrim()));
}
} else {
curItem.setDate(ParserUtils.getDate(elIssued.getTextTrim()));
}
// get subject element
Element elSubject = item.getChild("subject", dcNS);
if (elSubject != null) {
// TODO: Mulitple subject elements not handled currently
curItem.setSubject(elSubject.getTextTrim());
}
}
// set to current date
chnl.setLastUpdated(dateParsed);
return chnl;
}