Index: XmlTools2/trunk/xmlpatch.cpp
===================================================================
--- XmlTools2/trunk/xmlpatch.cpp	(revision 960)
+++ XmlTools2/trunk/xmlpatch.cpp	(revision 964)
@@ -47,5 +47,5 @@
 void XmlPatch::insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){
 
-    QStringList filesToProcess;
+    QVector<QString> filesToProcess;
     QList<pugi::xml_node> nodesToInsertion;
     pugi::xml_document newNode;
@@ -115,5 +115,5 @@
 void XmlPatch::removeNodesOperation(XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){
 
-    QStringList filesToProcess;
+    QVector<QString> filesToProcess;
 
     QList<pugi::xml_node> nodesToDeletion;
@@ -212,15 +212,7 @@
 }
 
-QScriptValue echo(QScriptContext *context, QScriptEngine *engine)
-{
-    std::cout << context->argument(0).toString().toUtf8().constData() << std::endl;
-
-    return "";
-}
-
 void XmlPatch::executeCustomCommandOperation(const QString &jsString, const QString &filesWildcard){
 
-    QString rexmlString, jsxmlString;
-    QStringList filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
+    QVector<QString> filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
 
     if(filesToProcess.isEmpty()){
@@ -228,81 +220,6 @@
     }
 
-    QFile rexmlfile(":/resources/libs/rexml.js");
-    QFile jsxmlfile(":/resources/libs/jsxml.js");
-
-    rexmlfile.open(QFile::ReadOnly | QFile::Text);
-    jsxmlfile.open(QFile::ReadOnly | QFile::Text);
-
-    rexmlString=QTextStream(&rexmlfile).readAll();
-    jsxmlString=QTextStream(&jsxmlfile).readAll();
-
-    // Process all XmlFiles
-#pragma omp parallel for
-    for(int i=0; i<filesToProcess.size(); i++){
-
-        QString currXmlFileString;
-
-        QScriptEngine engine;
-        QScriptValue engineResult; // variable to check for js_errors
-        double elapsed_secs; // elapsed seconds that a user script took
-        clock_t begin; // seconds that a script started
-
-        // Add echo function so user can debug the code
-        QScriptValue echoFunction = engine.newFunction(echo);
-        engine.globalObject().setProperty("echo", echoFunction);
-
-        engine.evaluate(rexmlString); // load js libraries
-        engine.evaluate(jsxmlString);
-
-        if(this->backupsEnabled){
-            UtilXmlTools::backupFile(filesToProcess[i], this->verboseEnabled);
-        }
-
-        QFile currXmlFile(filesToProcess[i]);
-
-        if(!currXmlFile.open(QFile::ReadOnly | QFile::Text)){
-            UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Error loading '" + filesToProcess[i] + "' file for read operation.");
-        }
-
-        currXmlFileString=QTextStream(&currXmlFile).readAll();
-
-        currXmlFile.close(); // close reading
-
-        engine.globalObject().setProperty("$xmlData",currXmlFileString);
-
-        begin = clock();
-
-        // main needs to be called so the user code is evaluated
-        // alternatively you can do: myFunc=engine.evaluate('(function main(){})'); myFunc.call();
-        // Note the () around the function
-        engineResult=engine.evaluate("main(); function main() {"+jsString+"}"); // main funtion allows to use return to exit prematurely from user code
-
-        if(this->verboseEnabled){
-            elapsed_secs = double(clock() - begin) / CLOCKS_PER_SEC;
-
-            // Warn the user if the script took much time
-            if(elapsed_secs>SLOW_SCRIPT_TIME){
-                std::cout << "Warning: Slow javascript code detected.\n" <<
-                             "Warning: Script execution seconds: " << elapsed_secs
-                          << std::endl;
-            }
-        }
-
-        if (engine.hasUncaughtException()) {
-            displayJsException(engine,engineResult);
-        }
-
-        if(!currXmlFile.open(QFile::WriteOnly | QFile::Text | QIODevice::Truncate)){
-            UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Error loading '" + filesToProcess[i] + "' file for @CUSTOM_CODE write operation.");
-        }
-
-        engineResult=engine.globalObject().property("$xmlData");
-
-        if (engine.hasUncaughtException()) {
-            displayJsException(engine,engineResult);
-        }
-
-        QTextStream(&currXmlFile) << engineResult.toString(); // retreive the modified xml by javascript and save it to the file
-    }
+    this->customCodeOperation.executeCustomCode(jsString,filesToProcess,this->backupsEnabled,this->verboseEnabled);
+
 
     UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@CUSTOM_CODE");
@@ -515,8 +432,2 @@
     return line.mid(startValueIdx,endValueIdx-startValueIdx); // return the value of the parameter (is in the middle of the mandatory quotes)
 }
-
-void XmlPatch::displayJsException(QScriptEngine &engine, QScriptValue &engineResult){
-    if (engine.hasUncaughtException()) {
-        UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Uncaught js exception (user code) at line " +QString::number(engine.uncaughtExceptionLineNumber()) + ":\n" + engineResult.toString());
-    }
-}
