package javaxt.rss;
import org.w3c.dom.*;
//******************************************************************************
//** RSS Parser
//******************************************************************************
/**
* Used to parse an RSS document and create a list of feeds/channels.
*
******************************************************************************/
public class Parser {
private Feed[] feeds = null;
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of the RSS Parser */
public Parser(org.w3c.dom.Document doc) {
Node node = getOuterNode(doc);
String nodeName = node.getNodeName();
//Get namespaces
java.util.HashMap namespaces = new java.util.HashMap();
NamedNodeMap attributes = node.getAttributes();
for (int i=0; i feeds = new java.util.ArrayList();
if (nodeName.equals("rss")){
NodeList Channels = doc.getElementsByTagName("channel");
for (int i=0; i
//**************************************************************************
//** getOuterNode
//**************************************************************************
/** Returns the outer node for a given xml document.
* @param xml A org.w3c.dom.Document
*/
protected static Node getOuterNode(Document xml){
if (xml==null) return null;
NodeList OuterNodes = xml.getChildNodes();
for (int i=0; i");
if (hasChildren(tree)) {
NodeList xmlNodeList = tree.getChildNodes();
for (int i=0; i");
}
}
//**************************************************************************
//** getAttributes
//**************************************************************************
/** Used to retrieve all of the attributes for a given node. */
protected static String getAttributes(Node node){
if (node==null) return "";
NamedNodeMap attr = node.getAttributes();
String Attributes = "";
if (attr!=null){
for (int j=0; j=format.length()){
int len = format.length()-1;
String tz = date.substring(len);
if (tz.length()==6){
String a = tz.substring(0,1);
if ((a.equals("-") || a.equals("+")) && tz.indexOf(":")==3){
tz = tz.replace(":", "");
date = date.substring(0, len) + tz;
}
}
}
}
}
try{
return parseDate(date, format);
}
catch(java.text.ParseException ex){
}
}
}
//If we're still here, throw an exception
throw new java.text.ParseException("Failed to parse date: " + date, 0);
}
//**************************************************************************
//** ParseDate
//**************************************************************************
/** Attempts to convert a String to a Date via the user-supplied Format */
private static java.util.Date parseDate(String date, String format)
throws java.text.ParseException {
if (date!=null){
date = date.trim();
if (date.length()==0) date = null;
}
if (date==null) throw new java.text.ParseException("Date is null.", 0);
java.text.SimpleDateFormat formatter =
new java.text.SimpleDateFormat(format);
return formatter.parse(date);
}
//
}