2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFXmlReader;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-03-16 19:09:42 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefXmlReaderRef = class(TCefBaseRefCountedRef, ICefXmlReader)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
|
|
|
function MoveToNextNode: Boolean;
|
|
|
|
function Close: Boolean;
|
|
|
|
function HasError: Boolean;
|
|
|
|
function GetError: ustring;
|
|
|
|
function GetType: TCefXmlNodeType;
|
|
|
|
function GetDepth: Integer;
|
|
|
|
function GetLocalName: ustring;
|
|
|
|
function GetPrefix: ustring;
|
|
|
|
function GetQualifiedName: ustring;
|
|
|
|
function GetNamespaceUri: ustring;
|
|
|
|
function GetBaseUri: ustring;
|
|
|
|
function GetXmlLang: ustring;
|
|
|
|
function IsEmptyElement: Boolean;
|
|
|
|
function HasValue: Boolean;
|
|
|
|
function GetValue: ustring;
|
|
|
|
function HasAttributes: Boolean;
|
|
|
|
function GetAttributeCount: NativeUInt;
|
|
|
|
function GetAttributeByIndex(index: Integer): ustring;
|
|
|
|
function GetAttributeByQName(const qualifiedName: ustring): ustring;
|
|
|
|
function GetAttributeByLName(const localName, namespaceURI: ustring): ustring;
|
|
|
|
function GetInnerXml: ustring;
|
|
|
|
function GetOuterXml: ustring;
|
|
|
|
function GetLineNumber: Integer;
|
|
|
|
function MoveToAttributeByIndex(index: Integer): Boolean;
|
|
|
|
function MoveToAttributeByQName(const qualifiedName: ustring): Boolean;
|
|
|
|
function MoveToAttributeByLName(const localName, namespaceURI: ustring): Boolean;
|
|
|
|
function MoveToFirstAttribute: Boolean;
|
|
|
|
function MoveToNextAttribute: Boolean;
|
|
|
|
function MoveToCarryingElement: Boolean;
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefXmlReader;
|
2018-05-12 14:50:54 +02:00
|
|
|
class function New(const stream: ICefStreamReader; encodingType: TCefXmlEncodingType; const URI: ustring): ICefXmlReader;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.Close: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.close(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
class function TCefXmlReaderRef.New(const stream: ICefStreamReader; encodingType: TCefXmlEncodingType; const URI: ustring): ICefXmlReader;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURI : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURI := CefString(URI);
|
|
|
|
Result := UnWrap(cef_xml_reader_create(CefGetData(stream), encodingType, @TempURI));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetAttributeByIndex(index: Integer): ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_attribute_byindex(PCefXmlReader(FData), index));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefXmlReaderRef.GetAttributeByLName(const localName, namespaceURI: ustring): ustring;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempLocalname, TempNamespaceURI : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempLocalname := CefString(localName);
|
|
|
|
TempNamespaceURI := CefString(namespaceURI);
|
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_attribute_bylname(PCefXmlReader(FData),
|
|
|
|
@TempLocalname,
|
|
|
|
@TempNamespaceURI));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefXmlReaderRef.GetAttributeByQName(const qualifiedName: ustring): ustring;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempName : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempName := CefString(qualifiedName);
|
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_attribute_byqname(PCefXmlReader(FData), @TempName));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetAttributeCount: NativeUInt;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.get_attribute_count(PCefXmlReader(FData));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetBaseUri: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_base_uri(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetDepth: Integer;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.get_depth(PCefXmlReader(FData));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetError: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_error(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetInnerXml: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_inner_xml(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetLineNumber: Integer;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.get_line_number(PCefXmlReader(FData));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetLocalName: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_local_name(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetNamespaceUri: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_namespace_uri(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetOuterXml: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_outer_xml(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetPrefix: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_prefix(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetQualifiedName: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_qualified_name(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetType: TCefXmlNodeType;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.get_type(PCefXmlReader(FData));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetValue: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_value(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.GetXmlLang: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefXmlReader(FData)^.get_xml_lang(PCefXmlReader(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.HasAttributes: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.has_attributes(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.HasError: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.has_error(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.HasValue: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.has_value(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.IsEmptyElement: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.is_empty_element(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.MoveToAttributeByIndex(index: Integer): Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.move_to_attribute_byindex(PCefXmlReader(FData), index) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefXmlReaderRef.MoveToAttributeByLName(const localName, namespaceURI: ustring): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempLocalname, TempNamespaceURI : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempLocalname := CefString(localName);
|
|
|
|
TempNamespaceURI := CefString(namespaceURI);
|
|
|
|
Result := PCefXmlReader(FData)^.move_to_attribute_bylname(PCefXmlReader(FData),
|
|
|
|
@TempLocalname,
|
|
|
|
@TempNamespaceURI) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefXmlReaderRef.MoveToAttributeByQName(const qualifiedName: ustring): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempName : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempName := CefString(qualifiedName);
|
|
|
|
Result := PCefXmlReader(FData)^.move_to_attribute_byqname(PCefXmlReader(FData), @TempName) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.MoveToCarryingElement: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.move_to_carrying_element(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.MoveToFirstAttribute: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.move_to_first_attribute(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.MoveToNextAttribute: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.move_to_next_attribute(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefXmlReaderRef.MoveToNextNode: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefXmlReader(FData)^.move_to_next_node(PCefXmlReader(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefXmlReaderRef.UnWrap(data: Pointer): ICefXmlReader;
|
|
|
|
begin
|
|
|
|
if data <> nil then
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := Create(data) as ICefXmlReader
|
|
|
|
else
|
2017-01-27 16:37:51 +01:00
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|