author | insilmaril |
Mon, 05 May 2008 13:46:42 +0000 | |
changeset 689 | c7b1178aec77 |
parent 677 | 3472b93efb0c |
child 825 | 1ad892c1a709 |
permissions | -rw-r--r-- |
insilmaril@205 | 1 |
#include "xsltproc.h" |
insilmaril@205 | 2 |
|
insilmaril@205 | 3 |
#include <iostream> |
insilmaril@205 | 4 |
#include <qmessagebox.h> |
insilmaril@205 | 5 |
|
insilmaril@205 | 6 |
#include "process.h" |
insilmaril@205 | 7 |
|
insilmaril@205 | 8 |
|
insilmaril@518 | 9 |
extern bool debug; |
insilmaril@518 | 10 |
|
insilmaril@205 | 11 |
XSLTProc::XSLTProc () |
insilmaril@205 | 12 |
{ |
insilmaril@205 | 13 |
xsltprocessor="xsltproc"; |
insilmaril@205 | 14 |
showOutput=false; |
insilmaril@205 | 15 |
dia=new ShowTextDialog; |
insilmaril@205 | 16 |
} |
insilmaril@205 | 17 |
|
insilmaril@205 | 18 |
XSLTProc::~XSLTProc () |
insilmaril@205 | 19 |
{ |
insilmaril@205 | 20 |
delete (dia); |
insilmaril@205 | 21 |
} |
insilmaril@205 | 22 |
|
insilmaril@205 | 23 |
void XSLTProc::addStringParam (const QString & k, const QString &v) |
insilmaril@205 | 24 |
{ |
insilmaril@205 | 25 |
stringParamKey.append (k); |
insilmaril@205 | 26 |
stringParamVal.append (v); |
insilmaril@205 | 27 |
} |
insilmaril@205 | 28 |
|
insilmaril@205 | 29 |
void XSLTProc::setOutputFile (const QString &s) |
insilmaril@205 | 30 |
{ |
insilmaril@205 | 31 |
outputFile=s; |
insilmaril@205 | 32 |
} |
insilmaril@205 | 33 |
|
insilmaril@205 | 34 |
void XSLTProc::setXSLFile(const QString &s) |
insilmaril@205 | 35 |
{ |
insilmaril@205 | 36 |
xslFile=s; |
insilmaril@205 | 37 |
} |
insilmaril@205 | 38 |
|
insilmaril@205 | 39 |
void XSLTProc::setInputFile (const QString &s) |
insilmaril@205 | 40 |
{ |
insilmaril@205 | 41 |
inputFile=s; |
insilmaril@205 | 42 |
} |
insilmaril@205 | 43 |
|
insilmaril@205 | 44 |
void XSLTProc::addOutput (const QString &s) |
insilmaril@205 | 45 |
{ |
insilmaril@205 | 46 |
dia->append (s); |
insilmaril@205 | 47 |
} |
insilmaril@205 | 48 |
|
insilmaril@205 | 49 |
void XSLTProc::process() |
insilmaril@205 | 50 |
{ |
insilmaril@205 | 51 |
ShowTextDialog dia; |
insilmaril@408 | 52 |
QStringList args; |
insilmaril@205 | 53 |
Process *xsltProc=new Process (); |
insilmaril@205 | 54 |
|
insilmaril@205 | 55 |
QStringList::Iterator itk; |
insilmaril@205 | 56 |
QStringList::Iterator itv=stringParamVal.begin(); |
insilmaril@205 | 57 |
|
insilmaril@205 | 58 |
for ( itk = stringParamKey.begin(); itk != stringParamKey.end(); ++itk ) |
insilmaril@205 | 59 |
{ |
insilmaril@408 | 60 |
args << "--stringparam"; |
insilmaril@408 | 61 |
args << *itk; |
insilmaril@408 | 62 |
args << *itv; |
insilmaril@205 | 63 |
++itv; |
insilmaril@205 | 64 |
} |
insilmaril@205 | 65 |
|
insilmaril@408 | 66 |
args << "--output"; |
insilmaril@408 | 67 |
args << outputFile; |
insilmaril@408 | 68 |
args << xslFile; |
insilmaril@408 | 69 |
args << inputFile; |
insilmaril@430 | 70 |
QString com=xsltprocessor+" "+args.join(" "); |
insilmaril@660 | 71 |
if (debug) cout <<"xsltproc executing:\n"<<qPrintable(com)<<endl; |
insilmaril@430 | 72 |
dia.append ("vym is executing: \n" + com ); |
insilmaril@408 | 73 |
xsltProc->start(xsltprocessor,args); |
insilmaril@408 | 74 |
if (!xsltProc->waitForStarted() ) |
insilmaril@205 | 75 |
{ |
insilmaril@205 | 76 |
QMessageBox::critical( 0, QObject::tr( "Critical Error" ), |
insilmaril@205 | 77 |
QObject::tr("Could not start %1").arg(xsltprocessor) ); |
insilmaril@205 | 78 |
} else |
insilmaril@205 | 79 |
{ |
insilmaril@430 | 80 |
if (!xsltProc->waitForFinished()) |
insilmaril@677 | 81 |
{ |
insilmaril@205 | 82 |
QMessageBox::critical( 0, QObject::tr( "Critical Error" ), |
insilmaril@205 | 83 |
QObject::tr("%1 didn't exit normally").arg(xsltprocessor) + |
insilmaril@205 | 84 |
xsltProc->getErrout() ); |
insilmaril@205 | 85 |
if (xsltProc->exitStatus()>0) showOutput=true; |
insilmaril@677 | 86 |
} |
insilmaril@205 | 87 |
|
insilmaril@205 | 88 |
} |
insilmaril@205 | 89 |
dia.append ("\n"); |
insilmaril@205 | 90 |
dia.append (xsltProc->getErrout()); |
insilmaril@205 | 91 |
dia.append (xsltProc->getStdout()); |
insilmaril@205 | 92 |
|
insilmaril@205 | 93 |
if (showOutput) dia.exec(); |
insilmaril@205 | 94 |
} |
insilmaril@205 | 95 |