1
1
/* *************************************************************************
2
2
* This file is part of QXmlEdit *
3
- * Copyright (C) 2011-2018 by Luca Bellonda and individual contributors *
3
+ * Copyright (C) 2011-2020 by Luca Bellonda and individual contributors *
4
4
* as indicated in the AUTHORS file *
5
5
* lbellonda _at_ gmail.com *
6
6
* *
@@ -142,11 +142,14 @@ bool ExtractionOperation::isXMLFilterExport() const
142
142
return OperationExportAndGroupXML == _operationType ;
143
143
}
144
144
145
+ /* ****
146
+ * Some notes: InFragment: true if inside the split path/depth, can be collected or not (filter) registerDocument=true)
147
+ * outside a fragment should be collected if filter and not group.
148
+ * ****/
145
149
void ExtractionOperation::execute (QFile *file)
146
150
{
147
151
bool debugIO = _debug ;
148
152
int operationCount = 0 ;
149
- // bool inDocument = false; TODO
150
153
bool insideAFragment = false ;
151
154
bool isWriting = false ;
152
155
QXmlStreamReader xmlReader;
@@ -188,7 +191,7 @@ void ExtractionOperation::execute(QFile *file)
188
191
xmlReader.clear ();
189
192
xmlReader.setDevice (file);
190
193
_size = Utils::infoSizeAboutLocalDevice (NULL , file->fileName ());
191
- bool isAFilteredExtraction = _isExtractDocuments && ! isExtractAllDocuments () && (OperationFilter == _operationType);
194
+ bool isAFilteredExtraction = _isExtractDocuments && (OperationFilter == _operationType);
192
195
bool isAnExportExtraction = _isExtractDocuments && ((OperationExportAndGroupCSV == _operationType) || (OperationExportAndGroupXML == _operationType));
193
196
qint64 previousPos = 0 ;
194
197
while (!xmlReader.atEnd ()) {
@@ -249,9 +252,12 @@ void ExtractionOperation::execute(QFile *file)
249
252
dontWrite = true ;
250
253
}
251
254
}
252
- if (isScripting && insideAFragment) {
253
- if (!manageText (info, level, path, xmlReader, dontWrite)) {
254
- return ;
255
+ if (isScripting && insideAFragment && !dontWrite) {
256
+ const bool canExecute = evaluateScriptingConditions (isAFilteredExtraction, insideAFragment, isStillInFragment, isWriting, dontWrite);
257
+ if (canExecute) {
258
+ if (!manageText (info, level, path, xmlReader, dontWrite)) {
259
+ return ;
260
+ }
255
261
}
256
262
}
257
263
break ;
@@ -318,9 +324,6 @@ void ExtractionOperation::execute(QFile *file)
318
324
}
319
325
insideAFragment = true ;
320
326
if (registerDocument) {
321
- if (!manageElement (info, level, path, xmlReader, dontWrite)) {
322
- return ;
323
- }
324
327
if (isAnExportExtraction) {
325
328
if (!handleExportedElement (info, xmlReader)) {
326
329
isError = true ;
@@ -335,9 +338,13 @@ void ExtractionOperation::execute(QFile *file)
335
338
}
336
339
}
337
340
}
338
- } else {
339
- if (!manageElement (info, level, path, xmlReader, dontWrite)) {
340
- return ;
341
+ }
342
+ if (isScripting) {
343
+ const bool canExecute = evaluateScriptingConditions (isAFilteredExtraction, insideAFragment, isStillInFragment, isWriting, dontWrite);
344
+ if (canExecute) {
345
+ if (!manageElement (info, level, path, xmlReader, dontWrite)) {
346
+ return ;
347
+ }
341
348
}
342
349
}
343
350
if (isError) {
@@ -461,6 +468,25 @@ void ExtractionOperation::execute(QFile *file)
461
468
_isEnded = true ;
462
469
}
463
470
471
+ bool ExtractionOperation::evaluateScriptingConditions (const bool isAFilteredExtraction, const bool insideAFragment,
472
+ const bool isStillInFragment, const bool isWriting, const bool dontWrite)
473
+ {
474
+ Utils::TODO_THIS_RELEASE (" prova con testo in e out dagli elementi" );
475
+ bool canExecute = false ;
476
+ if (isAFilteredExtraction) {
477
+ if ((!insideAFragment && !isStillInFragment) || (insideAFragment && isWriting)) {
478
+ if (!dontWrite) {
479
+ canExecute = true ;
480
+ }
481
+ }
482
+ } else {
483
+ if (isWriting && !dontWrite) {
484
+ canExecute = true ;
485
+ }
486
+ } // check for write
487
+ return canExecute;
488
+ }
489
+
464
490
bool ExtractionOperation::writeAToken (const bool isAFilteredExtraction, const bool insideAFragment, ExtractInfo &info, QXmlStreamReader &reader)
465
491
{
466
492
if ((insideAFragment && _isExtractDocuments) || isAFilteredExtraction) {
0 commit comments