source: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerTransform.php @ 18220

Revision 18220, 3.1 KB checked in by yokkuns, 15 years ago (diff)

#149 ロガークラス作成

Line 
1<?php
2/**
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements.  See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 *
19 * @package log4php
20 * @subpackage helpers
21 */
22
23/**
24 * @ignore
25 */
26if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
27 
28define('LOG4PHP_LOGGER_TRANSFORM_CDATA_START',          '<![CDATA[');
29define('LOG4PHP_LOGGER_TRANSFORM_CDATA_END',            ']]>');
30define('LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END',     ']]&gt;');
31define('LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END',   
32    LOG4PHP_LOGGER_TRANSFORM_CDATA_END .
33    LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END .
34    LOG4PHP_LOGGER_TRANSFORM_CDATA_START
35);
36
37/**
38 * Utility class for transforming strings.
39 *
40 * @author  Marco Vassura
41 * @package log4php
42 * @subpackage helpers
43 * @since 0.7
44 */
45class LoggerTransform {
46
47    /**
48    * This method takes a string which may contain HTML tags (ie,
49    * &lt;b&gt;, &lt;table&gt;, etc) and replaces any '&lt;' and '&gt;'
50    * characters with respective predefined entity references.
51    *
52    * @param string $input The text to be converted.
53    * @return string The input string with the characters '&lt;' and '&gt;' replaced with
54    *                &amp;lt; and &amp;gt; respectively.
55    * @static 
56    */
57    function escapeTags($input)
58    {
59        //Check if the string is null or zero length -- if so, return
60        //what was sent in.
61
62        if(empty($input))
63            return $input;
64
65        //Use a StringBuffer in lieu of String concatenation -- it is
66        //much more efficient this way.
67
68        return htmlspecialchars($input, ENT_NOQUOTES);
69    }
70
71    /**
72    * Ensures that embeded CDEnd strings (]]&gt;) are handled properly
73    * within message, NDC and throwable tag text.
74    *
75    * @param string $buf    String holding the XML data to this point.  The
76    *                       initial CDStart (<![CDATA[) and final CDEnd (]]>)
77    *                       of the CDATA section are the responsibility of
78    *                       the calling method.
79    * @param string &str    The String that is inserted into an existing
80    *                       CDATA Section within buf.
81    * @static 
82    */
83    function appendEscapingCDATA(&$buf, $str)
84    {
85        if(empty($str))
86            return;
87   
88        $rStr = str_replace(
89            LOG4PHP_LOGGER_TRANSFORM_CDATA_END,
90            LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END,
91            $str
92        );
93        $buf .= $rStr;
94    }
95}
Note: See TracBrowser for help on using the repository browser.