xsltproc.cpp
author insilmaril
Thu, 23 Mar 2006 12:38:54 +0000
changeset 258 42c8cf6dd1c3
parent 217 375be2baa976
child 265 96b8406d4a2f
permissions -rw-r--r--
Version 1.7.12
     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 	Process *xsltProc=new Process ();
    51 	xsltProc->clearArguments();
    52 	xsltProc->addArgument (xsltprocessor);	
    53 
    54 	QStringList::Iterator itk;
    55 	QStringList::Iterator itv=stringParamVal.begin();
    56 
    57 	for ( itk = stringParamKey.begin(); itk != stringParamKey.end(); ++itk ) 
    58 	{
    59 		xsltProc->addArgument ("--stringparam");
    60 		xsltProc->addArgument (*itk);
    61 		xsltProc->addArgument (*itv);
    62 		++itv;
    63     }
    64 	
    65 	xsltProc->addArgument ("--output");
    66 	xsltProc->addArgument (outputFile);
    67 	xsltProc->addArgument (xslFile);
    68 	xsltProc->addArgument (inputFile);
    69 	dia.append ("vym is executing: \n" + xsltProc->arguments().join(" ") );	
    70 	//FIXME testing
    71 	cout <<QString("vym is executing: \n" + xsltProc->arguments().join(" ")) <<endl;	
    72 	if (!xsltProc->start() )
    73 	{
    74 		QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
    75 					   QObject::tr("Could not start %1").arg(xsltprocessor) );
    76 	} else
    77 	{
    78 		xsltProc->waitFinished();
    79 		if (!xsltProc->normalExit() )
    80 			QMessageBox::critical( 0, QObject::tr( "Critical Error" ),
    81 			   QObject::tr("%1 didn't exit normally").arg(xsltprocessor) +
    82 			   xsltProc->getErrout() );
    83 		else
    84 			if (xsltProc->exitStatus()>0) showOutput=true;
    85 			
    86 	}	
    87 	dia.append ("\n");
    88 	dia.append (xsltProc->getErrout());
    89 	dia.append (xsltProc->getStdout());
    90 	
    91 	if (showOutput) dia.exec();
    92 }
    93