...
 
Commits (8)
init
res := v2
res := AAA
res := v1
res := v2
......
t := 123
res := AAA
u := 456
h := false
h := true
<?xml version="1.0" encoding="UTF-8"?>
<xml>
[
1,
2,
3,
{
&quot;a&quot;: 123,
&quot;b&quot;: &quot;c&lt;&amp;&gt;&quot;,
&quot;d&lt;&amp;&gt;&quot;: 456
}
]
</xml>
<?xml version="1.0" encoding="UTF-8"?>
<seq>
<e><seq><e>1</e><e>2</e><e>3</e><e><object><a>123</a><b>c&lt;&amp;&gt;</b><_ key="d&lt;&amp;&gt;">456</_></object></e></seq></e>
</seq>
......@@ -273,6 +273,8 @@ tests/test.sh xmlw-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format xml-wrap
tests/test.sh jsonw-json --printed-json-format compact -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format json-wrapped
tests/test.sh bash-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format bash
tests/test.sh xml2-json -e '[1,2,3,{"a": 123,"b":"c<&>", "d<&>": 456}]' --output-format xml
tests/test.sh xmlw2-json -e '[1,2,3,{"a": 123,"b":"c<&>", "d<&>": 456}]' --output-format xml-wrapped
tests/test.sh bash-escape1 --xquery '"1&#xA;2"' --output-format bash
tests/test.sh bash-escape2 --xquery '"1&#xD;2"' --output-format bash
......@@ -544,10 +546,14 @@ tests/test.sh regression_htmlparse --input-format html '<ol><li>a<li>b<li>c</ol
tests/test.sh variableActions [ '<a/>' --template-file tests/variable.actions ] '<b/>' --xquery '$first || ":" || $second '
tests/test.sh variableActions --template-file tests/variable.actions --xquery '$first || ":" || $second '
tests/test.sh moreActions1 --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions1 --template-action ac1,acmissing? --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions2 -e '"init"||get("res")' --template-action ac2 --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActionsLocalPattern --template-action local --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions -e '"init"||get("res")' --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res, for $i in ("ac2", "local", "ac1", "ac2") return ( x:call-action($i), "res:"||$res)' #variables set by call-action are reordered before the extract print, since the values of the extract are only known after the for has finished
tests/test.sh moreActions3 --template-file tests/more.actions -e 't:=123,x:call-action("local"),x:call-action("foo?"),u:=456,h:=x:has-action("foo"),h:=x:has-action("ac2")'
tests/test.sh eval --xquery 'let $a := 123 return eval("declare function local:abc(){0};456",{"language": "xquery"})'
tests/test.sh eval --xquery 'declare variable $outer := 456; let $a := 123 return eval("declare function local:abc(){0};$outer",{"language": "xquery"})'
echo
......
......@@ -221,6 +221,9 @@ Splits a text into lines.
<f name="call-action" args="($name as xs:string) as empty-sequence()">
Calls the action of a multipage template.
</f>
<f name="has-action" args="($name as xs:string) as xs:boolean">
Returns if a certain action is defined in the multipage template.
</f>
<f name="get-log" args="([$var as xs:string]) as item()*">
Gets all values of all variables, or all values of a single variable. <br/>
For all variables it returns a sequence of objects with name and value of the variable as properties.<br/>
......
......@@ -224,7 +224,7 @@ var htmlparser:THtmlTemplateParserBreaker;
multipagetemp: TMultiPageTemplate;
currentRoot: TTreeNode;
{$ifdef windows}
backgroundColor: integer;
backgroundColor, consoleTextAttributes: integer;
{$endif}
procedure setTerminalColor(err: boolean; color: TMyConsoleColors);
{$ifdef unix}
......@@ -339,8 +339,9 @@ begin
end;
{$ifdef windows}
if colorizing <> cNever then begin
GetConsoleScreenBufferInfo(StdOutputHandle, consoleBuffer);
backgroundColor := consoleBuffer.wAttributes and (BACKGROUND_RED or BACKGROUND_GREEN or BACKGROUND_BLUE or BACKGROUND_INTENSITY);
GetConsoleScreenBufferInfo(StdOutputHandle, @consoleBuffer);
consoleTextAttributes := consoleBuffer.wAttributes;
backgroundColor := consoleTextAttributes and (BACKGROUND_RED or BACKGROUND_GREEN or BACKGROUND_BLUE or BACKGROUND_INTENSITY);
end;
{$endif}
end;
......@@ -954,6 +955,9 @@ private
procedure httpReact (sender: TInternetAccess; var method: string; var url: TDecodedUrl; var data:TInternetAccessDataBlock; var reaction: TInternetAccessReaction);
end;
var globalCurrentExtraction: TExtraction;
type EInvalidArgument = Exception;
constructor TFollowToXQVObject.create(const abasedata: IData; const av: IXQValue);
......@@ -1777,6 +1781,7 @@ end;
constructor TExtraction.create;
begin
printVariables:=[pvCondensedLog];
if globalCurrentExtraction = nil then globalCurrentExtraction := self;
end;
function extractKindFromString(v: string): TExtractionKind;
......@@ -2595,6 +2600,7 @@ begin
if hasOutputEncoding <> oePassRaw then htmlparser.OutputEncoding := CP_UTF8
else htmlparser.OutputEncoding := CP_NONE;
globalDefaultInputFormat := inputFormat;
globalCurrentExtraction := self;
case extractKind of
ekPatternHTML, ekPatternXML: begin
......@@ -2638,6 +2644,7 @@ begin
end;
end;
ekMultipage: if assigned (onPrepareInternet) then begin
xpathparser.ParsingOptions.StringEntities:=xqseIgnoreLikeXPath;
multipage.onPageProcessed:=@pageProcessed;
if parent.silent then multipage.onLog := nil else multipage.onLog := @multipage.selfLog;
multipage.internet := onPrepareInternet(parent.userAgent, parent.proxy, @parent.httpReact);
......@@ -2709,6 +2716,7 @@ var
values: IXQValue;
j: Integer;
isShown: Boolean;
tempName: String;
begin
writeBeginGroup;
jsonItselfAssigned := false;
......@@ -2757,28 +2765,30 @@ begin
end else begin
first := true;
writeItem('{', cJSON);
setlength(tempUsed, vars.count);
FillChar(tempUsed[0], sizeof(tempUsed[0])*length(tempUsed), 0);
for i:=0 to vars.count-1 do begin
if tempUsed[i] then continue;
if acceptName(vars.Names[i]) then begin
if not first then wcolor(', ' + LineEnding, cJSON);
first := false;
writeVarName(jsonStrEscape(vars.Names[i]) + ': ', cJSON);
values := vars.getAll(vars.Names[i]);
if values.getSequenceCount = 1 then printExtractedValue(values, true)
else begin
wcolor('[', cJSON);
printExtractedValue(values.get(1), true);
for j:=2 to values.getSequenceCount do begin
wcolor(', ', cJSON);
printExtractedValue(values.get(j), true);
if vars.count > 0 then begin
setlength(tempUsed, vars.count);
FillChar(tempUsed[0], sizeof(tempUsed[0])*length(tempUsed), 0);
for i:=0 to vars.count-1 do begin
if tempUsed[i] then continue;
if acceptName(vars.Names[i]) then begin
if not first then wcolor(', ' + LineEnding, cJSON);
first := false;
writeVarName(jsonStrEscape(vars.Names[i]) + ': ', cJSON);
values := vars.getAll(vars.Names[i]);
if values.getSequenceCount = 1 then printExtractedValue(values, true)
else begin
wcolor('[', cJSON);
printExtractedValue(values.get(1), true);
for j:=2 to values.getSequenceCount do begin
wcolor(', ', cJSON);
printExtractedValue(values.get(j), true);
end;
wcolor(']', cJSON);
end;
wcolor(']', cJSON);
end;
for j := i + 1 to vars.count-1 do
if vars.Names[i] = vars.Names[j] then tempUsed[j] := true;
end;
for j := i + 1 to vars.count-1 do
if vars.Names[i] = vars.Names[j] then tempUsed[j] := true;
end;
wcolor(LineEnding + '}', cJSON);
end;
......@@ -2797,12 +2807,17 @@ begin
wcolor('</seq>' + LineEnding, cXML);
end else begin
wcolor(LineEnding + '<object>' + LineEnding, cXML);
for i:=0 to vars.count-1 do
if acceptName(vars.Names[i]) then begin
wcolor('<'+vars.Names[i] + '>', cXML);
printExtractedValue(vars.Values[i], true);
wcolor('</'+vars.Names[i] + '>'+LineEnding, cXML);
end;
for i:=0 to vars.count-1 do begin
if not acceptName(vars.Names[i]) then continue;
tempName := vars.Names[i];
if TXSSchema.isValidNCName(tempName) then wcolor('<'+tempName + '>', cXML)
else begin
wcolor('<_ key="'+xmlStrEscape(tempName, true) + '">', cXML);
tempName := '_';
end;
printExtractedValue(vars.Values[i], true);
wcolor('</'+tempName + '>'+LineEnding, cXML);
end;
wcolor('</object>'+LineEnding, cXML);
end;
end;
......@@ -3947,6 +3962,7 @@ begin
if outputfooter <> '' then wcolor(outputFooter, colorizing)
else if not mycmdline.existsProperty('output-footer') and not firstItem then wln();
{$ifdef windows}if colorizing <> cNever then SetConsoleTextAttribute(StdOutputHandle, consoleTextAttributes); {$endif}
mycmdLine.free;
tracer.free;
......@@ -4190,10 +4206,29 @@ begin
end;
function xqfCallAction(argc: SizeInt; args: PIXQValue): IXQValue;
var
oldEntites: TXQParsingOptionsStringEntities;
begin
requiredArgCount(argc, 1);
result := xqvalue;
if htmlparser.variableChangeLog.count > 0 then begin
assert(globalCurrentExtraction <> nil);
globalCurrentExtraction.printExtractedVariables(htmlparser, false);
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
end;
oldEntites := htmlparser.QueryEngine.ParsingOptions.StringEntities;
htmlparser.QueryEngine.ParsingOptions.StringEntities := xqseIgnoreLikeXPath;
multipage.callAction(args[0].toString);
htmlparser.QueryEngine.ParsingOptions.StringEntities := oldEntites;
end;
function xqfHasAction(argc: SizeInt; args: PIXQValue): IXQValue;
begin
requiredArgCount(argc, 1);
result := xqvalue(multipage.findAction(args[0].toString) <> nil);
end;
function xqfClearLog(argc: SizeInt; args: PIXQValue): IXQValue;
......@@ -4286,6 +4321,7 @@ initialization
pxpx.registerFunction('integer', @xqfInteger, ['($arg as item()) as xs:integer', '($arg as item(), $base as xs:integer) as xs:integer']);
pxpx.registerFunction('integer-to-base', @xqfIntegerToBase, ['($arg as xs:integer, $base as xs:integer) as xs:string']);
pxpx.registerFunction('call-action', @xqfCallAction, ['($arg as xs:string) as empty-sequence()']);
pxpx.registerFunction('has-action', @xqfHasAction, ['($arg as xs:string) as xs:boolean']);
pxpx.registerFunction('clear-log', @xqfClearLog, ['() as empty-sequence()', '($var as xs:string) as empty-sequence()']);
pxpx.registerFunction('get-log', @xqfGetLog, ['() as item()*', '($var as xs:string) as item()*']);
end.
......