using System;
using System.Xml;
using System.Collections;

/*
 * FeedExpress
 * (C) Copyright 2003 Jeppe Cramon
 * 
 * This software is provided "as is" without warranty of any kind,
 * either expressed or implied. The entire risk as to the
 * quality and performance of the software is with you. Should the
 * software prove defective, you assume the cost of all necessary
 * servicing, repair, or correction. In no event shall the author,
 * copyright holder, or any other party who may redistribute the
 * software be liable to you for damages, including any general,
 * special, incidental, or consequential damages arising out of
 * the use or inability to use the software (including, but not
 * limited to, loss of data, data being rendered inaccurate, loss of
 * business profits, loss of business information, business
 * interruptions, loss sustained by you or third parties, or a
 * failure of the software to operate with any other software) even
 * if the author, copyright holder, or other party has been advised
 * of the possibility of such damages. 
 */

namespace FeedExpress
{
	/// <summary>
	/// Rss091Reader
	/// </summary>
	public class Rss091Reader : IRssReader
	{
		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
		public Rss091Reader() {
		}

		public bool canRead(XmlDocument document) {
			XmlNode versionAttr = document.DocumentElement.Attributes.GetNamedItem("version");
			if (versionAttr != null && versionAttr.InnerText == "0.91") {
				return true;
			} else {
				return false;
			}
		}

		public IDictionary readFeeds(XmlDocument document) {
			XmlNodeList itemList = document.SelectNodes("//rss/channel/item");
			IDictionary returnValue = new Hashtable(itemList.Count);
			foreach (XmlNode item in itemList) {
				FeedEntry entry = new FeedEntry();
				entry.title = XmlUtils.getNodeText(item, "title");
				entry.description = XmlUtils.getNodeText(item, "description");
				entry.link = XmlUtils.getNodeText(item, "link");
				entry.publicationDate = DateTime.Now;
				entry.subject = "";
				// Since the format doesn't contain a guid, create one using the link
				entry.rssGuid = new FeedEntry.RssGuid(entry.link, true);
				returnValue.Add(entry.link, entry);
			}
			return returnValue;
		}

		public ChannelInformation readInformation(XmlDocument document) {
			ChannelInformation chInfo = new ChannelInformation();
			XmlElement root = document.DocumentElement;
			
			chInfo.title = XmlUtils.getNodeText(root, "//title");
			chInfo.link = XmlUtils.getNodeText(root, "//link");
			chInfo.description = XmlUtils.getNodeText(root, "//description");
			chInfo.language = XmlUtils.getNodeText(root, "//language");
			chInfo.creator = "";
			chInfo.rights = "";
			chInfo.date = XmlUtils.getNodeDateTime(root, "//lastBuildDate");
			
			chInfo.generatorAgent = "";
			chInfo.errorReportsTo = "";
			
			chInfo.updatePeriod = ChannelInformation.UpdatePeriodEnum.Hour;
			chInfo.updateFrequency = 1;
			chInfo.updateBase = DateTime.Now;
			chInfo.cssStyle = HTMLUtils.readChannelHTMLCSS(chInfo.link);

			return chInfo;
		}
	}
}
Close Window