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