@@ -36,16 +36,11 @@ TErrorInfo = record
36
36
public
37
37
// / <summary>Error code.</summary>
38
38
Code: TErrorCode;
39
- // / <summary>Reference to element causing problem.</summary>
40
- // / <remarks>May be nil if error doesn't relate to an element.
41
- // / </remarks>
42
- Element: IActiveTextElem;
43
39
// / <summary>Description of error.</summary>
44
40
Description: string;
45
41
// / <summary>Constructs a record. Sets fields from parameter values.
46
42
// / </summary>
47
- constructor Create(const ACode: TErrorCode; AElement: IActiveTextElem;
48
- const ADescription: string); overload;
43
+ constructor Create(const ACode: TErrorCode; const ADescription: string);
49
44
end ;
50
45
strict private
51
46
// / <summary>Validates given link element.</summary>
@@ -56,6 +51,14 @@ TErrorInfo = record
56
51
// / <returns>Boolean. True on success or False on failure.</returns>
57
52
class function ValidateLink (LinkElem: IActiveTextActionElem;
58
53
out ErrInfo: TErrorInfo): Boolean; static;
54
+ // / <summary>Validates document structure.</summary>
55
+ // / <param name="ActiveText">IActiveText [in] Active text to be validated.
56
+ // / </param>
57
+ // / <param name="ErrInfo">TErrorInfo [out] Contains error information if
58
+ // / validation fails. Undefined if validation succeeds.</param>
59
+ // / <returns>Boolean. True on success or False on failure.</returns>
60
+ class function ValidateDocumentStructure (ActiveText: IActiveText;
61
+ out ErrInfo: TErrorInfo): Boolean; static;
59
62
public
60
63
// / <summary>Validates given active text.</summary>
61
64
// / <param name="ActiveText">IActiveText [in] Active text to be validated.
@@ -92,6 +95,9 @@ class function TActiveTextValidator.Validate(ActiveText: IActiveText;
92
95
begin
93
96
if ActiveText.IsEmpty then
94
97
Exit(True);
98
+ // Validate document structure
99
+ if not ValidateDocumentStructure(ActiveText, ErrInfo) then
100
+ Exit(False);
95
101
// Validate elements
96
102
for Elem in ActiveText do
97
103
begin
@@ -115,6 +121,16 @@ class function TActiveTextValidator.Validate(ActiveText: IActiveText): Boolean;
115
121
Result := Validate(ActiveText, Dummy);
116
122
end ;
117
123
124
+ class function TActiveTextValidator.ValidateDocumentStructure (
125
+ ActiveText: IActiveText; out ErrInfo: TErrorInfo): Boolean;
126
+ resourcestring
127
+ sNoDocTags = ' Document must start and end with document tags' ;
128
+ begin
129
+ Result := ActiveText.IsValidActiveTextDocument;
130
+ if not Result then
131
+ ErrInfo := TErrorInfo.Create(errBadStructure, sNoDocTags);
132
+ end ;
133
+
118
134
class function TActiveTextValidator.ValidateLink (
119
135
LinkElem: IActiveTextActionElem; out ErrInfo: TErrorInfo): Boolean;
120
136
resourcestring
@@ -150,7 +166,7 @@ TProtocolInfo = record
150
166
< Length(PI.Protocol) + PI.MinURLLength then
151
167
begin
152
168
ErrInfo := TErrorInfo.Create(
153
- errBadLinkURL, LinkElem, Format(sURLLengthErr, [URL])
169
+ errBadLinkURL, Format(sURLLengthErr, [URL])
154
170
);
155
171
Exit(False);
156
172
end ;
@@ -160,17 +176,16 @@ TProtocolInfo = record
160
176
// No supported protocol
161
177
Result := False;
162
178
ErrInfo := TErrorInfo.Create(
163
- errBadLinkProtocol, LinkElem, Format(sURLProtocolErr, [URL])
179
+ errBadLinkProtocol, Format(sURLProtocolErr, [URL])
164
180
);
165
181
end ;
166
182
167
183
{ TActiveTextValidator.TErrorInfo }
168
184
169
185
constructor TActiveTextValidator.TErrorInfo.Create(const ACode: TErrorCode;
170
- AElement: IActiveTextElem; const ADescription: string);
186
+ const ADescription: string);
171
187
begin
172
188
Code := ACode;
173
- Element := AElement;
174
189
Description := ADescription;
175
190
end ;
176
191
0 commit comments