xsltproc.cpp
author insilmaril
Tue, 20 Jan 2009 15:23:16 +0000
changeset 735 84ae10f6e3a3
parent 677 3472b93efb0c
child 825 1ad892c1a709
permissions -rw-r--r--
More work on removing Selection class
     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"<<qPrintable(com)<<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 		{
    82 			QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
    83 			   QObject::tr("%1 didn't exit normally").arg(xsltprocessor) +
    84 			   xsltProc->getErrout() );
    85 			if (xsltProc->exitStatus()>0) showOutput=true;
    86 		}	   
    87 			
    88 	}	
    89 	dia.append ("\n");
    90 	dia.append (xsltProc->getErrout());
    91 	dia.append (xsltProc->getStdout());
    92 	
    93 	if (showOutput) dia.exec();
    94 }
    95