1<?php 2/* 3 * $Id: 8f87e1c7908c06223382baf628d018c3a0f10824 $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://phing.info>. 20 */ 21 22require_once 'phing/tasks/system/CopyTask.php'; 23include_once 'phing/system/io/FileReader.php'; 24include_once 'phing/system/io/FileWriter.php'; 25include_once 'phing/filters/XsltFilter.php'; 26 27/** 28 * Implements an XSLT processing filter while copying files. 29 * 30 * This is a shortcut for calling the <copy> task with the XSLTFilter used 31 * in the <filterchains> section. 32 * 33 * @author Andreas Aderhold, andi@binarycloud.com 34 * @version $Id: 8f87e1c7908c06223382baf628d018c3a0f10824 $ 35 * @package phing.tasks.system 36 */ 37class XsltTask extends CopyTask { 38 39 /** XSLTFilter object that we use to handle transformation. */ 40 private $xsltFilter; 41 42 /** Parameters to pass to XSLT procesor. */ 43 private $parameters = array(); 44 45 /** 46 * Setup the filterchains w/ XSLTFilter that we will use while copying the files. 47 */ 48 function init() { 49 $xf = new XsltFilter(); 50 $chain = $this->createFilterChain($this->getProject()); 51 $chain->addXsltFilter($xf); 52 $this->xsltFilter = $xf; 53 } 54 55 /** 56 * Set any XSLT Param and invoke CopyTask::main() 57 * @see CopyTask::main() 58 */ 59 function main() { 60 $this->log("Doing XSLT transformation using stylesheet " . $this->xsltFilter->getStyle(), Project::MSG_VERBOSE); 61 $this->xsltFilter->setParams($this->parameters); 62 parent::main(); 63 } 64 65 /** 66 * Set the stylesheet to use. 67 * @param PhingFile $style 68 */ 69 function setStyle(PhingFile $style) { 70 $this->xsltFilter->setStyle($style); 71 } 72 73 /** 74 * Whether to resolve entities in the XML document. 75 * 76 * @param bool $resolveExternals 77 * 78 * @since 2.4 79 */ 80 function setResolveDocumentExternals($resolveExternals) { 81 $this->xsltFilter->setResolveDocumentExternals((bool)$resolveExternals); 82 } 83 84 /** 85 * Whether to resolve entities in the stylesheet. 86 * 87 * @param bool $resolveExternals 88 * 89 * @since 2.4 90 */ 91 function setResolveStylesheetExternals($resolveExternals) { 92 $this->xsltFilter->setResolveStylesheetExternals((bool)$resolveExternals); 93 } 94 95 /** 96 * Support nested <param> tags useing XSLTParam class. 97 * @return XSLTParam 98 */ 99 function createParam() { 100 $num = array_push($this->parameters, new XSLTParam()); 101 return $this->parameters[$num-1]; 102 } 103} 104