xsltproc.cpp
author insilmaril
Wed, 11 Apr 2007 09:21:16 +0000
changeset 455 1462e380b82b
parent 431 c2ffbc9b832d
child 518 07f35022646d
permissions -rw-r--r--
Updated documentation about macros
     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 	QString com=xsltprocessor+" "+args.join(" "); 
    69 	cout <<com.ascii()<<endl;
    70 	dia.append ("vym is executing: \n" + com );	
    71 	xsltProc->start(xsltprocessor,args);
    72 	if (!xsltProc->waitForStarted() )
    73 	{
    74 		QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
    75 					   QObject::tr("Could not start %1").arg(xsltprocessor) );
    76 	} else
    77 	{
    78 		if (!xsltProc->waitForFinished())
    79 			QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
    80 			   QObject::tr("%1 didn't exit normally").arg(xsltprocessor) +
    81 			   xsltProc->getErrout() );
    82 		else
    83 			if (xsltProc->exitStatus()>0) showOutput=true;
    84 			
    85 	}	
    86 	dia.append ("\n");
    87 	dia.append (xsltProc->getErrout());
    88 	dia.append (xsltProc->getStdout());
    89 	
    90 	if (showOutput) dia.exec();
    91 }
    92