phpDocumentor ZNF
Presentation
[ class tree: ZNF ] [ index: ZNF ] [ all elements ]

Source for file XSLT.php

Documentation is available at XSLT.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4.  * PHP version 5
  5.  *
  6.  * This source file is subject to version 2.1 of the GNU Lesser General Public
  7.  * License, that is bundled with this package in the file COPYING, available
  8.  * through the world wide web at the following URI:
  9.  * http://www.gnu.org/copyleft/lesser.html.
  10.  *
  11.  * @package    ZNF
  12.  * @subpackage Presentation
  13.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  14.  * @author     Graziano Liberati <http://www.liberati.org>
  15.  * @copyright  2004-2007 The ZNF Development Team
  16.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  17.  * @version    SVN $Id: XSLT.php 43 2007-06-26 23:36:35Z aronnax $
  18.  * @since      Release 0.5.0
  19.  * @link       http://www.zeronotice.org
  20.  */
  21.  
  22. require_once('ZNF/Presentation/Render.php');
  23.  
  24. /**
  25.  * <i>ZNF_Presentation_XSLT</i> class, extends the <i>ZNF_Presentation_Render</i> class and implements renderization with PHP <i>XSLTProcessor</i>.
  26.  *
  27.  * Render XML data using package or theme XSLT.
  28.  *
  29.  * @access     public
  30.  * @package    ZNF
  31.  * @subpackage Presentation
  32.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  33.  * @author     Graziano Liberati <http://www.liberati.org>
  34.  * @copyright  2004-2007 The ZNF Development Team
  35.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  36.  * @version    SVN $Id: XSLT.php 43 2007-06-26 23:36:35Z aronnax $
  37.  * @since      Release 0.5.0
  38.  * @link       http://www.zeronotice.org
  39.  */
  40. {
  41.  
  42.     /**
  43.      * The <i>XSLTProcessor</i>.
  44.      *
  45.      * @access protected
  46.      * @var XSLTProcessor $_xslt 
  47.      */
  48.      protected $_xslt;
  49.  
  50.     /**
  51.      * Where assigned XSLT parameters are kept.
  52.      *
  53.      * @access protected
  54.      * @var array $_xsltParams 
  55.      */
  56.      protected $_xsltParams = array();
  57.  
  58.     /**
  59.      * Constructs a new <i>ZNF_Presentation_XSLT</i> object and sets the internal properties with application settings.
  60.      *
  61.      * @access public
  62.      * @param string $package Name of the package to which the xslt template
  63.      *                         refers, leave null this parameter to refer to the
  64.      *                         theme xslt template
  65.      * @param ZNF_Action_ActionMapping $mapping 
  66.      */
  67.     public function __construct($package null$mapping null)
  68.     {
  69.         parent::__construct($package$mapping);
  70.  
  71.         $this->_xslt = new XSLTProcessor();
  72.     }
  73.  
  74.     /**
  75.      * Executes and returns the xslt template results.
  76.      *
  77.      * @access public
  78.      * @param string $template File name of the xslt template
  79.      * @param string $xml The XML document
  80.      * @return string 
  81.      */
  82.     public function fetch($template$xml null)
  83.     {
  84.         $template $this->_getTemplatePath($template);
  85.  
  86.         $this->_xslt->importStylesheet(DOMDocument::load($template));
  87.         $this->_assignConstants($template);
  88.  
  89.         // change this istruction when the xsltprocessor->setParameter() is fixed to accept an array
  90.         foreach ($this->_xsltParams as $name => $value{
  91.             $this->_xslt->setParameter('znf'$name$value);
  92.         }
  93.  
  94.         return $this->_xslt->transformToXml(DOMDocument::loadXML($xml));
  95.     }
  96.  
  97.     /**
  98.      * Executes and displays the xslt template results.
  99.      *
  100.      * @access public
  101.      * @param string $template File name of the xslt template
  102.      * @param string $xml The XML document
  103.      */
  104.     public function display($template$xml null)
  105.     {
  106.         $template $this->_getTemplatePath($template);
  107.  
  108.         $this->_xslt->importStylesheet(DOMDocument::load($template));
  109.         $this->_assignConstants($template);
  110.  
  111.         // change this istruction when the xsltprocessor->setParameter() is fixed to accept an array
  112.         foreach ($this->_xsltParams as $name => $value{
  113.             $this->_xslt->setParameter('znf'$name$value);
  114.         }
  115.  
  116.         echo $this->_xslt->transformToXml(DOMDocument::loadXML($xml));
  117.     }
  118.  
  119.     /**
  120.      * Assigns values to xslt template parameters.
  121.      *
  122.      * @access public
  123.      * @param string $param The xslt template parameter name
  124.      * @param mixed $value The value to assign
  125.      */
  126.     public function assign($param$value)
  127.     {
  128.         if ($param{
  129.             $this->_xsltParams[$param$value;
  130.         }
  131.     }
  132.  
  133.     /**
  134.      * Assign to xslt template the ZNF constants.
  135.      *
  136.      * @access protected
  137.      */
  138.     protected function _assignConstants()
  139.     {
  140.         $constants $this->_getConstants();
  141.  
  142.         $this->assign('znf.baseHref'$constants['baseHref']);
  143.         $this->assign('znf.actionIndex'$constants['actionIndex']);
  144.         $this->assign('znf.moduleIndex'$constants['moduleIndex']);
  145.         $this->assign('znf.themePath'$constants['themePath']);
  146.         $this->assign('znf.packagePath'$constants['packagePath']);
  147.         $this->assign('znf.path'$constants['path']);
  148.         $this->assign('znf.nextPath'$constants['nextPath']);
  149.         $this->assign('znf.credits'$constants['credits']);
  150.     }
  151.  
  152.     /**
  153.      * Destroys the <i>ZNF_Presentation_XSLT</i> object.</>
  154.      *
  155.      * @access public
  156.      */
  157.     public function __destruct()
  158.     {
  159.     }
  160.  
  161. }
  162.  
  163. /**
  164.  * <i>ZNF_Presentation_XSLTException</i> is the exception type for the <i>ZNF_Presentation_XSLT</i> class.
  165.  *
  166.  * <i>ZNF_Presentation_XSLTException</i> extends the <i>Exception</i> class of PHP5.
  167.  *
  168.  * @access     public
  169.  * @package    ZNF
  170.  * @subpackage Presentation
  171.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  172.  * @author     Graziano Liberati <http://www.liberati.org>
  173.  * @copyright  2004-2007 The ZNF Development Team
  174.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  175.  * @version    SVN $Id: XSLT.php 43 2007-06-26 23:36:35Z aronnax $
  176.  * @since      Release 0.5.0
  177.  * @link       http://www.zeronotice.org
  178.  */
  179. class ZNF_Presentation_XSLTException extends Exception
  180. {
  181. }
  182.  
  183. ?>

Documentation generated on Wed, 14 Nov 2007 23:47:43 +0100 by phpDocumentor 1.4.0