cvs: pear /XML_XSLT_Wrapper/Backend DOM_XSL.php MSXSL_Com.php Sablotron.php XSLT_ext.php XT.php

From: Date: Tue, 01 Oct 2002 11:00:14 +0000
Subject: cvs: pear /XML_XSLT_Wrapper/Backend DOM_XSL.php MSXSL_Com.php Sablotron.php XSLT_ext.php XT.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-6792@lists.php.net to get a copy of this message
pajoye Tue Oct 1 07:00:14 2002 EDT Added files: /pear/XML_XSLT_Wrapper/Backend DOM_XSL.php MSXSL_Com.php Sablotron.php XSLT_ext.php XT.php Log: Initial commit

Index: pear/XML_XSLT_Wrapper/Backend/DOM_XSL.php +++ pear/XML_XSLT_Wrapper/Backend/DOM_XSL.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <pajoye@pearfr.org> | // +----------------------------------------------------------------------+ // // $Id: DOM_XSL.php,v 1.1 2002/10/01 11:00:14 pajoye Exp $ // class XML_XSLT_Backend_DOM_XSL extends XML_XSLT_Common{ /** * _oXML * * object DOM XML object * @access privat */ var $_oXML; /** * _oXSL * * object DOM XSL object * @access privat */ var $_oXSL; // {{{ Backend_DOM_XSL /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return */ function XML_XSLT_Backend_DOM_XSL (){ if (!function_exists('domxml_xslt_stylesheet')) { if (!PEAR::loadExtension('domxsl')) { return PEAR::raiseError(null, XML_XSLT_ERROR_BACKEND_FAILED, null, null, null, 'XML_XSLT_Error', true); } } } // }}} // {{{ _buildParams /** * Set the parameters for the active XSL sheet * * @access public * @return mixed return * @see backend */ function _buildParams(){ // does not need to build them return true; } // }}} // {{{ _initXSL /** * Set the parameters for XSLT * * @access public * @return mixed return * @see backend */ function _initXSL(){ switch( $this->XSL_Mode ){ case XML_XSLT_MODE_STRING: $this->_oXSL = @domxml_xslt_stylesheet($this->xslt); break; case XML_XSLT_MODE_FILE: $this->_oXSL = @domxml_xslt_stylesheet_file($this->xslt); break; case XML_XSLT_MODE_URI: $xslt = $this->getURIContent($this->xslt); $this->_oXSL = @domxml_xslt_stylesheet($this->xslt); break; } if( ! $this->_oXSL ){ return PEAR::raiseError(null, XML_XSLT_ERROR_LOADXSL_FAILED, null, null, null, 'XML_XSLT_Error', true); return false; } $this->_initXSL_Done = true; return true; } // }}} // {{{ _initXML /** * Set the parameters for the active XSL sheet * * @access public * @return mixed return * @see backend */ function _initXML(){ switch( $this->XML_Mode ){ case XML_XSLT_MODE_STRING: $this->_oXML = @domxml_open_mem($this->xml); break; case XML_XSLT_MODE_FILE: $this->_oXML = @domxml_open_file($this->xml); break; case XML_XSLT_MODE_URI: $xml = $this->getURIContent($this->xml); $this->_oXML = @domxml_open_mem($xml); break; } if( !$this->_oXML ){ return PEAR::raiseError(null, XML_XSLT_ERROR_XMLPARSER_ERROR, null, null, 'XSL File:'.$data, 'XML_XSLT_Error', true); return false; } $this->_initXML_Done = true; return true; } // }}} // {{{ process /** * Set the parameters for the active XSL sheet * * @access public * @return mixed return * @see backend */ function process(){ if(!$this->error_code){ if( !$this->_initXSL_Done ){ if(!$this->_initXSL()){ return false; } } if( !$this->_initXML_Done ){ if(!$this->_initXML() ){ return false; } } if( is_array($this->params) ){ $this->result = $this->_oXSL->process( $this->_oXML, $this->params); } else { $this->result = $this->_oXSL->process($this->_oXML); } if( !$this->result ){ return PEAR::raiseError(null, XML_XSLT_ERROR_PROCESS_FAILED, null, null, 'XSL File:'.$data, 'XML_XSLT_Error', true); return false; } } return true; } // }}} // {{{ ResultDumpOut /** * Set the parameters for the active XSL sheet * * @param boolean $free Free the ressources * after transformation * * @access public * @return mixed return * @see backend */ function ResultDumpOut($free=true){ if(!$this->error_code && $this->_initXSL_Done && $this->_initXML_Done){ if ( $this->outputEncoding!='' ){ echo $this->result->dump_mem(true,$this->outputEncoding); } else { echo $this->result->dump_mem(true); } return true; } return false; } // }}} // {{{ ResultDumpMem /** * Set the parameters for the active XSL sheet * * @param boolean $free Free the ressources * after transformation * * @access public * @return mixed return * @see backend */ function ResultDumpMem($free=true){ if(!$this->error_code && $this->_initXSL_Done && $this->_initXML_Done){ if ( $this->outputEncoding!='' ){ return $this->result->dump_mem(true,$this->outputEncoding); } else { return $this->result->dump_mem(true); } } else { return ''; } } // }}} // {{{ ResultDumpFile /** * Set the parameters for the active XSL sheet * * @param boolean $free Free the ressources * after transformation * * @access public * @return mixed return * @see backend */ function ResultDumpFile($output_file='', $free=true){ $return = false; if(!$this->error_code && $this->_initXSL_Done && $this->_initXML_Done){ if( $output_file==''){ $output_file = $this->outputFile; } if(!$this->error_code){ if( $this->result->dump_file($output_file,false) ){ $result = true; } } } return $result; } // }}} // {{{ batchXML /** * Transform single XML data with multiple XSL files * * @access public * @return mixed return * @ */ function batchXML($options=null){ if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, ' missing XML data', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = new XML_XSLT_Error (null, XML_XSLT_ERROR_MISSEDDIR_FAILED, E_USER_ERROR); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xml'])){ $mode = $options['xml'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if (!$this->setXML($options['xml'],$mode)){ $this->error = new XML_XSLT_Error (null, XML_XSLT_ERROR_XML_EMPTY, E_USER_ERROR); return false; } $this->_initXML(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XML_EMPTY, null, null, ' missing XML data', $this->error_class, true ); } if(isset($options['xslt_files']) && is_array($options['xslt_files'])){ $xsl_files = $options['xslt_files']; $xslt_args = ''; foreach($xsl_files as $xslt_file=>$xslt){ if( $this->setXSL($xslt['filepath'],XML_XSLT_MODE_FILE) ){ $this->_initXSL(); $this->process(); $this->ResultDumpFile($dest_dir.'/'.$xslt['outputfile'],false); } else { return false; } } } $this->free(); return true; } // }}} // {{{ batchXSL /** * Transform multiple XML data with a single XSL files * * @access public * @return mixed return * @ */ function batchXSL($options=null){ if(is_null($options)){ return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = new XML_XSLT_Error (null, XML_XSLT_ERROR_MISSEDDIR_FAILED, E_USER_ERROR); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xslt'])){ if (!$this->setXSL($options['xslt'],XML_XSLT_MODE_FILE)){ return false; } $this->_initXSL(); } if(isset($options['xml_datas']) && is_array($options['xml_datas'])){ $xml_files = $options['xml_datas']; $xml_args = ''; foreach($xml_files as $xml_file=>$xml){ $mode = $xml['data'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; $this->setXML($xml['data'],$mode); $this->_initXML(); $this->process(); $this->ResultDumpFile($dest_dir.'/'.$xml['outputfile'],false); } } $this->free(); return true; } // }}} // {{{ free /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return * @ */ function free(){ unset($this->_oXML); unset($this->_oXSL); } // }}} } /* * Local Variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * End: */ ?> Index: pear/XML_XSLT_Wrapper/Backend/MSXSL_Com.php +++ pear/XML_XSLT_Wrapper/Backend/MSXSL_Com.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <pajoye@pearfr.org> | // +----------------------------------------------------------------------+ // // $Id: MSXSL_Com.php,v 1.1 2002/10/01 11:00:14 pajoye Exp $ // /** * MSXML2 implemention * * @package XSLT_Wrapper * @author Pierre-Alain Joye <pajoye@pearfr.org> */ class XML_XSLT_Backend_MSXSL_Com extends XML_XSLT_Common{ /** * _xsldom * * ressource XSL sheet DOM document object * @access privat */ var $_xsldom; /** * _xmldom * * ressource XML sheet DOM document object * @access privat */ var $_xmldom; /** * _xslt * * ressource MSXML2.XSLTemplate Object * @access privat */ var $_xsltcom; // {{{ Backend_MSXSL_Com /** * Constructor * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function XML_XSLT_Backend_MSXSL_Com (){ if ( !(OS_WINDOWS && $this->_xsltcom = new COM("MSXML2.XSLTemplate.4.0")) ){ return PEAR::raiseError(null, XML_XSLT_ERROR_BACKEND_FAILED, null, null, 'You need the COM extension to run this Backend', 'XML_XSLT_Error', true); } } // }}} // {{{ buildParams /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access privat * @see backend */ function _buildParams(){ $arg_params = ''; if( !is_null($this->params) ){ $parms = $this->params; foreach($parms as $name=>$value){ $this->xslproc->addParameter($name, $value); } } } // }}} // {{{ _loadDOM /** * Set the xml data from a file or a string variable * * @access privat * @return mixed return * @ */ function &_loadDOM( $data,$mode ){ $dom = new COM("MSXML2.FreeThreadedDOMDocument.4.0"); if($mode==XML_XSLT_MODE_STRING){ $result=$dom->loadXML($data); if (!$dom->loadXML($data)){ $this->_error($dom); $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSMPARSER_ERROR, null, null, 'Error: '.$this->error_code .':'. $this->error_message, $this->error_class, true ); return null; } }else{ if (!$dom->load($data)){ $this->_error($dom); $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XMLPARSER_ERROR, null, null, 'Error: '.$this->error_code .':'. $this->error_message, $this->error_class, true ); return null; } } return $dom; } // }}} // {{{ _initXSL /** * Set the XSLT sheet * * @access public * @return mixed return * @see backend */ function _initXSL(){ if($this->_xsldom = $this->_loadDOM($this->xslt,$this->XSL_Mode)){ $this->_xsldom->async = false; $this->_initXSL_Done = true; return true; } else { $this->_initXSL_Done = false; return false; } } // }}} // {{{ _initXML /** * Set the XML DATA * * * @access public * @return mixed return * @see backend */ function _initXML(){ if($this->_xmldom = $this->_loadDOM($this->xml,$this->XML_Mode)){ $this->_xmldom->async = false; $this->_initXML_Done = true; return true; } else { $this->_initXSL_Done = false; return null; } } // }}} // {{{ process /** * Do the transformation and store the result * to the result property * * @param string $backend name of the backend * @access public * @return mixed return */ function process(){ if( !$this->_initXSL_Done ){ if(!$this->_initXSL()){ return false; } } if( !$this->_initXML_Done ){ if(!$this->_initXML() ){ return false; } } if(is_null($this->params)){ $this->result = $xmldoc->transformNode($this->_xsldom); } else { $this->_xsltcom->stylesheet = $this->_xsldom; $this->xslproc = $this->_xsltcom->createProcessor(); $this->xslproc->input = $this->_xmldom; $this->_buildParams(); if($this->xslproc->transform()){ $this->result = $this->xslproc->output; return true; } else { $this->_error($this->xslproc); $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLPARSER_ERROR, null, null, 'Error: '.$this->error_code .':'. $this->error_message, $this->error_class, true ); return false; } } } // }}} // {{{ ResultDumpMem /** * Return the transformation result * * @param boolean $free Free the ressources or not * after the transformation * * @access public * @return mixed return * @see backend */ function ResultDumpMem($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ if($free){ $this->free(); } return $this->result; } else { return ''; } } // }}} // {{{ ResultDumpFile /** * Dumps the transformation result to a file * * @param boolean $free Free the ressources or not * after the transformation * @access public * @return mixed return * @see backend */ function ResultDumpFile($output_file='',$free=true){ $result = $this->_saveResult($output_file); if($free){ $this->free(); } return $result; } // }}} // {{{ saveResult /** * Dumps the transformation result to stdout * * @param boolean $free Free the ressources or not * after the transformation * * @access public * @return mixed return * @see backend */ function ResultDumpOut($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ echo $this->result; if($free){ $this->free(); } return true; } else { return false; } } // }}} // {{{ batchXML /** * Transform single XML data with multiple XSL files * * @access public * @return mixed return * @ */ function batchXML($options=null){ $error = false; if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, 'missing options', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xml'])){ $xmldoc = new COM("Msxml2.DOMDocument.4.0"); if($options['xml'][0]=='<'){ $mode = XML_XSLT_MODE_STRING; $xmldoc->loadXML($options['xml']); }else{ $mode = XML_XSLT_MODE_FILE; $xmldoc->load($options['xml']); } $xmldoc->async = false; if ($xmldoc->parseError->errorCode){ $this->_error($xmldoc); return false; } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XML_EMPTY, null, null, ' missing XML data', $this->error_class, true ); } if(isset($options['xslt_files']) && is_array($options['xslt_files'])){ $xsl_files = $options['xslt_files']; $xslt_args = ''; foreach($xsl_files as $xslt_file=>$xslt){ $xsldoc = new COM("Msxml2.FreeThreadedDOMDocument.4.0"); $xsldoc->async = false; $xsldoc->load($xslt['filepath']); if ($xsldoc->parseError->errorCode){ $this->_error($xsldoc); $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, $this->error_message, $this->error_class, true ); return false; } $this->result = $xmldoc->transformNode($xsldoc); $this->ResultDumpFile($dest_dir.'/'.$xslt['outputfile'],false); } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSL_EMPTY, null, null, 'Missing XSL data', $this->error_class, true ); return false; } $this->free(); return true; } // }}} // {{{ batchXSL /** * Transform multiple XML data with a single XSL files * * @access public * @return mixed return * @ */ function batchXSL($options=null){ $error = false; if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, 'missing options', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xslt'])){ $xsldoc = new COM("Msxml2.DOMDocument.4.0"); $xsldoc->async = false; if($options['xslt'][0]=='<'){ $xsldoc->loadXML($options['xslt']); } else { $xsldoc->load($options['xslt']); } } if(isset($options['xml_datas']) && is_array($options['xml_datas'])){ $xml_files = $options['xml_datas']; $xml_args = ''; foreach($xml_files as $xml_file=>$xml){ $xmldoc = new COM("Msxml2.DOMDocument.4.0"); $xmldoc->async = false; if($xml['data'][0]=='<'){ $xmldoc->loadXML($xml['data']); } else { $xmldoc->load($xml['data']); } if (!$this->result = $xmldoc->transformNode($xsldoc)){ $this->_error($xmldoc); return false; } $this->ResultDumpFile($dest_dir.'/'.$xml['outputfile'],false); } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSL_EMPTY, null, null, 'Missed XML data', $this->error_class, true ); return false; } $this->free(); return true; } // }}} // {{{ _error /** * return an error object build from xml error * * @access _privat * @return mixed return * @see backend */ function _error( &$domxml ){ $msg = 'Error Code:' . $domxml->parseError->errorCode."\n"; $msg .= 'Reason: ' . $domxml->parseError->reason.""; $msg .= 'URL: ' . $domxml->parseError->url."\n"; $msg .= 'Line: ' . $domxml->parseError->line."\n"; $msg .= 'Col: ' . $domxml->parseError->linepos."\n"; $msg .= 'File Pos:' . $domxml->parseError->filepos."\n"; $msg .= 'Src Text: ' . $domxml->parseError->srcText; $this->error_message = $msg; $this->error_code = $domxml->parseError->errorCode; } // }}} // {{{ free /** * Free all ressources * * @access public * @return mixed return */ function free(){ unset($this->_xsltcom); unset($this->_xmlcom); unset($this->xslproc); } // }}} } /* * Local Variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * End: */ ?> Index: pear/XML_XSLT_Wrapper/Backend/Sablotron.php +++ pear/XML_XSLT_Wrapper/Backend/Sablotron.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <pajoye@pearfr.org> | // +----------------------------------------------------------------------+ // // $Id: Sablotron.php,v 1.1 2002/10/01 11:00:14 pajoye Exp $ // class XML_XSLT_Backend_Sablotron extends XML_XSLT_Common{ /** * _hXSLT * * object DOM XML object * @access privat */ var $_hXSLT; /** * _XML * * string filepath or 'arg:' format * @access privat */ var $_XML; /** * _XSL * * string filepath or 'arg:' format * @access privat */ var $_XSL; // {{{ Backend_Saxon /** * Constructor * * @access public * @return mixed return * @see backend */ function XML_XSLT_Backend_Sablotron (){ if(!defined( 'XSLT_SAXON_CMD' )){ include_once 'System/Command.php'; $cmd = escapeshellcmd(System_Command::which('sabcmd')); if($cmd!=''){ define('XSLT_SAXON_CMD', $cmd); } else { return PEAR::raiseError(); } } $this->console_mode = true; } // }}} // {{{ _buildParams /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access privat * @return mixed return * @see backend */ function _buildParams(){ $arg_params = ''; if( !is_null($this->params) ){ $parms = $this->params; foreach($parms as $name=>$value){ if(is_string($value)){ $value = "'".escapeshellcmd($value)."'"; } $arg_params .= '$'.$name."=$value "; } } return $arg_params; } // }}} // {{{ initXSL /** * Set the XSLT data * * @access public * @return mixed return * @see backend */ function initXSL(){ switch( $this->XSL_Mode ){ case XML_XSLT_MODE_STRING: $this->_arguments['/_xsl'] = $this->xslt; $this->arg_xsl = 'arg:/_xsl'; break; case XML_XSLT_MODE_FILE: $this->arg_xsl = $this->xslt; if ( isset($this->_arguments['_xsl']) ){ unset($this->_arguments['_xsl']); } break; case XML_XSLT_MODE_URI: $this->arg_xsl = $this->xslt; if ( isset($this->_arguments['_xsl']) ){ unset($this->_arguments['_xsl']); } break; default: $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_UNKNOWN_MODE, null, null, 'Unknown XSL mode', $this->error_class, true ); return false; } $this->_initXSL_Done = true; return true; } // }}} // {{{ initXML /** * Set the XML DATA * * * @access public * @return mixed return * @see backend */ function initXML(){ switch( $this->XML_Mode ){ case XML_XSLT_MODE_STRING: $this->arg_xml = $this->_saveTempData($this->xml); break; case XML_XSLT_MODE_FILE: $this->arg_xml = $this->xml; break; case XML_XSLT_MODE_URI: $this->arg_xml = $this->xml; break; default: $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_UNKNOWN_MODE, null, null, 'Unknown XML mode', $this->error_class, true ); return false; } $this->_initXML_Done = true; return true; } // }}} // {{{ process /** * Do nothing with this backend, all process * and ouputs are done in ResultDumpXXXX methods * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function process(){ if(!$this->_initXML_Done){ if ( !$this->initXML() ){ return false; } } if( !$this->_initXSL_Done){ if ( !$this->initXSL() ){ return false; } } return true; } // }}} // {{{ ResultDumpMem /** * Return the result of the transformation * * @param boolean $free Free the ressources * after the transformation * * @access public * @return mixed return */ function ResultDumpMem($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ exec( XSLT_SAXON_CMD.' '.$this->xslt.' '.' '.$this->arg_xml.' '. " '".$this->_buildParams()."'", $result,$return_code ); if($free){ $this->free(); } if($return_code==0){ return( implode("\n",$result) ); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code, $this->error_class, true ); return ''; } } else { return ''; } } // }}} // {{{ ResultDumpFile /** * Dump the result of the transformation to a file * * @param string $outputFile output filepath * * @param boolean $free Free the ressources * after the transformation * * @access public * @return mixed return */ function ResultDumpFile($outputFile='',$free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ if($outputFile==''){ $outputFile = escapeshellarg('pxslt_'.time()); } exec( XSLT_SAXON_CMD.' '.$this->xslt ." " . $this->arg_xml . " '".$this->_buildParams()."' >".$outputFile, $messages,$return_code ); if($free){ $this->free(); } if($return_code==0){ return $outputFile; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code, $this->error_class, true ); return false; } } else { return false; } } // }}} // {{{ ResultDumpOut /** * Dumps the result of the transformation to stdout * * @param boolean $free Free the ressources or not * after the transformation * * @access public * @return mixed return */ function ResultDumpOut($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ if( $this->XML_Mode==XML_XSLT_MODE_STRING ){ $command_pipe = popen ("sabcmd ". $this->xslt ." ".'file://stdin $numberofcols=3',"w"); fwrite ($command_pipe,$this->xml); pclose ($command_pipe); } else { passthru( XSLT_SAXON_CMD.' '. $this->xslt ." " . $this->xml . " '".$this->_buildParams()."' " ); } if($free){ $this->free(); } return true; } else { return false; } } // }}} // {{{ batchXML /** * Transform single XML data with multiple XSL files * * @access public * @return mixed return * @ */ function batchXML($options=null){ if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, ' missing XML data', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xml'])){ $mode = $options['xml'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if (!$this->setXML($options['xml'],$mode)){ return false; } $this->initXML(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XML_EMPTY, null, null, ' missing XML data', $this->error_class, true ); return false; } if(isset($options['xslt_files']) && is_array($options['xslt_files'])){ $xsl_files = $options['xslt_files']; $xslt_args = ''; foreach($xsl_files as $xslt_file=>$xslt){ $xslt_args .= ' '.escapeshellarg($xslt['filepath']) . ' '. $dest_dir.$xslt['outputfile']; } exec( XSLT_SAXON_CMD.' -x '.$this->arg_xml ." " . $xslt_args . " '".$this->_buildParams()."' ", $messages,$return_code ); } $this->free(); if($return_code==0){ return true; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code, $this->error_class, true ); return false; } } // }}} // {{{ batchXSL /** * Transform multiple XML data with a single XSL files * * @access public * @return mixed return * @ */ function batchXSL($options=null){ if(is_null($options)){ return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xslt'])){ if (!$this->setXSL($options['xslt'],XML_XSLT_MODE_FILE)){ return false; } $this->initXSL(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSL_EMPTY, null, null, 'missing XSL data in batchXSL', $this->error_class, true ); return false; } if(isset($options['xml_datas']) && is_array($options['xml_datas'])){ $xml_files = $options['xml_datas']; $xml_args = ''; foreach($xml_files as $xml_file=>$xml){ $mode = $xml['data'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if($xml['data'][0]=='<'){ $xmlfile = $this->_saveTempData($xml['data']); } else { $xmlfile = $xml['data']; } $xml_args .= ' '.escapeshellarg($xmlfile) . ' '. $dest_dir.$xml['outputfile']; } exec( XSLT_SAXON_CMD.' -s '.$this->arg_xsl ." " . $xml_args . " '".$this->_buildParams()."' ", $messages,$return_code ); } $this->free(); if($return_code==0){ return true; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code, $this->error_class, true ); return false; } } // }}} // {{{ free /** * Free all ressources * * @access public * @return mixed return * @ */ function free(){ $this->_removeTempData(); } // }}} } /* * Local Variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * End: */ ?> Index: pear/XML_XSLT_Wrapper/Backend/XSLT_ext.php +++ pear/XML_XSLT_Wrapper/Backend/XSLT_ext.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <pajoye@pearfr.org> | // +----------------------------------------------------------------------+ // // $Id: XSLT_ext.php,v 1.1 2002/10/01 11:00:14 pajoye Exp $ // class XML_XSLT_Backend_XSLT_ext extends XML_XSLT_Common{ /** * _hXSLT * * object DOM XML object * @access privat */ var $_hXSLT; /** * _XML * * string filepath or 'arg:' format * @access privat */ var $_XML; /** * _arguments * * string filepath or 'arg:' format * @access privat */ var $_arguments=null; /** * _XSL * * string filepath or 'arg:' format * @access privat */ var $_XSL; /** * _XSL * * string filepath or 'arg:' format * @access privat */ var $nativeErrorCode; // {{{ Backend_XSLT_ext /** * Constructor * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function Backend_XSLT_ext (){ if (!function_exists('xslt_create')) { include_once('PEAR.php'); if (!PEAR::loadExtension('xslt')) { return PEAR::raiseError( 'The xslt extension can not be found.', true ); } } } // }}} // {{{ buildParams /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function buildParams(){ // do not need to build them } // }}} // {{{ initXSL /** * Set the XSLT data * * @access public * @return mixed return */ function _initXSL(){ if( $this->hXSLT = xslt_create() ){ switch( $this->XSL_Mode ){ case XML_XSLT_MODE_STRING: $this->_arguments['/_xsl'] = &$this->xslt; $this->arg_xsl = 'arg:/_xsl'; break; case XML_XSLT_MODE_FILE: $this->arg_xsl = $this->xslt; if ( isset($this->_arguments['_xsl']) ){ unset($this->_arguments['_xsl']); } break; case XML_XSLT_MODE_URI: $this->arg_xsl = $this->xslt; if ( isset($this->_arguments['_xsl']) ){ unset($this->_arguments['_xsl']); } break; default: return false; } $this->_initXSL_Done = true; return true; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLPARSER_ERROR, null, null, 'Error: '.xslt_errno($this->_oXSL).':'. xslt_error($this->_oXSL), $this->error_class, true); return false; } } // }}} // {{{ initXML /** * Set the XML DATA * * * @access public * @return mixed return * @see backend */ function _initXML(){ switch( $this->XML_Mode ){ case XML_XSLT_MODE_STRING: $this->_arguments['/_xml'] = &$this->xml; $this->arg_xml = 'arg:/_xml'; break; case XML_XSLT_MODE_FILE: $this->arg_xml = $this->xml; if ( isset($this->_arguments['_xml']) ){ unset($this->_arguments['_xml']); } break; case XML_XSLT_MODE_URI: $this->arg_xml = $this->xml; if ( isset($this->_arguments['_xml']) ){ unset($this->_arguments['_xml']); } break; default: $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_UNKNOWN_MODE, null, null, 'Unknown mode', $this->error_class, true ); return false; } $this->_initXML_Done = true; return true; } // }}} // {{{ process /** * Do nothing with this backend, all process * and ouputs are done in ResultDumpXXXX methods * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function process(){ if( !$this->_initXSL_Done ){ if(!$this->_initXSL()){ return false; } } if( !$this->_initXML_Done ){ if(!$this->_initXML() ){ return false; } } return true; } // }}} // {{{ ResultDumpOut /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function ResultDumpOut($free=true){ $error = false; if($this->_initXSL_Done && $this->_initXSL_Done){ if($this->error_code==0){ $args = isset($this->_arguments)&&sizeof($this->_arguments)?$this->_arguments:array(); if( $this->result=xslt_process($this->hXSLT, $this->arg_xml, $this->arg_xsl, null, $args, $this->params) ){ echo $this->result; if($free){ $this->free(); } } else { $error = true; $error_code = XML_XSLT_ERROR_XSLEXEC_ERROR; $error_user = xslt_errno($this->_oXSL). ': '.xslt_error($this->_oXSL); } } } if( $error ){ $this->error = PEAR::raiseError(null, $error_code, null, null, $error_user, $this->error_class, true ); return false; } else { return true; } } // }}} // {{{ dumpResult /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function ResultDumpMem($free=true){ $result = ''; if($this->_initXSL_Done && $this->_initXSL_Done){ if($this->error_code==0){ $args = isset($this->_arguments)&&sizeof($this->_arguments)? $this->_arguments:array(); $result = @xslt_process($this->hXSLT, $this->arg_xml, $this->arg_xsl, null, $args, $this->params); if ($result){ if($free){ $this->free(); } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, xslt_errno($this->_oXSL). ': '.xslt_error($this->_oXSL), $this->error_class, true ); } } } return $result; } // }}} // {{{ saveResult /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function ResultDumpFile($output_file='',$free=true){ $error = false; if($this->_initXSL_Done && $this->_initXSL_Done){ if($this->error_code==0){ if( $output_file=='' ){ $output_file = $this->outputFile; } $args = isset($this->_arguments)&&sizeof($this->_arguments)? $this->_arguments:array(); $params = isset($this->params)&&sizeof($this->params)? $this->params:array(); $result = xslt_process($this->hXSLT, $this->arg_xml, $this->arg_xsl, $output_file, $args, $params); if( !$result ){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, xslt_errno($this->hXSLT). ': '.xslt_error($this->hXSLT), $this->error_class, true ); $error = true; } if($free){ $this->free(); } } } return !$error; } // }}} // {{{ batchXML /** * Transform single XML data with multiple XSL files * * TODO Add errors in the loop process * * @access public * @return mixed return * @ */ function batchXML($options=null){ $error = false; if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, ' missing XML data', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xml'])){ $mode = $options['xml'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if (!$this->setXML($options['xml'],$mode)){ return false; } $this->_initXML(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XML_EMPTY, null, null, ' missing XML data', $this->error_class, true ); } if(isset($options['xslt_files']) && is_array($options['xslt_files'])){ $xsl_files = $options['xslt_files']; $xslt_args = ''; foreach($xsl_files as $xslt_file=>$xslt){ if ( !$this->setXSL($xslt['filepath'],XML_XSLT_MODE_FILE) ){ $error = true; break; } if ( !$this->_initXSL() ){ $error = true; break; } if ( !$this->process() ){ $error = true; break; } if ( !$this->ResultDumpFile($dest_dir.''.$xslt['outputfile'],false) ){ $error = true; break; } } } // TODO Add error if xslt_files missing $this->free(); return !$error; } // }}} // {{{ batchXSL /** * Transform multiple XML data with a single XSL files * * TODO Add errors in the loop process * * @access public * @return mixed return * @ */ function batchXSL($options){ $error = false; if(is_null($options)){ return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xslt'])){ if ( !$this->setXSL($options['xslt'],XML_XSLT_MODE_FILE) ){ return false; } if ( !$this->_initXSL() ){ return false; } } if(isset($options['xml_datas']) && is_array($options['xml_datas'])){ $xml_files = $options['xml_datas']; $xml_args = ''; foreach($xml_files as $xml_file=>$xml){ $mode = $xml['data'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if ( !$this->setXML($xml['data'],$mode) ){ $error = true; break; } if ( !$this->_initXML() ){ $error = true; break; } if ( !$this->process() ){ $error = true; break; } if( !$this->ResultDumpFile($dest_dir.'/'.$xml['outputfile'],false) ){ $error = true; break; } } } // TODO Add error if xml_datas missing return !$error; } // }}} // {{{ free /** * Free all ressources * * @param string $backend name of the backend * @access public * @return mixed return * @ */ function free(){ xslt_free($this->hXSLT); } // }}} } /* * Local Variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * End: */ ?> Index: pear/XML_XSLT_Wrapper/Backend/XT.php +++ pear/XML_XSLT_Wrapper/Backend/XT.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <pajoye@pearfr.org> | // +----------------------------------------------------------------------+ // // $Id: XT.php,v 1.1 2002/10/01 11:00:14 pajoye Exp $ // class XML_XSLT_Backend_XT extends XML_XSLT_Common{ /** * _arguments * * string arguments console string format * @access privat */ var $_arguments=null; /** * _XSL * * string filepath or 'arg:' format * @access privat */ var $_XSL; /** * _arg_xsl * * string filepath to the xsl file * @access privat */ var $_arg_xsl; /** * _arg_xml * * string filepath to the xml file * @access privat */ var $_arg_xml; // {{{ Backend_XT /** * Constructor * * @access public * @return mixed return * @see backend */ function Backend_XT (){ if(!defined( 'XSLT_XT_CMD' )){ include_once 'System/Command.php'; $ext = OS_WINDOWS?'.bat':'.sh'; $cmd = escapeshellcmd(System_Command::which('xt'.$ext)); if($cmd!=''){ define('XSLT_XT_CMD', $cmd); } else { return PEAR::raiseError(); } } $this->console_mode = true; } // }}} // {{{ _buildParams /** * Set the parameters for the active XSL sheet * * @param string $backend name of the backend * @access privat * @return mixed return * @see backend */ function _buildParams(){ $arg_params = ''; if( !is_null($this->params) ){ $parms = $this->params; foreach($parms as $name=>$value){ if(is_string($value)){ $value = "'".escapeshellcmd($value)."'"; } else { if( is_numeric($value) ){ $arg_params .= $name."=".$value; } } } } return $arg_params; } // }}} // {{{ initXSL /** * Set the XSLT data * * @access public * @return mixed return * @see backend */ function initXSL(){ switch( $this->XSL_Mode ){ case XML_XSLT_MODE_STRING: $this->_arg_xsl = $this->_saveTempData($this->xsl); break; case XML_XSLT_MODE_FILE: $this->_arg_xsl = $this->xslt; break; case XML_XSLT_MODE_URI: $this->_arg_xsl = $this->xslt; break; default: $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_UNKNOWN_MODE, null, null, 'Unknown XSL mode', $this->error_class, true ); return false; return false; } $this->_initXSL_Done = true; return true; } // }}} // {{{ initXML /** * Set the XML DATA * * * @access public * @return mixed return * @see backend */ function initXML(){ switch( $this->XML_Mode ){ case XML_XSLT_MODE_STRING: $this->_arg_xml = $this->_saveTempData($this->xml); break; case XML_XSLT_MODE_FILE: $this->_arg_xml = $this->xml; break; case XML_XSLT_MODE_URI: $$this->_arg_xml = $this->xml; break; default: $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_UNKNOWN_MODE, null, null, 'Unknown XML mode', $this->error_class, true ); return false; return false; } $this->_initXML_Done = true; return true; } // }}} // {{{ process /** * Do nothing with this backend, all process * and ouputs are done in ResultDumpXXXX methods * * @param string $backend name of the backend * @access public * @return mixed return * @see backend */ function process(){ if(!$this->_initXML_Done){ if ( !$this->initXML() ){ return false; } } if(!$this->_initXSL_Done){ if( !$this->initXSL() ){ return false; } } return true; } // }}} // {{{ ResultDumpMem /** * Return the result of the transformation * * @param boolean $free Free the ressources * after the transformation * * @access public * @return mixed return */ /* exec( XSLT_XT_CMD.' '. $this->_arg_xml ." " . $this->_arg_xsl . " '".$this->_buildParams()."'", $result,$return_code); */ function ResultDumpMem($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ exec( XSLT_XT_CMD.' '. $this->_arg_xml ." " . $this->_arg_xsl . " '".$this->_buildParams()."'", $result,$return_code); if($free){ $this->free(); } if (is_array($result)){ $string_result = implode("\n",$result); } else { $string_result = $result; } if($return_code==0 && is_string($string_result) && $string_result>0 ){ return $string_result; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code. ' '.$string_result, $this->error_class, true ); return false; } } else { return false; } } // }}} // {{{ ResultDumpFile /** * Dump the result of the transformation to a file * * @param boolean $free Free the ressources * after the transformation * @access public * @return mixed return */ function ResultDumpFile($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ system( XSLT_XT_CMD.' '.$this->_arg_xml.' '.$this->_arg_xsl. " '".$this->_buildParams()."' >".$this->outputFile, $messages,$return_code ); if($free){ $this->free(); } if($return_code==0 ){ return true; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code. ' '.$messages, $this->error_class, true ); return false; } } else { return false; } } // }}} // {{{ ResultDumpOut /** * Dumps the result of the transformation to stdout * * @param boolean $free Free the ressources or not * after the transformation * * @access public * @return mixed return */ function ResultDumpOut($free=true){ if($this->_initXSL_Done && $this->_initXSL_Done){ passthru( XSLT_XT_CMD.' '.$this->_arg_xml.' '.$this->_arg_xsl .' '. $this->_buildParams() ); if($free){ $this->free(); } } else { return false; } } // }}} // {{{ batchXML /** * Transform one single XML data with multiple XSL files * * @access public * @return mixed return * @ */ function batchXML($options=null){ if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, ' missing XML data', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xml'])){ $mode = $options['xml'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if (!$this->setXML($options['xml'],$mode)){ $this->raiseError(1002); return false; } $this->initXML(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XML_EMPTY, null, null, ' missing XML data', $this->error_class, true ); return false; } if(isset($options['xslt_files']) && is_array($options['xslt_files'])){ $xsl_files = $options['xslt_files']; $xslt_args = ''; foreach($xsl_files as $xslt_file=>$xslt){ exec( XSLT_XT_CMD.' '.$this->_arg_xml ." " . escapeshellarg($xslt['filepath']) . " '".$this->_buildParams()."' >". $dest_dir.$xslt['outputfile'], $messages,$return_code ); if($return_code==0){ $error = false; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code. ' '.$messages, $this->error_class, true ); $error = true; break; } } } $this->free(); return !$error; } // }}} // {{{ batchXSL /** * Transform multiple XML data with a single XSL files * * @access public * @return mixed return * @ */ function batchXSL($options=null){ if(is_null($options)){ $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_NOOPTIONS, null, null, ' missing XML data', $this->error_class, true ); return false; } if( isset($options['outputfolder']) ){ if(!is_dir($options['outputfolder'])){ if(!$this->_mkdir_p($options['outputfolder'])){ return false; } } } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_MISSEDDIR_FAILED, null, null, 'Output folder missing', $this->error_class, true ); return false; } $dest_dir = $options['outputfolder']; if(isset($options['xslt'])){ if (!$this->setXSL($options['xslt'],XML_XSLT_MODE_FILE)){ $this->raiseError(1002); return false; } $this->initXSL(); } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSL_EMPTY, null, null, 'missing XSL data in batchXSL', $this->error_class, true ); return false; } if(isset($options['xml_datas']) && is_array($options['xml_datas'])){ $xml_files = $options['xml_datas']; $xml_args = ''; foreach($xml_files as $xml_file=>$xml){ $mode = $xml['data'][0]=='<'? XML_XSLT_MODE_STRING:XML_XSLT_MODE_FILE; if($xml['data'][0]=='<'){ $xmlfile = $this->_saveTempData($xml['data']); } else { $xmlfile = $xml['data']; } exec( XSLT_XT_CMD.' '.escapeshellarg($xmlfile) ." " . $this->_arg_xsl . " '".$this->_buildParams()."' >". $dest_dir.$xml['outputfile'], $messages, $return_code ); if($return_code==0){ $error = false; } else { $this->error = PEAR::raiseError(null, XML_XSLT_ERROR_XSLEXEC_ERROR, null, null, 'Command returned: '.$return_code. ' '.$messages, $this->error_class, true ); $error = true; break; } } } $this->free(); return !$error; } // }}} // {{{ free /** * Free all ressources * * @access public * @return mixed return * @ */ function free(){ $this->_removeTempData(); } // }}} } /* * Local Variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * End: */ ?>
« previous php.pear.cvs (#6792) next »