diff options
Diffstat (limited to 'buildscripts/phing/classes/phing/filters')
24 files changed, 1079 insertions, 161 deletions
diff --git a/buildscripts/phing/classes/phing/filters/BaseFilterReader.php b/buildscripts/phing/classes/phing/filters/BaseFilterReader.php index c9f8c619..4489b16e 100644..100755 --- a/buildscripts/phing/classes/phing/filters/BaseFilterReader.php +++ b/buildscripts/phing/classes/phing/filters/BaseFilterReader.php @@ -1,7 +1,7 @@ <?php /* - * $Id: BaseFilterReader.php,v 1.8 2004/05/20 02:24:10 hlellelid Exp $ + * $Id: a1da135c09abf5cf07a53b3a327baf3497cfb697 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -28,7 +28,7 @@ include_once 'phing/system/io/StringReader.php'; * Base class for core filter readers. * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> - * @version $Revision: 1.8 $ $Date: 2004/05/20 02:24:10 $ + * @version $Id$ * @access public * @see FilterReader * @package phing.filters @@ -147,11 +147,11 @@ class BaseFilterReader extends FilterReader { * @param string $msg Message to log. * @param int $level Priority level. */ - function log($msg, $level = PROJECT_MSG_INFO) { + function log($msg, $level = Project::MSG_INFO) { if ($this->project !== null) { $this->project->log("[filter:".get_class($this)."] ".$msg, $level); } } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/BaseParamFilterReader.php b/buildscripts/phing/classes/phing/filters/BaseParamFilterReader.php index 3d767b40..8d3b0810 100644..100755 --- a/buildscripts/phing/classes/phing/filters/BaseParamFilterReader.php +++ b/buildscripts/phing/classes/phing/filters/BaseParamFilterReader.php @@ -1,7 +1,7 @@ <?php /* - * $Id: BaseParamFilterReader.php,v 1.5 2005/02/27 20:52:08 mrook Exp $ + * $Id: 412cc012db35b1dcf3545b93d5053e727d66b61f $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -28,8 +28,8 @@ include_once 'phing/types/Parameter.php'; * Base class for core filter readers. * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> - * @copyright © 2003 seasonfive. All rights reserved - * @version $Revision: 1.5 $ $Date: 2005/02/27 20:52:08 $ + * @copyright � 2003 seasonfive. All rights reserved + * @version $Id$ * @access public * @see FilterReader * @package phing.filters @@ -66,4 +66,4 @@ class BaseParamFilterReader extends BaseFilterReader implements Parameterizable } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/ChainableReader.php b/buildscripts/phing/classes/phing/filters/ChainableReader.php index c7de07c4..2b773dbe 100644 --- a/buildscripts/phing/classes/phing/filters/ChainableReader.php +++ b/buildscripts/phing/classes/phing/filters/ChainableReader.php @@ -1,7 +1,7 @@ <?php /* - * $Id: ChainableReader.php,v 1.2 2003/11/19 05:48:27 hlellelid Exp $ + * $Id: fb9ebbb44f13ecc3693265e1b793ab17cea543a1 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -24,6 +24,7 @@ * Interface indicating that a reader may be chained to another one. * * @author Magesh Umasankar + * @package phing.filters */ interface ChainableReader { @@ -39,4 +40,4 @@ interface ChainableReader { public function chain(Reader $rdr); } -?> + diff --git a/buildscripts/phing/classes/phing/filters/ExpandProperties.php b/buildscripts/phing/classes/phing/filters/ExpandProperties.php index dfd98cc8..2517783f 100644..100755 --- a/buildscripts/phing/classes/phing/filters/ExpandProperties.php +++ b/buildscripts/phing/classes/phing/filters/ExpandProperties.php @@ -1,7 +1,7 @@ <?php /* - * $Id: ExpandProperties.php,v 1.6 2004/07/14 17:14:15 hlellelid Exp $ + * $Id: d6bb7717db7cf2b122cbdcb93e5bb0f45d97ec52 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -33,13 +33,30 @@ include_once 'phing/filters/ChainableReader.php'; * * @author Yannick Lecaillez <yl@seasonfive.com> * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.6 $ + * @version $Id: d6bb7717db7cf2b122cbdcb93e5bb0f45d97ec52 $ * @see BaseFilterReader * @package phing.filters */ class ExpandProperties extends BaseFilterReader implements ChainableReader { + protected $logLevel = Project::MSG_VERBOSE; /** + * Set level of log messages generated (default = info) + * @param string $level + */ + public function setLevel($level) + { + switch ($level) + { + case "error": $this->logLevel = Project::MSG_ERR; break; + case "warning": $this->logLevel = Project::MSG_WARN; break; + case "info": $this->logLevel = Project::MSG_INFO; break; + case "verbose": $this->logLevel = Project::MSG_VERBOSE; break; + case "debug": $this->logLevel = Project::MSG_DEBUG; break; + } + } + + /** * Returns the filtered stream. * The original stream is first read in fully, and the Phing properties are expanded. * @@ -57,7 +74,7 @@ class ExpandProperties extends BaseFilterReader implements ChainableReader { } $project = $this->getProject(); - $buffer = ProjectConfigurator::replaceProperties($project, $buffer, $project->getProperties()); + $buffer = ProjectConfigurator::replaceProperties($project, $buffer, $project->getProperties(), $this->logLevel); return $buffer; } @@ -79,4 +96,4 @@ class ExpandProperties extends BaseFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/HeadFilter.php b/buildscripts/phing/classes/phing/filters/HeadFilter.php index 84673b4a..3cbcb51b 100644..100755 --- a/buildscripts/phing/classes/phing/filters/HeadFilter.php +++ b/buildscripts/phing/classes/phing/filters/HeadFilter.php @@ -1,7 +1,7 @@ <?php /* - * $Id: HeadFilter.php,v 1.6 2004/03/15 14:45:06 hlellelid Exp $ + * $Id: e3e9c0a171b4416545e57fe42b45b4eec14914ce $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -36,7 +36,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.6 $ $Date: 2004/03/15 14:45:06 $ + * @version $Id$ * @access public * @see FilterReader * @package phing.filters @@ -158,4 +158,4 @@ class HeadFilter extends BaseParamFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/IconvFilter.php b/buildscripts/phing/classes/phing/filters/IconvFilter.php new file mode 100755 index 00000000..c9883b17 --- /dev/null +++ b/buildscripts/phing/classes/phing/filters/IconvFilter.php @@ -0,0 +1,155 @@ +<?php + +/* + * $Id: 9c0d703f08f0160b6a699d328a6025587877e104 $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. +*/ + +include_once 'phing/filters/BaseParamFilterReader.php'; +include_once 'phing/filters/ChainableReader.php'; + +/** + * Encode data from <code>in</code> encoding to <code>out</code> encoding. + * + * Example: + * <pre> + * <iconvfilter inputencoding="UTF-8" outputencoding="CP1251" /> + * </pre> + * Or: + * <pre> + * <filterreader classname="phing.filters.IconvFilter"> + * <param name="inputencoding" value="UTF-8" /> + * <param name="outputencoding" value="CP1251" /> + * </filterreader> + * </pre> + * + * @author Alexey Shockov, <alexey@shockov.com> + * @version $Id$ + * @package phing.filters + */ +class IconvFilter + extends BaseParamFilterReader + implements ChainableReader { + + private $_inputEncoding; + + private $_outputEncoding; + + /** + * Returns first n lines of stream. + * @return the resulting stream, or -1 + * if the end of the resulting stream has been reached + * + * @exception IOException if the underlying stream throws an IOException + * during reading + */ + function read($len = null) { + $this->_initialize(); + + // Process whole text at once. + $text = null; + while (($data = $this->in->read($len)) !== -1) { + $text .= $data; + } + + // At the end. + if (null === $text) { + return -1; + } + + $this->log( + "Encoding " . $this->in->getResource() . " from " . $this->getInputEncoding() . " to " . $this->getOutputEncoding(), + Project::MSG_VERBOSE + ); + + return iconv($this->_inputEncoding, $this->_outputEncoding, $text); + } + + /** + * + * @param string $encoding Input encoding. + */ + public function setInputEncoding($encoding) { + $this->_inputEncoding = $encoding; + } + + /** + * + * @return string + */ + public function getInputEncoding() { + return $this->_inputEncoding; + } + + /** + * + * @param string $encoding Output encoding. + */ + public function setOutputEncoding($encoding) { + $this->_outputEncoding = $encoding; + } + + /** + * + * @return string + */ + public function getOutputEncoding() { + return $this->_outputEncoding; + } + + /** + * Creates a new IconvFilter using the passed in Reader for instantiation. + * + * @param object A Reader object providing the underlying stream. Must not be <code>null</code>. + * + * @return object A new filter based on this configuration, but filtering the specified reader. + */ + function chain(Reader $reader) { + $filter = new self($reader); + + $filter->setInputEncoding($this->getInputEncoding()); + $filter->setOutputEncoding($this->getOutputEncoding()); + + $filter->setInitialized(true); + $filter->setProject($this->getProject()); + + return $filter; + } + + /** + * Configuring object from the parameters list. + */ + private function _initialize() { + if ($this->getInitialized()) { + return; + } + + $params = $this->getParameters(); + if ($params !== null) { + foreach ($params as $param) { + if ('in' == $param->getName()) { + $this->setInputEncoding($param->getValue()); + } else if ('out' == $param->getName()) { + $this->setOutputEncoding($param->getValue()); + } + } + } + + $this->setInitialized(true); + } +} diff --git a/buildscripts/phing/classes/phing/filters/LineContains.php b/buildscripts/phing/classes/phing/filters/LineContains.php index 8f3136b7..b84b62c1 100644..100755 --- a/buildscripts/phing/classes/phing/filters/LineContains.php +++ b/buildscripts/phing/classes/phing/filters/LineContains.php @@ -1,7 +1,7 @@ <?php /* - * $Id: LineContains.php,v 1.11 2005/02/27 20:52:08 mrook Exp $ + * $Id: 2e783b14ff093df7de21477479a123403d630984 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -47,7 +47,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author Yannick Lecaillez <yl@seasonfive.com> * @author Hans Lellelid <hans@velum.net> - * @version $Revision: 1.11 $ + * @version $Id$ * @see PhingFilterReader * @package phing.filters */ @@ -153,7 +153,7 @@ class LineContains extends BaseParamFilterReader implements ChainableReader { } /** - * Adds a <code><contains></code> nested element. + * Adds a <code>contains</code> nested element. * * @return Contains The <code>contains</code> element added. * Must not be <code>null</code>. @@ -169,7 +169,7 @@ class LineContains extends BaseParamFilterReader implements ChainableReader { * * @param array $contains An array of words which must be contained * within a line in order for it to match in this filter. - * Must not be <code>null<code>. + * Must not be <code>null</code>. */ function setContains($contains) { // type check, error must never occur, bad code of it does @@ -231,6 +231,8 @@ class LineContains extends BaseParamFilterReader implements ChainableReader { /** * Holds a contains element. + * + * @package phing.filters */ class Contains { @@ -255,4 +257,4 @@ class Contains { return $this->_value; } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/LineContainsRegexp.php b/buildscripts/phing/classes/phing/filters/LineContainsRegexp.php index dcbb532c..c603978f 100644..100755 --- a/buildscripts/phing/classes/phing/filters/LineContainsRegexp.php +++ b/buildscripts/phing/classes/phing/filters/LineContainsRegexp.php @@ -1,6 +1,6 @@ <?php /* - * $Id: LineContainsRegexp.php,v 1.8 2005/02/27 20:52:08 mrook Exp $ + * $Id: 0a881c0b67c96c20345980fd033f006379949dda $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -42,7 +42,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author Yannick Lecaillez <yl@seasonfive.com> * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.8 $ + * @version $Id$ * @see FilterReader * @package phing.filters */ @@ -176,4 +176,4 @@ class LineContainsRegexp extends BaseParamFilterReader implements ChainableReade } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/PrefixLines.php b/buildscripts/phing/classes/phing/filters/PrefixLines.php index a5580f87..9edcc02a 100644..100755 --- a/buildscripts/phing/classes/phing/filters/PrefixLines.php +++ b/buildscripts/phing/classes/phing/filters/PrefixLines.php @@ -1,7 +1,7 @@ <?php /* - * $Id: PrefixLines.php,v 1.6 2004/03/15 14:45:06 hlellelid Exp $ + * $Id: 744d8766d5aba397c0a8efd61afb8e60bd77b0c3 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -37,7 +37,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.6 $ $Date: 2004/03/15 14:45:06 $ + * @version $Id$ * @access public * @see FilterReader * @package phing.filters @@ -139,4 +139,4 @@ class PrefixLines extends BaseParamFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/ReplaceRegexp.php b/buildscripts/phing/classes/phing/filters/ReplaceRegexp.php index 3c5592e8..70e8940f 100644..100755 --- a/buildscripts/phing/classes/phing/filters/ReplaceRegexp.php +++ b/buildscripts/phing/classes/phing/filters/ReplaceRegexp.php @@ -1,7 +1,7 @@ <?php /* - * $Id: ReplaceRegexp.php,v 1.5 2003/12/24 12:38:39 hlellelid Exp $ + * $Id: 3ea7f569d0f0b1c4d0f057c9f7f8969cb829f2cb $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -36,7 +36,7 @@ include_once 'phing/types/RegularExpression.php'; * </pre> * * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.5 $ + * @version $Id$ * @package phing.filters */ class ReplaceRegexp extends BaseFilterReader implements ChainableReader { @@ -97,10 +97,10 @@ class ReplaceRegexp extends BaseFilterReader implements ChainableReader { $regexp = $exptype->getRegexp($this->project); try { $buffer = $regexp->replace($buffer); - $this->log("Performing regexp replace: /".$regexp->getPattern()."/".$regexp->getReplace()."/g".($regexp->getIgnoreCase() ? 'i' : ''), PROJECT_MSG_VERBOSE); + $this->log("Performing regexp replace: /".$regexp->getPattern()."/".$regexp->getReplace()."/g".$regexp->getModifiers(), Project::MSG_VERBOSE); } catch (Exception $e) { // perhaps mismatch in params (e.g. no replace or pattern specified) - $this->log("Error performing regexp replace: " . $e->getMessage(), PROJECT_MSG_WARN); + $this->log("Error performing regexp replace: " . $e->getMessage(), Project::MSG_WARN); } } @@ -126,4 +126,4 @@ class ReplaceRegexp extends BaseFilterReader implements ChainableReader { } -?> + diff --git a/buildscripts/phing/classes/phing/filters/ReplaceTokens.php b/buildscripts/phing/classes/phing/filters/ReplaceTokens.php index 999f734f..a5cd7521 100644..100755 --- a/buildscripts/phing/classes/phing/filters/ReplaceTokens.php +++ b/buildscripts/phing/classes/phing/filters/ReplaceTokens.php @@ -1,7 +1,7 @@ <?php /* - * $Id: ReplaceTokens.php,v 1.14 2005/06/16 15:09:10 hlellelid Exp $ + * $Id: 6c5d97f2254de3c08ac34baaabf6119c54a49a7d $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -24,7 +24,7 @@ include_once 'phing/filters/BaseParamFilterReader.php'; include_once 'phing/types/TokenSource.php'; include_once 'phing/filters/ChainableReader.php'; -/* +/** * Replaces tokens in the original input with user-supplied values. * * Example: @@ -43,7 +43,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.14 $ $Date: 2005/06/16 15:09:10 $ + * @version $Id: 6c5d97f2254de3c08ac34baaabf6119c54a49a7d $ * @access public * @see BaseParamFilterReader * @package phing.filters @@ -142,7 +142,7 @@ class ReplaceTokens extends BaseParamFilterReader implements ChainableReader { $replaceWith = $this->_beginToken . $key . $this->_endToken; $this->log("No token defined for key \"".$this->_beginToken . $key . $this->_endToken."\""); } else { - $this->log("Replaced \"".$this->_beginToken . $key . $this->_endToken ."\" with \"".$replaceWith."\""); + $this->log("Replaced \"".$this->_beginToken . $key . $this->_endToken ."\" with \"".$replaceWith."\"", Project::MSG_VERBOSE); } return $replaceWith; @@ -169,7 +169,7 @@ class ReplaceTokens extends BaseParamFilterReader implements ChainableReader { // filter buffer $buffer = preg_replace_callback( - "/".preg_quote($this->_beginToken)."([\w\.\-:]+?)".preg_quote($this->_endToken)."/", + "/".preg_quote($this->_beginToken, '/')."([\w\.\-:]+?)".preg_quote($this->_endToken, '/')."/", array($this, 'replaceTokenCallback'), $buffer); return $buffer; @@ -360,6 +360,8 @@ class ReplaceTokens extends BaseParamFilterReader implements ChainableReader { /** * Holds a token. + * + * @package phing.filters */ class Token { @@ -390,7 +392,16 @@ class Token { * @param string $value The value for this token. Must not be <code>null</code>. */ function setValue($value) { - $this->_value = (string) $value; + // special case for boolean values + if (is_bool($value)) { + if ($value) { + $this->_value = "true"; + } else { + $this->_value = "false"; + } + } else { + $this->_value = (string) $value; + } } /** @@ -410,6 +421,15 @@ class Token { function getValue() { return $this->_value; } + + /** + * Sets the token value from text. + * + * @param string $value The value for this token. Must not be <code>null</code>. + */ + function addText($value) { + $this->setValue($value); + } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/ReplaceTokensWithFile.php b/buildscripts/phing/classes/phing/filters/ReplaceTokensWithFile.php new file mode 100644 index 00000000..580b8d84 --- /dev/null +++ b/buildscripts/phing/classes/phing/filters/ReplaceTokensWithFile.php @@ -0,0 +1,361 @@ +<?php + +/* + * $Id: 164a2d9eeba3673653086b32e9fa2045168c992c $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. +*/ + +include_once 'phing/filters/BaseParamFilterReader.php'; +include_once 'phing/filters/ChainableReader.php'; + +/** + * Replaces tokens in the original input with the contents of a file. + * The file to be used is controlled by the name of the token which + * corresponds to the basename of the file to be used together with + * the optional pre and postfix strings that is possible to set. + * + * By default all HTML entities in the file is replaced by the + * corresponding HTML entities. This behaviour can be controlled by + * the "translatehtml" parameter. + * + * Supported parameters are: + * <pre> + * prefix string Text to be prefixed to token before using as filename + * postfix string Text to be prefixed to token before using as filename + * dir string The directory where the files should be read from + * translatehtml bool If we should translate all HTML entities in the file. + * </pre> + * Example: + * + * <pre><filterreader classname="phing.filters.ReplaceTokensWithFile"> + * <param name="dir" value="examples/" /> + * <param name="postfix" value=".php" /> + * </filterreader></pre> + * + * @author johan persson, johanp@aditus.nu + * @version $Id: 164a2d9eeba3673653086b32e9fa2045168c992c $ + * @access public + * @see ReplaceTokensWithFile + * @package phing.filters + */ +class ReplaceTokensWithFile extends BaseParamFilterReader implements ChainableReader { + + /** + * Default "begin token" character. + * @var string + */ + const DEFAULT_BEGIN_TOKEN = "#@#"; + + /** + * Default "end token" character. + * @var string + */ + const DEFAULT_END_TOKEN = "#@#"; + + /** + * Array to hold the token sources that make tokens from + * different sources available + * @var array + */ + private $_tokensources = array(); + + /** + * Character marking the beginning of a token. + * @var string + */ + private $_beginToken = ReplaceTokensWithFile::DEFAULT_BEGIN_TOKEN; + + /** + * Character marking the end of a token. + * @var string + */ + private $_endToken = ReplaceTokensWithFile::DEFAULT_END_TOKEN; + + /** + * File prefix to be inserted in front of the token to create the + * file name to be used. + * @var string + */ + private $_prefix = ''; + + /** + * File postfix to be inserted in front of the token to create the + * file name to be used. + * @var string + */ + private $_postfix = ''; + + /** + * Directory where to look for the files. The default is to look in the + * current file. + * + * @var string + */ + private $_dir = './'; + + /** + * Translate all HTML entities in the file to the corresponding HTML + * entities before it is used as replacements. For example all '<' + * will be translated to < before the content is inserted. + * + * @var boolean + */ + private $_translatehtml = true; + + + /** + * Sets the drectory where to look for the files to use for token replacement + * + * @param string $dir + */ + function setTranslateHTML($translate) { + $this->_translatehtml = (bool) $translate; + } + + /** + * Returns the drectory where to look for the files to use for token replacement + */ + function getTranslateHTML() { + return $this->_translatehtml; + } + + /** + * Sets the drectory where to look for the files to use for token replacement + * + * @param string $dir + */ + function setDir($dir) { + $this->_dir = (string) $dir; + } + + /** + * Returns the drectory where to look for the files to use for token replacement + */ + function getDir() { + return $this->_dir; + } + + /** + * Sets the prefix that is prepended to the token in order to create the file + * name. For example if the token is 01 and the prefix is "example" then + * the filename to look for will be "example01" + * + * @param string $prefix + */ + function setPrefix($prefix) { + $this->_prefix = (string) $prefix; + } + + /* + * Returns the prefix that is prepended to the token in order to create the file + * name. For example if the token is 01 and the prefix is "example" then + * the filename to look for will be "example01" + */ + function getPrefix() { + return $this->_prefix; + } + + /** + * Sets the postfix that is added to the token in order to create the file + * name. For example if the token is 01 and the postfix is ".php" then + * the filename to look for will be "01.php" + * + * @param string $postfix + */ + function setPostfix($postfix) { + $this->_postfix = (string) $postfix; + } + + /** + * Returns the postfix that is added to the token in order to create the file + * name. For example if the token is 01 and the postfix is ".php" then + * the filename to look for will be "01.php" + */ + function getPostfix() { + return $this->_postfix; + } + + /** + * Sets the "begin token" character. + * + * @param string $beginToken the character used to denote the beginning of a token. + */ + function setBeginToken($beginToken) { + $this->_beginToken = (string) $beginToken; + } + + /** + * Returns the "begin token" character. + * + * @return string The character used to denote the beginning of a token. + */ + function getBeginToken() { + return $this->_beginToken; + } + + /** + * Sets the "end token" character. + * + * @param string $endToken the character used to denote the end of a token + */ + function setEndToken($endToken) { + $this->_endToken = (string) $endToken; + } + + /** + * Returns the "end token" character. + * + * @return the character used to denote the beginning of a token + */ + function getEndToken() { + return $this->_endToken; + } + + /** + * Replace the token found with the appropriate file contents + * @param array $matches Array of 1 el containing key to search for. + * @return string Text with which to replace key or value of key if none is found. + * @access private + */ + private function replaceTokenCallback($matches) { + + $filetoken = $matches[1]; + + // We look in all specified directories for the named file and use + // the first directory which has the file. + $dirs = explode(';',$this->_dir); + + $ndirs = count($dirs); + $n = 0; + $file = $dirs[$n] . $this->_prefix . $filetoken . $this->_postfix; + + while ( $n < $ndirs && ! is_readable($file) ) { + ++$n; + } + + if( ! is_readable($file) || $n >= $ndirs ) { + $this->log("Can not read or find file \"$file\". Searched in directories: {$this->_dir}", Project::MSG_WARN); + //return $this->_beginToken . $filetoken . $this->_endToken; + return "[Phing::Filters::ReplaceTokensWithFile: Can not find file " . '"' . $filetoken . $this->_postfix . '"' . "]"; + } + + $buffer = file_get_contents($file); + if( $this->_translatehtml ) { + $buffer = htmlentities($buffer); + } + + if ($buffer === null) { + $buffer = $this->_beginToken . $filetoken . $this->_endToken; + $this->log("No corresponding file found for key \"$buffer\"", Project::MSG_WARN); + } else { + $this->log("Replaced \"".$this->_beginToken . $filetoken . $this->_endToken."\" with content from file \"$file\""); + } + + return $buffer; + } + + /** + * Returns stream with tokens having been replaced with appropriate values. + * If a replacement value is not found for a token, the token is left in the stream. + * + * @return mixed filtered stream, -1 on EOF. + */ + function read($len = null) { + if ( !$this->getInitialized() ) { + $this->_initialize(); + $this->setInitialized(true); + } + + // read from next filter up the chain + $buffer = $this->in->read($len); + + if($buffer === -1) { + return -1; + } + + // filter buffer + $buffer = preg_replace_callback( + "/".preg_quote($this->_beginToken)."([\w\.\-:\/]+?)".preg_quote($this->_endToken)."/", + array($this, 'replaceTokenCallback'), $buffer); + + return $buffer; + } + + /** + * Creates a new ReplaceTokensWithFile using the passed in + * Reader for instantiation. + * + * @param object A Reader object providing the underlying stream. + * Must not be <code>null</code>. + * + * @return object A new filter based on this configuration, but filtering + * the specified reader + */ + function chain(Reader $reader) { + $newFilter = new ReplaceTokensWithFile($reader); + $newFilter->setProject($this->getProject()); + $newFilter->setTranslateHTML($this->getTranslateHTML()); + $newFilter->setDir($this->getDir()); + $newFilter->setPrefix($this->getPrefix()); + $newFilter->setPostfix($this->getPostfix()); + $newFilter->setBeginToken($this->getBeginToken()); + $newFilter->setEndToken($this->getEndToken()); + $newFilter->setInitialized(true); + return $newFilter; + } + + /** + * Initializes parameters + * This method is only called when this filter is used through + * a <filterreader> tag in build file. + */ + private function _initialize() { + $params = $this->getParameters(); + $n = count($params); + + if ( $params !== null ) { + for($i = 0 ; $i < $n ; $i++) { + if ( $params[$i] !== null ) { + $name = $params[$i]->getName(); + switch( $name ) { + case 'begintoken' : + $this->_beginToken = $params[$i]->getValue(); + break; + case 'endtoken' : + $this->_endToken = $params[$i]->getValue(); + break; + case 'dir': + $this->_dir = $params[$i]->getValue(); + break; + case 'prefix': + $this->_prefix = $params[$i]->getValue(); + break; + case 'postfix': + $this->_postfix = $params[$i]->getValue(); + break; + case 'translatehtml': + $this->_translatehtml = $params[$i]->getValue(); + break; + } + } + } + } + } +} + + diff --git a/buildscripts/phing/classes/phing/filters/StripLineBreaks.php b/buildscripts/phing/classes/phing/filters/StripLineBreaks.php index c5a06129..08d1aa6b 100644..100755 --- a/buildscripts/phing/classes/phing/filters/StripLineBreaks.php +++ b/buildscripts/phing/classes/phing/filters/StripLineBreaks.php @@ -1,7 +1,7 @@ <?php /* - * $Id: StripLineBreaks.php,v 1.8 2004/03/15 14:45:06 hlellelid Exp $ + * $Id: 84767114c6fcf8abe5fcc0dce48513faf18d6306 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -36,7 +36,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.8 $ $Date: 2004/03/15 14:45:06 $ + * @version $Id$ * @access public * @see BaseParamFilterReader * @package phing.filters @@ -145,4 +145,4 @@ class StripLineBreaks extends BaseParamFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/StripLineComments.php b/buildscripts/phing/classes/phing/filters/StripLineComments.php index 5d97979a..2a19ca25 100644..100755 --- a/buildscripts/phing/classes/phing/filters/StripLineComments.php +++ b/buildscripts/phing/classes/phing/filters/StripLineComments.php @@ -1,7 +1,7 @@ <?php /* - * $Id: StripLineComments.php,v 1.8 2005/02/27 20:52:08 mrook Exp $ + * $Id: b0b2b1dc67fff8bd5285e43e9d11b15f4ef44ae7 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -23,7 +23,7 @@ include_once 'phing/filters/BaseParamFilterReader.php'; include_once 'phing/filters/ChainableReader.php'; -/* +/** * This filter strips line comments. * * Example: @@ -48,7 +48,7 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.8 $ $Date: 2005/02/27 20:52:08 $ + * @version $Id$ * @access public * @see BaseParamFilterReader * @package phing.filters @@ -175,9 +175,11 @@ class StripLineComments extends BaseParamFilterReader implements ChainableReader } } -/* +/** * The class that holds a comment representation. -*/ + * + * @package phing.filters + */ class Comment { /** The prefix for a line comment. */ @@ -202,4 +204,4 @@ class Comment { return $this->_value; } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/StripPhpComments.php b/buildscripts/phing/classes/phing/filters/StripPhpComments.php index 9e21eed3..0abb8a67 100644..100755 --- a/buildscripts/phing/classes/phing/filters/StripPhpComments.php +++ b/buildscripts/phing/classes/phing/filters/StripPhpComments.php @@ -1,7 +1,7 @@ <?php /* - * $Id: StripPhpComments.php,v 1.6 2004/07/16 01:36:35 hlellelid Exp $ + * $Id: 6c68ae0ad1aa7f2f7825087c1c54233bd2462124 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -32,11 +32,10 @@ include_once 'phing/filters/ChainableReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @version $Revision: 1.6 $ $Date: 2004/07/16 01:36:35 $ + * @version $Id$ * @access public * @see FilterReader * @package phing.filters - * @todo -c use new PHP functions to perform this instead of regex. */ class StripPhpComments extends BaseFilterReader implements ChainableReader { /** @@ -171,7 +170,7 @@ class StripPhpComments extends BaseFilterReader implements ChainableReader { } /** - * Creates a new StripJavaComments using the passed in + * Creates a new StripPhpComments using the passed in * Reader for instantiation. * * @param reader A Reader object providing the underlying stream. @@ -187,4 +186,3 @@ class StripPhpComments extends BaseFilterReader implements ChainableReader { } } -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/filters/StripWhitespace.php b/buildscripts/phing/classes/phing/filters/StripWhitespace.php new file mode 100755 index 00000000..d7b6113f --- /dev/null +++ b/buildscripts/phing/classes/phing/filters/StripWhitespace.php @@ -0,0 +1,95 @@ +<?php + +/* + * $Id $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. +*/ + +include_once 'phing/filters/BaseFilterReader.php'; +include_once 'phing/filters/ChainableReader.php'; + +/** + * Strips whitespace from [php] files using PHP stripwhitespace() method. + * + * @author Hans Lellelid, hans@velum.net + * @version $Id$ + * @see FilterReader + * @package phing.filters + * @todo -c use new PHP functions to perform this instead of regex. + */ +class StripWhitespace extends BaseFilterReader implements ChainableReader { + + private $processed = false; + + /** + * Returns the stream without Php comments and whitespace. + * + * @return the resulting stream, or -1 + * if the end of the resulting stream has been reached + * + * @throws IOException if the underlying stream throws an IOException + * during reading + */ + function read($len = null) { + + if ($this->processed === true) { + return -1; // EOF + } + + // Read XML + $php = null; + while ( ($buffer = $this->in->read($len)) !== -1 ) { + $php .= $buffer; + } + + if ($php === null ) { // EOF? + return -1; + } + + if(empty($php)) { + $this->log("PHP file is empty!", Project::MSG_WARN); + return ''; // return empty string, don't attempt to strip whitespace + } + + // write buffer to a temporary file, since php_strip_whitespace() needs a filename + $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace')); + file_put_contents($file->getAbsolutePath(), $php); + $output = php_strip_whitespace($file->getAbsolutePath()); + unlink($file->getAbsolutePath()); + + $this->processed = true; + + return $output; + } + + /** + * Creates a new StripWhitespace using the passed in + * Reader for instantiation. + * + * @param reader A Reader object providing the underlying stream. + * Must not be <code>null</code>. + * + * @return a new filter based on this configuration, but filtering + * the specified reader + */ + public function chain(Reader $reader) { + $newFilter = new StripWhitespace($reader); + $newFilter->setProject($this->getProject()); + return $newFilter; + } +} diff --git a/buildscripts/phing/classes/phing/filters/TabToSpaces.php b/buildscripts/phing/classes/phing/filters/TabToSpaces.php index 7293d3b5..80d3c215 100644..100755 --- a/buildscripts/phing/classes/phing/filters/TabToSpaces.php +++ b/buildscripts/phing/classes/phing/filters/TabToSpaces.php @@ -1,7 +1,7 @@ <?php /* - * $Id: TabToSpaces.php,v 1.9 2004/03/15 14:45:06 hlellelid Exp $ + * $Id: 71dc074faa0ed97b47c49fec5449233ea485120c $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -38,7 +38,7 @@ require_once 'phing/filters/ChainableReader.php'; * * @author Yannick Lecaillez <yl@seasonfive.com> * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.9 $ + * @version $Id$ * @see BaseParamFilterReader * @package phing.filters */ @@ -141,4 +141,4 @@ class TabToSpaces extends BaseParamFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/TailFilter.php b/buildscripts/phing/classes/phing/filters/TailFilter.php index a6af6e4b..95a9c6f5 100644..100755 --- a/buildscripts/phing/classes/phing/filters/TailFilter.php +++ b/buildscripts/phing/classes/phing/filters/TailFilter.php @@ -1,7 +1,7 @@ <?php /* - * $Id: TailFilter.php,v 1.7 2004/03/15 14:45:06 hlellelid Exp $ + * $Id: 3c108d45a4b3be6f6b9a395477e7641d8e17c44b $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -37,8 +37,8 @@ require_once 'phing/filters/BaseParamFilterReader.php'; * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> * @author hans lellelid, hans@velum.net - * @copyright © 2003 seasonfive. All rights reserved - * @version $Revision: 1.7 $ + * @copyright � 2003 seasonfive. All rights reserved + * @version $Id$ * @see BaseParamFilterReader * @package phing.filters */ @@ -154,4 +154,4 @@ class TailFilter extends BaseParamFilterReader implements ChainableReader { } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/TidyFilter.php b/buildscripts/phing/classes/phing/filters/TidyFilter.php index 10d75fc4..22abcee5 100644..100755 --- a/buildscripts/phing/classes/phing/filters/TidyFilter.php +++ b/buildscripts/phing/classes/phing/filters/TidyFilter.php @@ -1,6 +1,6 @@ <?php /* - * $Id: TidyFilter.php,v 1.2 2005/12/08 19:15:20 hlellelid Exp $ + * $Id: a612fea7722441639c6dfdc69b43ad65ec02652f $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -35,56 +35,56 @@ include_once 'phing/filters/ChainableReader.php'; * </pre> * * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.2 $ $Date: 2005/12/08 19:15:20 $ + * @version $Id$ * @package phing.filters */ class TidyFilter extends BaseParamFilterReader implements ChainableReader { - - /** @var string Encoding of resulting document. */ - private $encoding = 'utf8'; + + /** @var string Encoding of resulting document. */ + private $encoding = 'utf8'; /** @var array Parameter[] */ - private $configParameters = array(); + private $configParameters = array(); - /** - * Set the encoding for resulting (X)HTML document. - * @param string $v - */ - public function setEncoding($v) { - $this->encoding = $v; - } - - /** - * Sets the config params. - * @param array Parameter[] - * @see chain() - */ - public function setConfigParameters($params) - { - $this->configParameters = $params; - } - - /** - * Adds a <config> element (which is a Parameter). - * @return Parameter - */ - public function createConfig() { - $num = array_push($this->configParameters, new Parameter()); + /** + * Set the encoding for resulting (X)HTML document. + * @param string $v + */ + public function setEncoding($v) { + $this->encoding = $v; + } + + /** + * Sets the config params. + * @param array Parameter[] + * @see chain() + */ + public function setConfigParameters($params) + { + $this->configParameters = $params; + } + + /** + * Adds a <config> element (which is a Parameter). + * @return Parameter + */ + public function createConfig() { + $num = array_push($this->configParameters, new Parameter()); return $this->configParameters[$num-1]; - } - - /** - * Converts the Parameter objects being used to store configuration into a simle assoc array. - * @return array - */ - private function getDistilledConfig() { - $config = array(); - foreach($this->configParameters as $p) { - $config[$p->getName()] = $p->getValue(); - } - return $config; - } - + } + + /** + * Converts the Parameter objects being used to store configuration into a simle assoc array. + * @return array + */ + private function getDistilledConfig() { + $config = array(); + foreach($this->configParameters as $p) { + $config[$p->getName()] = $p->getValue(); + } + return $config; + } + /** * Reads input and returns Tidy-filtered output. * @@ -94,29 +94,29 @@ class TidyFilter extends BaseParamFilterReader implements ChainableReader { * during reading */ function read($len = null) { - - if (!class_exists('Tidy')) { - throw new BuildException("You must enable the 'tidy' extension in your PHP configuration in order to use the Tidy filter."); - } - - if ( !$this->getInitialized() ) { + + if (!class_exists('Tidy')) { + throw new BuildException("You must enable the 'tidy' extension in your PHP configuration in order to use the Tidy filter."); + } + + if ( !$this->getInitialized() ) { $this->_initialize(); $this->setInitialized(true); } - + $buffer = $this->in->read($len); if($buffer === -1) { return -1; } - - $config = $this->getDistilledConfig(); - - $tidy = new Tidy(); - $tidy->parseString($buffer, $config, $this->encoding); - $tidy->cleanRepair(); + + $config = $this->getDistilledConfig(); + + $tidy = new Tidy(); + $tidy->parseString($buffer, $config, $this->encoding); + $tidy->cleanRepair(); - return tidy_get_output($tidy); - + return tidy_get_output($tidy); + } @@ -131,32 +131,32 @@ class TidyFilter extends BaseParamFilterReader implements ChainableReader { */ public function chain(Reader $reader) { $newFilter = new TidyFilter($reader); - $newFilter->setConfigParameters($this->configParameters); - $newFilter->setEncoding($this->encoding); + $newFilter->setConfigParameters($this->configParameters); + $newFilter->setEncoding($this->encoding); $newFilter->setProject($this->getProject()); return $newFilter; } - - /** + + /** * Initializes any parameters (e.g. config options). * This method is only called when this filter is used through a <filterreader> tag in build file. */ private function _initialize() { $params = $this->getParameters(); - if ($params) { - foreach($params as $param) { - if ($param->getType() == "config") { - $this->configParameters[] = $param; - } else { - - if ($param->getName() == "encoding") { - $this->setEncoding($param->getValue()); - } - - } - - } - } + if ($params) { + foreach($params as $param) { + if ($param->getType() == "config") { + $this->configParameters[] = $param; + } else { + + if ($param->getName() == "encoding") { + $this->setEncoding($param->getValue()); + } + + } + + } + } } } diff --git a/buildscripts/phing/classes/phing/filters/TranslateGettext.php b/buildscripts/phing/classes/phing/filters/TranslateGettext.php index f71823e3..b2a4264c 100644..100755 --- a/buildscripts/phing/classes/phing/filters/TranslateGettext.php +++ b/buildscripts/phing/classes/phing/filters/TranslateGettext.php @@ -1,7 +1,7 @@ <?php /* - * $Id: TranslateGettext.php,v 1.11 2005/12/08 15:59:56 hlellelid Exp $ + * $Id: 7dc28b63ed7f57bcf86d92f2b669bd386c2076a6 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -39,7 +39,7 @@ include_once 'phing/filters/ChainableReader.php'; * </pre> * * @author Hans Lellelid <hans@xmpl.org> - * @version $Revision: 1.11 $ $Date: 2005/12/08 15:59:56 $ + * @version $Id$ * @access public * @see BaseFilterReader * @package phing.filters @@ -140,7 +140,7 @@ class TranslateGettext extends BaseParamFilterReader implements ChainableReader protected function initEnvironment() { $this->storedLocale = getenv("LANG"); - $this->log("Setting locale to " . $this->locale, PROJECT_MSG_DEBUG); + $this->log("Setting locale to " . $this->locale, Project::MSG_DEBUG); putenv("LANG=".$this->locale); $ret = setlocale(LC_ALL, $this->locale); if ($ret === false) { @@ -150,7 +150,7 @@ class TranslateGettext extends BaseParamFilterReader implements ChainableReader throw new BuildException($msg); } - $this->log("Binding domain '".$this->domain."' to " . $this->dir, PROJECT_MSG_DEBUG); + $this->log("Binding domain '".$this->domain."' to " . $this->dir, Project::MSG_DEBUG); bindtextdomain($this->domain, $this->dir->getAbsolutePath()); textdomain($this->domain); } @@ -181,7 +181,7 @@ class TranslateGettext extends BaseParamFilterReader implements ChainableReader $charbefore = $matches[1]; $msgid = $matches[2]; $translated = gettext($msgid); - $this->log("Translating \"$msgid\" => \"$translated\"", PROJECT_MSG_DEBUG); + $this->log("Translating \"$msgid\" => \"$translated\"", Project::MSG_DEBUG); return $charbefore . '"' . $translated . '"'; } @@ -231,7 +231,7 @@ class TranslateGettext extends BaseParamFilterReader implements ChainableReader $matches = array(); if (preg_match('/([^\w]|^)(gettext\([^\)]+\))/', $buffer, $matches)) { - $this->log("Unable to perform translation on: " . $matches[2], PROJECT_MSG_WARN); + $this->log("Unable to perform translation on: " . $matches[2], Project::MSG_WARN); } $this->restoreEnvironment(); @@ -282,4 +282,4 @@ class TranslateGettext extends BaseParamFilterReader implements ChainableReader } } -?> + diff --git a/buildscripts/phing/classes/phing/filters/XincludeFilter.php b/buildscripts/phing/classes/phing/filters/XincludeFilter.php new file mode 100644 index 00000000..e2b3cd00 --- /dev/null +++ b/buildscripts/phing/classes/phing/filters/XincludeFilter.php @@ -0,0 +1,176 @@ +<?php + +/* + * $Id: 6c47e03d52cf26c183b05e347dac83735dd8c8dd $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +include_once 'phing/filters/BaseParamFilterReader.php'; +include_once 'phing/filters/ChainableReader.php'; + +/** + * Applies Xinclude parsing to incoming text. + * + * Uses PHP DOM XML support + * + * @author Bill Karwin <bill@karwin.com> + * @version $Id: 6c47e03d52cf26c183b05e347dac83735dd8c8dd $ + * @see FilterReader + * @package phing.filters + */ +class XincludeFilter extends BaseParamFilterReader implements ChainableReader { + + private $basedir = null; + + /** + * @var bool + */ + private $processed = false; + + /** + * Whether to resolve entities. + * + * @var bool + * + * @since 2.4 + */ + private $resolveExternals = false; + + /** + * Whether to resolve entities. + * + * @param $resolveExternals + * + * @since 2.4 + */ + public function setResolveExternals($resolveExternals) + { + $this->resolveExternals = (bool)$resolveExternals; + } + + /** + * @return bool + * + * @since 2.4 + */ + public function getResolveExternals() + { + return $this->resolveExternals; + } + + public function setBasedir(PhingFile $dir) + { + $this->basedir = $dir; + } + + public function getBasedir() + { + return $this->basedir; + } + + /** + * Reads stream, applies XSLT and returns resulting stream. + * @return string transformed buffer. + * @throws BuildException - if XSLT support missing, if error in xslt processing + */ + function read($len = null) { + + if (!class_exists('DomDocument')) { + throw new BuildException("Could not find the DomDocument class. Make sure PHP has been compiled/configured to support DOM XML."); + } + + if ($this->processed === true) { + return -1; // EOF + } + + // Read XML + $_xml = null; + while ( ($data = $this->in->read($len)) !== -1 ) + $_xml .= $data; + + if ($_xml === null ) { // EOF? + return -1; + } + + if (empty($_xml)) { + $this->log("XML file is empty!", Project::MSG_WARN); + return ''; + } + + $this->log("Transforming XML " . $this->in->getResource() . " using Xinclude ", Project::MSG_VERBOSE); + + $out = ''; + try { + $out = $this->process($_xml); + $this->processed = true; + } catch (IOException $e) { + throw new BuildException($e); + } + + return $out; + } + + /** + * Try to process the Xinclude transformation + * + * @param string XML to process. + * + * @throws BuildException On errors + */ + protected function process($xml) { + + if ($this->basedir) { + $cwd = getcwd(); + chdir($this->basedir); + } + + // Create and setup document. + $xmlDom = new DomDocument(); + $xmlDom->resolveExternals = $this->resolveExternals; + + $xmlDom->loadXML($xml); + + $xmlDom->xinclude(); + + if ($this->basedir) { + chdir($cwd); + } + + return $xmlDom->saveXML(); + } + + /** + * Creates a new XincludeFilter using the passed in + * Reader for instantiation. + * + * @param Reader A Reader object providing the underlying stream. + * Must not be <code>null</code>. + * + * @return Reader A new filter based on this configuration, but filtering + * the specified reader + */ + function chain(Reader $reader) { + $newFilter = new XincludeFilter($reader); + $newFilter->setProject($this->getProject()); + $newFilter->setBasedir($this->getBasedir()); + return $newFilter; + } + +} + + diff --git a/buildscripts/phing/classes/phing/filters/XsltFilter.php b/buildscripts/phing/classes/phing/filters/XsltFilter.php index 0b8c4e6f..8866bff7 100644 --- a/buildscripts/phing/classes/phing/filters/XsltFilter.php +++ b/buildscripts/phing/classes/phing/filters/XsltFilter.php @@ -1,7 +1,7 @@ <?php /* - * $Id: XsltFilter.php,v 1.16 2005/12/07 20:05:01 hlellelid Exp $ + * $Id: 057af49d450e4c137127acc0f5331368e7a76183 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -31,7 +31,7 @@ include_once 'phing/filters/ChainableReader.php'; * @author Hans Lellelid <hans@velum.net> * @author Yannick Lecaillez <yl@seasonfive.com> * @author Andreas Aderhold <andi@binarycloud.com> - * @version $Revision: 1.16 $ + * @version $Id: 057af49d450e4c137127acc0f5331368e7a76183 $ * @see FilterReader * @package phing.filters */ @@ -61,6 +61,26 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { private $html = false; /** + * Whether to resolve entities in the XML document (see + * {@link http://www.php.net/manual/en/class.domdocument.php#domdocument.props.resolveexternals} + * for more details). + * + * @var bool + * + * @since 2.4 + */ + private $resolveDocumentExternals = false; + + /** + * Whether to resolve entities in the stylesheet. + * + * @var bool + * + * @since 2.4 + */ + private $resolveStylesheetExternals = false; + + /** * Create new XSLT Param object, to handle the <param/> nested element. * @return XSLTParam */ @@ -121,6 +141,46 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { } /** + * Whether to resolve entities in document. + * + * @param bool $resolveExternals + * + * @since 2.4 + */ + function setResolveDocumentExternals($resolveExternals) { + $this->resolveDocumentExternals = (bool)$resolveExternals; + } + + /** + * @return bool + * + * @since 2.4 + */ + function getResolveDocumentExternals() { + return $this->resolveDocumentExternals; + } + + /** + * Whether to resolve entities in stylesheet. + * + * @param bool $resolveExternals + * + * @since 2.4 + */ + function setResolveStylesheetExternals($resolveExternals) { + $this->resolveStylesheetExternals = (bool)$resolveExternals; + } + + /** + * @return bool + * + * @since 2.4 + */ + function getResolveStylesheetExternals() { + return $this->resolveStylesheetExternals; + } + + /** * Reads stream, applies XSLT and returns resulting stream. * @return string transformed buffer. * @throws BuildException - if XSLT support missing, if error in xslt processing @@ -150,7 +210,7 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { } if(empty($_xml)) { - $this->log("XML file is empty!", PROJECT_MSG_WARN); + $this->log("XML file is empty!", Project::MSG_WARN); return ''; // return empty string, don't attempt to apply XSLT } @@ -159,7 +219,7 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { $xslFr = new FileReader($this->xslFile); $xslFr->readInto($_xsl); - $this->log("Tranforming XML " . $this->in->getResource() . " using style " . $this->xslFile->getPath(), PROJECT_MSG_VERBOSE); + $this->log("Tranforming XML " . $this->in->getResource() . " using style " . $this->xslFile->getPath(), Project::MSG_VERBOSE); $out = ''; try { @@ -185,8 +245,13 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { $processor = new XSLTProcessor(); - $xmlDom = new DOMDocument(); - $xslDom = new DOMDocument(); + // Create and setup document. + $xmlDom = new DOMDocument(); + $xmlDom->resolveExternals = $this->resolveDocumentExternals; + + // Create and setup stylesheet. + $xslDom = new DOMDocument(); + $xslDom->resolveExternals = $this->resolveStylesheetExternals; if ($this->html) { $xmlDom->loadHTML($xml); @@ -201,13 +266,16 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { // ignoring param "type" attrib, because // we're only supporting direct XSL params right now foreach($this->xsltParams as $param) { - $this->log("Setting XSLT param: " . $param->getName() . "=>" . $param->getExpression(), PROJECT_MSG_DEBUG); + $this->log("Setting XSLT param: " . $param->getName() . "=>" . $param->getExpression(), Project::MSG_DEBUG); $processor->setParameter(null, $param->getName(), $param->getExpression()); } - $result = $processor->transformToXML($xmlDom); + $errorlevel = error_reporting(); + error_reporting($errorlevel & ~E_WARNING); + @$result = $processor->transformToXML($xmlDom); + error_reporting($errorlevel); - if ( !$result ) { + if (false === $result) { //$errno = xslt_errno($processor); //$err = xslt_error($processor); throw new BuildException("XSLT Error"); @@ -262,6 +330,8 @@ class XsltFilter extends BaseParamFilterReader implements ChainableReader { /** * Class that holds an XSLT parameter. + * + * @package phing.filters */ class XSLTParam { @@ -286,6 +356,28 @@ class XSLTParam { } /** + * Sets expression value (alias to the setExpression()) method. + * + * @param string $v + * @see setExpression() + */ + public function setValue($v) + { + $this->setExpression($v); + } + + /** + * Gets expression value (alias to the getExpression()) method. + * + * @param string $v + * @see getExpression() + */ + public function getValue() + { + return $this->getExpression(); + } + + /** * Sets expression value. * @param string $expr */ @@ -314,4 +406,3 @@ class XSLTParam { } } -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/filters/util/ChainReaderHelper.php b/buildscripts/phing/classes/phing/filters/util/ChainReaderHelper.php index 80508a82..c465d0a1 100644..100755 --- a/buildscripts/phing/classes/phing/filters/util/ChainReaderHelper.php +++ b/buildscripts/phing/classes/phing/filters/util/ChainReaderHelper.php @@ -1,6 +1,6 @@ <?php /* - * $Id: ChainReaderHelper.php,v 1.8 2005/02/27 20:52:09 mrook Exp $ + * $Id: c1709ddb9da44ce62fbe072c61d29dba4814e3f6 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -61,7 +61,7 @@ include_once 'phing/filters/ChainableReader.php'; * TODO: Implement the classPath feature. * * @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a> - * @version $Revision: 1.8 $ $Date: 2005/02/27 20:52:09 $ + * @version $Id$ * @access public * @package phing.filters.util */ @@ -181,4 +181,3 @@ class ChainReaderHelper { } -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/filters/util/IniFileTokenReader.php b/buildscripts/phing/classes/phing/filters/util/IniFileTokenReader.php index 34bc5943..f47e155c 100644..100755 --- a/buildscripts/phing/classes/phing/filters/util/IniFileTokenReader.php +++ b/buildscripts/phing/classes/phing/filters/util/IniFileTokenReader.php @@ -1,6 +1,6 @@ <?php /* - * $Id: IniFileTokenReader.php,v 1.7 2005/05/26 13:10:51 mrook Exp $ + * $Id: e709765b4c0c1be330183f462ab527fa8354b555 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -27,7 +27,7 @@ include_once 'phing/filters/ReplaceTokens.php'; // For class Token * Class that allows reading tokens from INI files. * * @author Manuel Holtgewe - * @version $Revision: 1.7 $ + * @version $Id$ * @package phing.filters.util */ class IniFileTokenReader extends TokenReader { @@ -49,6 +49,7 @@ class IniFileTokenReader extends TokenReader { * Reads the next token from the INI file * * @throws IOException On error + * @return Token */ function readToken() { if ($this->file === null) { @@ -93,4 +94,4 @@ class IniFileTokenReader extends TokenReader { } } -?> + |