package javaxt.rss;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
//******************************************************************************
//** RSS Feed
//******************************************************************************
/**
* Used to represent an RSS feed/channel. Returns a list of entries and other
* attributes associated with the feed.
*
******************************************************************************/
public class Feed {
private String title = "";
private String description = "";
private java.net.URL link = null;
private Location location = null;
private java.util.Date lastUpdate = null;
private Integer interval = null;
private java.util.ArrayList- items = new java.util.ArrayList
- ();
//**************************************************************************
//** Constructor
//**************************************************************************
public Feed(){}
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class using an XML node from an RSS XML
* document.
*/
protected Feed(org.w3c.dom.Node node, java.util.HashMap namespaces) {
//java.util.ArrayList
- items = new java.util.ArrayList
- ();
NodeList nodeList = node.getChildNodes();
for (int i=0; i\n");
str.append("\n");
str.append(" \n");
str.append(" " + getTitle() + "\n");
str.append(" " + getLink() + "\n");
str.append(" " + formatDate(lastUpdate==null ? new java.util.Date() : lastUpdate) + "\n");
str.append(" JavaXT RSS\n");
str.append(" " + (interval==null ? 15 : interval) + "\n");
for (Item item : items){
str.append(item.toXML());
}
str.append(" \n");
str.append("");
return createDocument(str.toString());
}
//**************************************************************************
//** createDocument
//**************************************************************************
private Document createDocument(String xml){
try{
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
return builder.parse(is);
}
catch(Exception e){
//e.printStackTrace();
return null;
}
}
//**************************************************************************
//** formatDate
//**************************************************************************
protected static String formatDate(java.util.Date date){
java.text.DateFormat formatter = new java.text.SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss zzz", java.util.Locale.US);
return formatter.format(date);
}
}