XsltTask.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. * $Id: XsltTask.php 905 2010-10-05 16:28:03Z mrook $
  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. require_once 'phing/tasks/system/CopyTask.php';
  22. include_once 'phing/system/io/FileReader.php';
  23. include_once 'phing/system/io/FileWriter.php';
  24. include_once 'phing/filters/XsltFilter.php';
  25. /**
  26. * Implements an XSLT processing filter while copying files.
  27. *
  28. * This is a shortcut for calling the <copy> task with the XSLTFilter used
  29. * in the <filterchains> section.
  30. *
  31. * @author Andreas Aderhold, andi@binarycloud.com
  32. * @version $Id: XsltTask.php 905 2010-10-05 16:28:03Z mrook $
  33. * @package phing.tasks.system
  34. */
  35. class XsltTask extends CopyTask {
  36. /** XSLTFilter object that we use to handle transformation. */
  37. private $xsltFilter;
  38. /** Parameters to pass to XSLT procesor. */
  39. private $parameters = array();
  40. /**
  41. * Setup the filterchains w/ XSLTFilter that we will use while copying the files.
  42. */
  43. function init() {
  44. $xf = new XsltFilter();
  45. $chain = $this->createFilterChain($this->getProject());
  46. $chain->addXsltFilter($xf);
  47. $this->xsltFilter = $xf;
  48. }
  49. /**
  50. * Set any XSLT Param and invoke CopyTask::main()
  51. * @see CopyTask::main()
  52. */
  53. function main() {
  54. $this->log("Doing XSLT transformation using stylesheet " . $this->xsltFilter->getStyle(), Project::MSG_VERBOSE);
  55. $this->xsltFilter->setParams($this->parameters);
  56. parent::main();
  57. }
  58. /**
  59. * Set the stylesheet to use.
  60. * @param PhingFile $style
  61. */
  62. function setStyle(PhingFile $style) {
  63. $this->xsltFilter->setStyle($style);
  64. }
  65. /**
  66. * Whether to resolve entities in the XML document.
  67. *
  68. * @param bool $resolveExternals
  69. *
  70. * @since 2.4
  71. */
  72. function setResolveDocumentExternals($resolveExternals) {
  73. $this->xsltFilter->setResolveDocumentExternals((bool)$resolveExternals);
  74. }
  75. /**
  76. * Whether to resolve entities in the stylesheet.
  77. *
  78. * @param bool $resolveExternals
  79. *
  80. * @since 2.4
  81. */
  82. function setResolveStylesheetExternals($resolveExternals) {
  83. $this->xsltFilter->setResolveStylesheetExternals((bool)$resolveExternals);
  84. }
  85. /**
  86. * Support nested <param> tags useing XSLTParam class.
  87. * @return XSLTParam
  88. */
  89. function createParam() {
  90. $num = array_push($this->parameters, new XSLTParam());
  91. return $this->parameters[$num-1];
  92. }
  93. }