⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uatomfeed.pas

📁 自己写的一个 RSS 阅读器
💻 PAS
字号:
unit uAtomFeed;

interface

uses Classes,uW3CDTF, FastStringFuncs,
	uRssBase, MSXML2_TLB, uConstants;

type

TAtomFeed = class(TInterfacedObject, IRSSBase)
private
  FDoc:IXMLDOMDocument2;
  FItems : IRSSItemBaseList;
  FTitle, FDescription : string;
  FVersion, FLink, FCreator : WideString;
protected
    function Get_Version : WideString;
    function Get_Title : string;
    function Get_Link: WideString;
    function Get_Description: string;
    function Get_Creator: WideString;
    function Get_Items: IRSSItemBaseList;
public
	constructor Create(theDoc : IXMLDOMDocument2);
  property Items:IRSSItemBaseList read fItems;
  property Version: WideString read Get_Version;
  property Title: string read Get_Title;
  property Link: Widestring read Get_Link;
  property Description: string read Get_Description;
  property Creator: WideString read Get_Creator;
end;

TAtomItems = class(TInterfacedObject, IRSSItemBaseList)
private
    fItems : TList;
    fNode:IXMLDOMNode;
protected
    procedure Add(item : TInterfacedObject);
    function Get_Item(Index: Integer): IRSSItemBase;
    function Get_Count(): integer;
public
	constructor Create(theNode:IXMLDOMNode);
end;

TAtomItem = class(TInterfacedObject, IRSSItemBase)
  private
    fNode:IXMLDOMNode;
    FAuthor: string;
    FTitle: string;
    FPubDate: TW3CDTF;
    FGuid: WideString;
    FLink: WideString;
    FDescription: string;
  protected
    function Get_Author: string;
    function Get_Title: string;
    function Get_PubDate: TW3CDTF;
    function Get_Guid: WideString;
    function Get_Link: WideString;
    function Get_Category: string;
    function Get_Creator: WideString;
    function Get_Description: string;
  public
		constructor Create(theNode : IXmlDOMNode);
  end;

  function GetAtomFeed(Doc: IXMLDomDocument2): IRSSBase;

implementation

uses SysUtils;

function GetAtomFeed(Doc: IXMLDOMDocument2): IRSSBase;
begin
  Result := TAtomFeed.Create(Doc) as IRSSBase;
end;

{ TAtomFeed }

constructor TAtomFeed.Create(theDoc: IXMLDOMDocument2);
var
	i : integer;
  channelNodes : IXMLDomNodeList;
  tmpNode, node : IXmlDomNode;
begin
  FDoc:=theDoc;
	node := FDoc.documentElement;
  fItems := TAtomItems.Create(node);
  channelNodes := node.selectNodes('entry');
  FVersion := ''; FTitle := ''; FLink := ''; FDescription := ''; FCreator := '';
  if assigned(node) then begin
  	FCreator := getNodeVal(node, 'generator');
    tmpNode := node.selectSingleNode('info');
    if Assigned(tmpNode) then FDescription := tmpNode.XML;
 		FTitle := ExtractNonHTML(getNodeVal(node, 'title'));
		FVersion := 'ATOM ' + getNodeVal(node, '@version');
    FLink := getNodeVal(node, 'link[@rel="alternate"]/@href');
  end;
  for i := 0 to channelNodes.length-1 do
    fitems.Add( TAtomItem.Create(channelNodes.item[i]) )
end;

function TAtomFeed.Get_Creator: WideString; begin Result := FCreator; end;
function TAtomFeed.Get_Description: string; begin Result := FDescription; end;
function TAtomFeed.Get_Items: IRSSItemBaseList; begin Result := fItems; end;
function TAtomFeed.Get_Link: WideString; begin Result := FLink; end;
function TAtomFeed.Get_Title: string; begin Result := FTitle; end;
function TAtomFeed.Get_Version: WideString; begin Result := FVersion; end;

{ TAtomItems }

constructor TAtomItems.Create(theNode:IXMLDOMNode);
begin
  fItems := TList.Create();
  fNode:=theNode;
end;
procedure TAtomItems.Add(item: TInterfacedObject); begin fItems.Add(item); end;
function TAtomItems.Get_Count: integer; begin Result := fItems.Count; end;
function TAtomItems.Get_Item(Index: Integer): IRSSItemBase; begin Result := TAtomItem(fItems.Items[index]); end;

{ TAtomItem }

constructor TAtomItem.Create(theNode: IXmlDOMNode);
var
	val : widestring;
  tmpNode : IXMLDomNode;
begin
  FAuthor:='';
  FTitle:='';
  FGuid:='';
  FLink:='';
  FDescription:='';
  if assigned(theNode) then begin
    fNode:=theNode;

	 	FAuthor := getNodeVal(thenode,'author/name');
    FGuid := getNodeVal(theNode, 'id');
    FTitle := ExtractNonHTML(getNodeVal(thenode, 'title'));
    FLink := getNodeVal(thenode, 'link[@rel="alternate"]/@href');
    if FGuid = '' then FGuid := FLink;
    if FGuid = '' then FGuid := FTitle;
    try
      val := getNodeVal(thenode, 'modified');
      if val = '' then val := getNodeVal(thenode, 'created');
      FPubDate := TW3CDTF.Create( val );
    except
      FPubDate := TW3CDTF.CreateDatetime(0);
    end;
    tmpNode := theNode.selectSingleNode('content');
    if Assigned(tmpNode) then
	    FDescription := tmpNode.text
    else
      FDescription := GetNodeVal(theNode,'summary');
  end else
  	FPubDate := TW3CDTF.CreateDatetime(0);
end;

function TAtomItem.Get_Author: string; begin Result := FAuthor; end;
function TAtomItem.Get_Category: string; begin Result := ''; end;
function TAtomItem.Get_Creator: WideString; begin Result := Get_Author(); end;
function TAtomItem.Get_Description: string; begin Result := FDescription; end;
function TAtomItem.Get_Guid: WideString; begin Result := FGuid; end;
function TAtomItem.Get_PubDate: TW3CDTF; begin Result := FPubDate; end;
function TAtomItem.Get_Title: string; begin Result := FTitle; end;
function TAtomItem.Get_Link: WideString; begin Result := FLink; end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -