* Renamed TXMLCharSource.SystemID to SourceURI to better reflect its purpose (System ID should typically be combined with Base URI to get the full URI for the given resource).

git-svn-id: trunk@20687 -
This commit is contained in:
sergei 2012-04-01 20:44:32 +00:00
parent 9525abb330
commit dfec10d430

View File

@ -170,12 +170,12 @@ type
FLineNo: Integer; FLineNo: Integer;
LFPos: PWideChar; LFPos: PWideChar;
FXML11Rules: Boolean; FXML11Rules: Boolean;
FSystemID: XMLString; FSourceURI: XMLString;
FCharCount: Cardinal; FCharCount: Cardinal;
FStartNesting: Integer; FStartNesting: Integer;
FXMLVersion: TXMLVersion; FXMLVersion: TXMLVersion;
FXMLEncoding: XMLString; FXMLEncoding: XMLString;
function GetSystemID: XMLString; function GetSourceURI: XMLString;
protected protected
function Reload: Boolean; virtual; function Reload: Boolean; virtual;
public public
@ -188,7 +188,7 @@ type
procedure Initialize; virtual; procedure Initialize; virtual;
function SetEncoding(const AEncoding: string): Boolean; virtual; function SetEncoding(const AEncoding: string): Boolean; virtual;
function Matches(const arg: XMLString): Boolean; function Matches(const arg: XMLString): Boolean;
property SystemID: XMLString read GetSystemID write FSystemID; property SourceURI: XMLString read GetSourceURI write FSourceURI;
end; end;
TXMLDecodingSource = class(TXMLCharSource) TXMLDecodingSource = class(TXMLCharSource)
@ -672,12 +672,12 @@ begin
Result := True; // always succeed Result := True; // always succeed
end; end;
function TXMLCharSource.GetSystemID: XMLString; function TXMLCharSource.GetSourceURI: XMLString;
begin begin
if FSystemID <> '' then if FSourceURI <> '' then
Result := FSystemID Result := FSourceURI
else if Assigned(FParent) then else if Assigned(FParent) then
Result := FParent.SystemID Result := FParent.SourceURI
else else
Result := ''; Result := '';
end; end;
@ -966,7 +966,7 @@ end;
constructor TXMLFileInputSource.Create(var AFile: Text); constructor TXMLFileInputSource.Create(var AFile: Text);
begin begin
FFile := @AFile; FFile := @AFile;
SystemID := FilenameToURI(TTextRec(AFile).Name); SourceURI := FilenameToURI(TTextRec(AFile).Name);
FetchData; FetchData;
end; end;
@ -1045,14 +1045,14 @@ end;
function TXMLTextReader.ResolveResource(const ASystemID, APublicID, ABaseURI: XMLString; out Source: TXMLCharSource): Boolean; function TXMLTextReader.ResolveResource(const ASystemID, APublicID, ABaseURI: XMLString; out Source: TXMLCharSource): Boolean;
var var
AbsSysID: XMLString; SrcURI: XMLString;
Filename: string; Filename: string;
Stream: TStream; Stream: TStream;
fd: THandle; fd: THandle;
begin begin
Source := nil; Source := nil;
Result := False; Result := False;
if not ResolveRelativeURI(ABaseURI, ASystemID, AbsSysID) then if not ResolveRelativeURI(ABaseURI, ASystemID, SrcURI) then
Exit; Exit;
{ TODO: alternative resolvers { TODO: alternative resolvers
These may be 'internal' resolvers or a handler set by application. These may be 'internal' resolvers or a handler set by application.
@ -1061,14 +1061,14 @@ begin
External resolver will produce TXMLInputSource that should be converted. External resolver will produce TXMLInputSource that should be converted.
External resolver must NOT be called for root entity. External resolver must NOT be called for root entity.
External resolver can return nil, in which case we do the default } External resolver can return nil, in which case we do the default }
if URIToFilename(AbsSysID, Filename) then if URIToFilename(SrcURI, Filename) then
begin begin
fd := FileOpen(Filename, fmOpenRead + fmShareDenyWrite); fd := FileOpen(Filename, fmOpenRead + fmShareDenyWrite);
if fd <> THandle(-1) then if fd <> THandle(-1) then
begin begin
Stream := THandleOwnerStream.Create(fd); Stream := THandleOwnerStream.Create(fd);
Source := TXMLStreamInputSource.Create(Stream, True); Source := TXMLStreamInputSource.Create(Stream, True);
Source.SystemID := AbsSysID; // <- Revisit: Really need absolute sysID? Source.SourceURI := SrcURI;
end; end;
end; end;
Result := Assigned(Source); Result := Assigned(Source);
@ -1136,14 +1136,14 @@ end;
procedure TXMLTextReader.DoErrorPos(Severity: TErrorSeverity; const descr: string; const ErrPos: TLocation); procedure TXMLTextReader.DoErrorPos(Severity: TErrorSeverity; const descr: string; const ErrPos: TLocation);
var var
E: EXMLReadError; E: EXMLReadError;
sysid: XMLString; srcuri: XMLString;
begin begin
if Assigned(FSource) then if Assigned(FSource) then
begin begin
sysid := FSource.FSystemID; srcuri := FSource.FSourceURI;
if (sysid = '') and Assigned(FSource.FEntity) then if (srcuri = '') and Assigned(FSource.FEntity) then
sysid := FSource.FEntity.FURI; srcuri := FSource.FEntity.FURI;
E := EXMLReadError.CreateFmt('In ''%s'' (line %d pos %d): %s', [sysid, ErrPos.Line, ErrPos.LinePos, descr]); E := EXMLReadError.CreateFmt('In ''%s'' (line %d pos %d): %s', [srcuri, ErrPos.Line, ErrPos.LinePos, descr]);
end end
else else
E := EXMLReadError.Create(descr); E := EXMLReadError.Create(descr);
@ -1854,7 +1854,7 @@ begin
Src.LFPos := Src.FBuf - AEntity.FStartLocation.LinePos; Src.LFPos := Src.FBuf - AEntity.FStartLocation.LinePos;
// needed in case of prefetched external PE // needed in case of prefetched external PE
if AEntity.FSystemID <> '' then if AEntity.FSystemID <> '' then
Src.SystemID := AEntity.FURI; Src.SourceURI := AEntity.FURI;
end; end;
AEntity.FOnStack := True; AEntity.FOnStack := True;
@ -1981,7 +1981,7 @@ begin
AEntity.FCharCount := FValue.Length; AEntity.FCharCount := FValue.Length;
AEntity.FStartLocation.Line := 1; AEntity.FStartLocation.Line := 1;
AEntity.FStartLocation.LinePos := 1; AEntity.FStartLocation.LinePos := 1;
AEntity.FURI := FSource.SystemID; // replace base URI with absolute one AEntity.FURI := FSource.SourceURI; // replace base URI with absolute one
finally finally
ContextPop; ContextPop;
AEntity.FPrefetched := True; AEntity.FPrefetched := True;
@ -2267,7 +2267,7 @@ begin
if (FDocType.FSystemID <> '') then if (FDocType.FSystemID <> '') then
begin begin
if ResolveResource(FDocType.FSystemID, FDocType.FPublicID, FSource.SystemID, Src) then if ResolveResource(FDocType.FSystemID, FDocType.FPublicID, FSource.SourceURI, Src) then
begin begin
Initialize(Src); Initialize(Src);
try try
@ -2479,7 +2479,7 @@ begin
Notation.FName := NameStr; Notation.FName := NameStr;
Notation.FPublicID := PubID; Notation.FPublicID := PubID;
Notation.FSystemID := SysID; Notation.FSystemID := SysID;
Notation.FURI := Src.SystemID; Notation.FURI := Src.SourceURI;
Entry^.Data := Notation; Entry^.Data := Notation;
end end
else else
@ -2667,7 +2667,7 @@ begin
// remember where the entity is declared, use URI from the point where declaration // remember where the entity is declared, use URI from the point where declaration
// was starting. // was starting.
Entity.FURI := Src.SystemID; Entity.FURI := Src.SourceURI;
if FEntityValue.Buffer = nil then if FEntityValue.Buffer = nil then
BufAllocate(FEntityValue, 256); BufAllocate(FEntityValue, 256);
@ -2931,7 +2931,7 @@ end;
function TXMLTextReader.GetBaseUri: XMLString; function TXMLTextReader.GetBaseUri: XMLString;
begin begin
result := FSource.SystemID; result := FSource.SourceURI;
end; end;
{ IXmlLineInfo methods } { IXmlLineInfo methods }
@ -3297,7 +3297,6 @@ procedure TXMLTextReader.ResolveEntity;
var var
n: PNodeData; n: PNodeData;
ent: TEntityDecl; ent: TEntityDecl;
src: TXMLCharSource;
begin begin
if FCurrNode^.FNodeType <> ntEntityReference then if FCurrNode^.FNodeType <> ntEntityReference then
raise EInvalidOperation.Create('Wrong node type'); raise EInvalidOperation.Create('Wrong node type');
@ -4302,7 +4301,7 @@ var
begin begin
ADoc := TXMLDocument.Create; ADoc := TXMLDocument.Create;
Src := TXMLStreamInputSource.Create(f, False); Src := TXMLStreamInputSource.Create(f, False);
Src.SystemID := ABaseURI; Src.SourceURI := ABaseURI;
Reader := TXMLTextReader.Create(Src, ADoc.Names); Reader := TXMLTextReader.Create(Src, ADoc.Names);
try try
ldr.ProcessXML(ADoc, Reader); ldr.ProcessXML(ADoc, Reader);
@ -4351,7 +4350,7 @@ var
ldr: TLoader; ldr: TLoader;
begin begin
Src := TXMLStreamInputSource.Create(f, False); Src := TXMLStreamInputSource.Create(f, False);
Src.SystemID := ABaseURI; Src.SourceURI := ABaseURI;
Reader := TXMLTextReader.Create(Src, AParentNode.OwnerDocument.Names); Reader := TXMLTextReader.Create(Src, AParentNode.OwnerDocument.Names);
try try
ldr.ProcessFragment(AParentNode, Reader); ldr.ProcessFragment(AParentNode, Reader);
@ -4402,7 +4401,7 @@ var
begin begin
ADoc := TXMLDocument.Create; ADoc := TXMLDocument.Create;
Src := TXMLStreamInputSource.Create(f, False); Src := TXMLStreamInputSource.Create(f, False);
Src.SystemID := ABaseURI; Src.SourceURI := ABaseURI;
Reader := TXMLTextReader.Create(Src, ADoc.Names); Reader := TXMLTextReader.Create(Src, ADoc.Names);
try try
ldr.ProcessDTD(ADoc,Reader); ldr.ProcessDTD(ADoc,Reader);