]> git.sven.stormbind.net Git - sven/vym.git/blob - xsltproc.cpp
0739fc0f9c69aa3204e864246cc7998f4da9dfef
[sven/vym.git] / xsltproc.cpp
1 #include "xsltproc.h"
2
3 #include <iostream>
4 #include <QDebug>
5 #include <QMessageBox>
6
7 #include "vymprocess.h"
8
9
10 extern bool debug;
11
12 XSLTProc::XSLTProc ()
13 {
14     xsltprocessor="xsltproc";
15     showOutput=false;
16     dia=new ShowTextDialog;
17 }
18
19 XSLTProc::~XSLTProc ()
20 {
21     delete (dia);
22 }
23
24 void XSLTProc::addStringParam (const QString & k, const QString &v)
25 {
26     stringParamKey.append (k);
27     stringParamVal.append (v);
28 }
29
30 void XSLTProc::setOutputFile    (const QString &s)
31 {
32     outputFile=s;
33 }
34
35 void XSLTProc::setXSLFile(const QString &s)
36 {
37     xslFile=s;
38 }
39
40 void XSLTProc::setInputFile     (const QString &s)
41 {
42     inputFile=s;
43 }
44
45 void XSLTProc::addOutput (const QString &s)
46 {
47     dia->append (s);
48 }
49
50 void XSLTProc::process()
51 {
52     ShowTextDialog dia;
53     dia.useFixedFont (true);
54     QStringList args;
55     VymProcess *xsltProc=new VymProcess ();
56
57     QStringList::Iterator itk;
58     QStringList::Iterator itv=stringParamVal.begin();
59
60     for ( itk = stringParamKey.begin(); itk != stringParamKey.end(); ++itk ) 
61     {
62         args << "--stringparam";
63         args << *itk;
64         args << *itv;
65         ++itv;
66     }
67     
68     args << "--output";
69     args << outputFile;
70     args << xslFile;
71     args << inputFile;
72     QString com=xsltprocessor+" "+args.join(" "); 
73     if (debug) qDebug() <<"xsltproc executing:\n"<<qPrintable(com);
74     dia.append ("vym is executing: \n" + com ); 
75     xsltProc->start(xsltprocessor,args);
76     if (!xsltProc->waitForStarted() )
77     {
78         QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
79                        QObject::tr("Could not start %1").arg(xsltprocessor) );
80     } else
81     {
82         if (!xsltProc->waitForFinished())
83         {
84             QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
85                QObject::tr("%1 didn't exit normally").arg(xsltprocessor) +
86                xsltProc->getErrout() );
87             if (xsltProc->exitStatus()>0) showOutput=true;
88         }      
89             
90     }   
91     dia.append ("\n");
92     dia.append (xsltProc->getErrout());
93     dia.append (xsltProc->getStdout());
94     
95     if (showOutput) dia.exec();
96 }
97