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