﻿/**
 * RSS解析类
 * RSS解析类
 *
 * @param node:		[IN]/CVFDLNode节点
 * @param nameSpace:[IN]/起始名字空间
 * @return true/false
 *
 * @author 2006-07-21	yangzh
*/
function CRSSNode(node, nameSpace)
{
	// 定义公共成员
	/** 名字空间 */
	if (nameSpace == null)
		nameSpace = "RSSNode";
	this.NameSpace = nameSpace;

	/** 解析类类型 */
	this.GetClass	= function() {return CRSSNode;}
	
	/** 别名 */
	this.GetTitle		= function() {return node.GetNodeText("title");}
	/** 类型 */
	this.GetType		= function() {return node.XmlNode.tagName;}
	/** 摘要 */
	this.GetDescription	= function() {return node.GetNodeText("description");}
	/** 创建时间 */
	this.GetPubDate		= function() {return node.GetNodeText("pubDate");}
	/** 关联文件位置 */
	this.GetLink		= function() {return node.GetNodeText("link");}
	/** 作者 */
	this.GetAuthor		= function() {return node.GetNodeText("author");}
	/**分类信息*/
	this.GetCategory			= function() {return node.GetNodeText("category");}
	/** 评论信息 */
	this.GetComments			=	function()	{return node.GetNodeText("comments");}
}

/**
 * VFDL文档类
 * VFDL文档类
 *
 * @param xmlDoc: [IN]/Dom文档
 *
 * @author	2006-02-20	yangzhang
*/
function CRSSDoc(xmlDoc)
{
	this.Base = CVFDLDoc;
	this.Base(xmlDoc);
	
	// 定义公共成员
	/** Dom文档 */
	this.XmlDoc = xmlDoc;

	/** xml版本 */
	this.GetXmlVersion		= function() {return this.XmlDoc.firstChild.attributes("version").nodeValue;}
	/** 文档编码 */
	this.GetXmlEncoding		= function() {return this.XmlDoc.firstChild.attributes("encoding").nodeValue;}
	/** 文档版本 */
	this.GetDocVersion		= function() {return CXUtility.GetXmlNodeText(this.XmlDoc, "rss/@version");}
	/** 文档名称 */
	this.GetDocName			= function() {return this.XmlDoc.selectSingleNode("rss").nodeName;}
	/** 文档标题 */
	this.GetDocTitle		= function() {return CXUtility.GetXmlNodeText(this.GetRootNode(), "title");}
	/** 文档图片 */
	this.GetDocImage		= function() {return CXUtility.GetXmlNodeText(this.GetRootNode(), "image");}
	/** 文档摘要 */
	this.GetDocDescription	= function() {return CXUtility.GetXmlNodeText(this.GetRootNode(), "description");}
	/** 文档语言 */
	this.GetDocLanguage		= function() {return CXUtility.GetXmlNodeText(this.GetRootNode(), "language");}
	/** 文档链接 */
	this.GetDocLink			= function() {return CXUtility.GetXmlNodeText(this.GetRootNode(), "link");}
	/** 文档Docs */
	this.GetDocDocs			=	function()	{return CXUtility.GetXmlNodeText(this.GetRootNode(),"docs");}
	/** 文档生成者 */
	this.GetDocGenerator			=	function()	{return CXUtility.GetXmlNodeText(this.GetRootNode(),"generator");}
	/**
	 * 读取根节点
	 * 读取根节点
	 *
	 * @param null
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/	
	this.GetRootNode = function()
	{
		return this.XmlDoc.selectSingleNode("/*/channel");
	}

	/**
	 * 读取指定节点的父节点
	 * 读取指定节点的父节点
	 *
	 * @param node:	[IN]/xmlNode
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/		
	this.GetParentNode = function(node)
	{
		if (node.parentNode == null || node.parentNode.tagName == "channel" || node.parentNode.tagName == "item")
			return node.parentNode;
			
		return GetParentNode(node.parentNode);
	}
	
	/**
	 * 读取指定节点的第一个子节点
	 * 读取指定节点的第一个子节点
	 *
	 * @param node:	[IN]/xmlNode
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/	
	this.GetFirstChild = function(node)
	{
		return node.selectSingleNode("channel|item");
	}
	
	/**
	 * 读取指定节点的最后一个子节点
	 * 读取指定节点的最后一个子节点
	 *
	 * @param node:	[IN]/xmlNode
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/	
	this.GetLastChild = function(node)
	{
		var nodeList = node.selectNodes("channel|item");
		if (nodeList.length > 0)
			return nodeList[nodeList.length-1];
			
		return null;
	}
	
	/**
	 * 读取指定节点的子节点数量
	 * 读取指定节点的子节点数量
	 *
	 * @param node:	[IN]/xmlNode
	 * @return number
	 *
	 * @author 2006-07-21	yangzh
	*/		
	this.GetChildNum = function(node)
	{
		return node.selectNodes("channel|item").length;
	}
	
	/**
	 * 读取指定节点的前一个节点
	 * 读取指定节点的前一个节点
	 *
	 * @param node:	[IN]/xmlNode
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/
	this.GetPrevNode = function(node)
	{
		if (node.previousSibling == null || node.previousSibling.tagName == "channel" || node.previousSibling.tagName == "item")
			return node.previousSibling;
			
		return 	GetPrevNode(node.previousSibling);
	}

	/**
	 * 读取指定节点的后一个节点
	 * 读取指定节点的后一个节点
	 *
	 * @param node:	[IN]/xmlNode
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/	
	this.GetNextNode = function(node)
	{
		if (node.nextSibling == null || node.nextSibling.tagName == "channel" || node.nextSibling.tagName == "item")
			return node.nextSibling;
			
		return 	GetNextNode(node.nextSibling);
	}
	
	/**
	 * 根据名称读取节点
	 * 根据名称读取节点
	 *
	 * @param parentNode:	[IN]/父节点xmlNode
	 * @param alias:		[IN]/别名
	 * @return XmlNode
	 *
	 * @author 2006-07-21	yangzh
	*/		
	this.GetNode = function(parentNode, alias)
	{
		return parentNode.selectSingleNode('channel[title="'+alias+'"]|item[title="'+alias+'"]');
	}
	
	/**
	 * 浏览节点
	 * 浏览节点
	 *
	 * @param node:		[IN]/父节点XmlNode
	 * @return XmlNodeList
	 *
	 * @author 2006-07-21	yangzh
	*/		
	this.BrowseNode = function(node)
	{
		return node.selectNodes("//channel|//item");
	}
}

// 添加解析类
CXConfig.Modules.RSS.Class=CRSSNode;