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