📄 ulocalrss.pas
字号:
unit uLocalRSS;
interface
uses Classes, uW3CDTF, FastStringFuncs, MSXML2_TLB,
uConstants;
type
TLocalRssItem = class(TComponent)
private
FNode:IXMLDOMNode;
FFeedTitle:string;
FAuthor: string;
FTitle: string;
FPubDate: TW3CDTF;
FGuid: WideString;
FLink: WideString;
FDescription: string;
FCategory : string;
FCommentCount : integer;
FComment : Widestring;
FCommentRss : Widestring;
FCommentURL : Widestring;
FReaded:Boolean;
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_CommentCount: integer;
function Get_CommenTLocalRss: WideString;
function Get_CommentURL: WideString;
function Get_Comment: WideString;
function Get_Description: string;
procedure Set_PubDate(Value:TW3CDTF);
procedure Set_Title(Value:string);
procedure Set_Link(Value:WideString);
procedure Set_Guid(Value:Widestring);
procedure Set_Description(Value:string);
procedure Set_Author(Value:string);
procedure Set_Category(Value:string);
procedure Set_Creator(Value:Widestring);
procedure Set_Comment(Value:Widestring);
procedure Set_CommentCount(Value:Integer);
procedure Set_CommentURL(Value:Widestring);
procedure Set_CommenTLocalRss(Value:Widestring);
function Get_Readed:Boolean;
procedure Set_Readed(Value:Boolean);
public
constructor Create(AOnwer:TComponent;theNode : IXmlDOMNode);
property PubDate: TW3CDTF read Get_PubDate write Set_PubDate;
property Title: string read Get_Title write Set_Title;
property Link: WideString read Get_Link write Set_Link;
property Guid: WideString read Get_Guid write Set_Guid;
property Description: string read Get_Description write Set_Description;
property Author: string read Get_Author write Set_Author;
property Category: string read Get_Category write Set_Category;
property Creator: WideString read Get_Creator write Set_Creator;
property Comment: WideString read Get_Comment write Set_Comment;
property CommentCount: integer read Get_CommentCount write Set_CommentCount;
property CommentRss: WideString read Get_CommenTLocalRss write Set_CommenTLocalRss;
property Readed:Boolean read Get_Readed write Set_Readed;
end;
TLocalRssItems = class(TComponent)
private
fItems : TList;
fNode:IXMLDOMNode;
protected
procedure Add(item : TObject);overload;
function Get_Item(index : integer): TLocalRssItem;
function Get_Count(): integer;
public
constructor Create(AOnwer:TComponent;theNode:IXMLDOMNode);
function IndexOfLink(ALink:WideString):integer;
function IndexOfTitle(ATitle:String):integer;
function Add:TLocalRssItem;overload;
procedure Delete(Index:integer);overload;
procedure Delete(Item:TLocalRssItem);overload;
property Item[Index: Integer]: TLocalRssItem read Get_Item;
property Count : integer read Get_Count;
end;
TLocalRSSImage = class(TComponent)
private
fNode:IXMLDOMNode;
FTitle: WideString;
FLink: WideString;
FURL: WideString;
FWidth: WideString;
FHeight: WideString;
protected
{ IRSSImageBase }
function Get_Title: WideString;
function Get_Link: WideString;
function Get_URL: WideString;
function Get_Width: WideString;
function Get_Height: WideString;
procedure Set_Title(Value:WideString);
procedure Set_Link(Value:WideString);
procedure Set_URL(Value:WideString);
procedure Set_Width(Value:WideString);
procedure Set_Height(Value:WideString);
public
constructor Create(AOnwer:TComponent;theNode : IXMLDOMNode);
property Title: WideString read Get_Title write Set_Title;
property Link: WideString read Get_Link write Set_Link;
property URL: WideString read Get_URL write Set_URL;
property Width: WideString read Get_Width write Set_Width;
property Height: WideString read Get_Height write Set_Height;
end;
TLocalRssFeed = class(TComponent)
private
FDoc:IXMLDOMDocument2;
fNode:IXMLDOMNode;
fItems : TLocalRssItems;
FImage : TLocalRSSImage;
FTitle, FDescription : string;
FLastUpdate:TW3CDTF;
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: TLocalRssItems;
function Get_Image: TLocalRSSImage;
function Get_LastUpdate:TW3CDTF;
procedure Set_Title(Value:string);
procedure Set_Version(Value:WideString);
procedure Set_Link(Value:WideString);
procedure Set_Description(Value:string);
procedure Set_Creator(Value:WideString);
procedure Set_LastUpdate(Value:TW3CDTF);
public
constructor Create(AOnwer:TComponent;theDoc : IXMLDOMDocument2);
procedure SaveXml(Destination: OleVariant);
property Items:TLocalRssItems read fItems write fItems;
property Image:TLocalRSSImage read FImage write FImage;
property Version: WideString read Get_Version write Set_Version;
property Title: string read Get_Title write Set_Title;
property Link: Widestring read Get_Link write Set_Link;
property Description: string read Get_Description write Set_Description;
property Creator: WideString read Get_Creator write Set_Creator;
property LastUpdate:TW3CDTF read Get_LastUpdate write Set_LastUpdate;
end;
function GetLocalRssFeed(AOnwer:TComponent;Doc: IXMLDOMDocument2): TLocalRssFeed;
function LoadRSSFeed(AOnwer:TComponent;FileName:WideString): TLocalRssFeed;
implementation
uses SysUtils, ComObj;
function GetLocalRssFeed(AOnwer:TComponent;Doc: IXMLDOMDocument2): TLocalRssFeed;
begin
Result := TLocalRssFeed.Create(AOnwer,Doc);
end;
function LoadRSSFeed(AOnwer:TComponent;FileName:WideString): TLocalRssFeed;
var Doc:IXMLDOMDocument2;
begin
if FileExists(FileName) then
begin
Doc:=CoDOMDocument.Create;
Doc.load(FileName);
Result := TLocalRssFeed.Create(AOnwer,Doc);
end
else Result:=nil;
end;
{ TLocalRssFeed }
constructor TLocalRssFeed.Create(AOnwer:TComponent;theDoc: IXMLDOMDocument2);
var
i : integer;
channelNodes : IXMLDOMNodeList;
theNode: IXmlDomNode;
sLastUpdate:string;
begin
inherited Create(AOnwer);
FDoc:=theDoc;
theNode:= FDoc.documentElement;
fNode := theNode.selectSingleNode('channel');
fItems := TLocalRssItems.Create(Self,fnode);
Fimage := TLocalRssImage.Create(Self,fnode.selectSingleNode('image'));
FCreator := getNodeVal(fnode, 'creator');
FDescription := getNodeVal(fnode, 'description');
FTitle := ExtractNonHTML(getNodeVal(fnode, 'title'));
FLink := getNodeVal(fnode, 'link');
FVersion := 'RSS ' + getNodeVal(thenode, '@version');
sLastUpdate:=getNodeVal(fnode, 'lastUpdate');
if sLastUpdate='' then
FLastUpdate:=TW3CDTF.Create(DateTimeToStr(Now))
else
FLastUpdate:=TW3CDTF.Create(sLastUpdate);
channelNodes := fnode.selectNodes('item');
for i := 0 to channelNodes.Length - 1 do
fitems.Add( TLocalRssItem.Create(fItems,channelNodes.item[i]) );
end;
procedure TLocalRssFeed.SaveXml(Destination: OleVariant);
begin
FDoc.save(Destination);
end;
function TLocalRssFeed.Get_Creator: WideString; begin Result := FCreator; end;
function TLocalRssFeed.Get_Description: string; begin Result := FDescription; end;
function TLocalRssFeed.Get_Image: TLocalRSSImage; begin Result := FImage; end;
function TLocalRssFeed.Get_Items: TLocalRssItems; begin Result := fItems; end;
function TLocalRssFeed.Get_Link: WideString; begin Result := FLink; end;
function TLocalRssFeed.Get_Title: string; begin Result := FTitle; end;
function TLocalRssFeed.Get_Version: WideString; begin Result := FVersion; end;
function TLocalRssFeed.Get_LastUpdate: TW3CDTF; begin Result := FLastUpdate; end;
procedure TLocalRssFeed.Set_Title(Value:string);
begin
FTitle:=Value;
SetNodeVal(fNode,'title',Value);
end;
procedure TLocalRssFeed.Set_Version(Value:WideString);
begin
FVersion:=Value;
SetNodeAttrVal(fNode.parentNode,'version',Value);
end;
procedure TLocalRssFeed.Set_Link(Value:WideString);
begin
FLink:=Value;
SetNodeVal(fNode,'link',Value);
end;
procedure TLocalRssFeed.Set_Description(Value:string);
begin
FDescription:=Value;
SetNodeVal(fNode,'description',Value);
end;
procedure TLocalRssFeed.Set_Creator(Value:WideString);
begin
FCreator:=Value;
SetNodeVal(fNode,'creator',Value);
end;
procedure TLocalRssFeed.Set_LastUpdate(Value:TW3CDTF);
begin
FLastUpdate:=Value;
SetNodeVal(fNode,'lastUpdate',FLastUpdate.ToRFC822String);
end;
{ TLocalRssItems }
constructor TLocalRssItems.Create(AOnwer:TComponent;theNode:IXMLDOMNode);
begin
inherited Create(AOnwer);
fNode:=theNode;
fItems := TList.Create;
end;
function TLocalRssItems.IndexOfLink(ALink:WideString):integer;
var i:Integer;
begin
Result:=-1;
for i:= 0 to fItems.Count - 1 do
if TLocalRssItem(fItems[i]).FLink=ALink then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -