~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/PHPExcel/PHPExcel/Shared/XMLWriter.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHPExcel
 
4
 *
 
5
 * Copyright (c) 2006 - 2009 PHPExcel
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 *
 
21
 * @category   PHPExcel
 
22
 * @package    PHPExcel_Shared
 
23
 * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
 
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 
25
 * @version    1.7.0, 2009-08-10
 
26
 */
 
27
 
 
28
if (!defined('DATE_W3C')) {
 
29
  define('DATE_W3C', 'Y-m-d\TH:i:sP');
 
30
}
 
31
 
 
32
/**
 
33
 * PHPExcel_Shared_XMLWriter
 
34
 *
 
35
 * @category   PHPExcel
 
36
 * @package    PHPExcel_Shared
 
37
 * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
 
38
 */
 
39
class PHPExcel_Shared_XMLWriter {
 
40
        /** Temporary storage method */
 
41
        const STORAGE_MEMORY    = 1;
 
42
        const STORAGE_DISK              = 2;
 
43
 
 
44
        /**
 
45
         * Internal XMLWriter
 
46
         *
 
47
         * @var XMLWriter
 
48
         */
 
49
        private $_xmlWriter;
 
50
 
 
51
        /**
 
52
         * Temporary filename
 
53
         *
 
54
         * @var string
 
55
         */
 
56
        private $_tempFileName = '';
 
57
 
 
58
        /**
 
59
         * Create a new PHPExcel_Shared_XMLWriter instance
 
60
         *
 
61
         * @param int           $pTemporaryStorage                      Temporary storage location
 
62
         * @param string        $pTemporaryStorageFolder        Temporary storage folder
 
63
         */
 
64
    public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
 
65
        // Create internal XMLWriter
 
66
        $this->_xmlWriter = new XMLWriter();
 
67
 
 
68
        // Open temporary storage
 
69
        if ($pTemporaryStorage == self::STORAGE_MEMORY) {
 
70
                $this->_xmlWriter->openMemory();
 
71
        } else {
 
72
                // Create temporary filename
 
73
                $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
 
74
 
 
75
                // Open storage
 
76
                if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
 
77
                        // Fallback to memory...
 
78
                        $this->_xmlWriter->openMemory();
 
79
                }
 
80
        }
 
81
 
 
82
        // Set default values
 
83
        $this->_xmlWriter->setIndent(true);
 
84
    }
 
85
 
 
86
    /**
 
87
     * Destructor
 
88
     */
 
89
    public function __destruct() {
 
90
        // Desctruct XMLWriter
 
91
        unset($this->_xmlWriter);
 
92
 
 
93
        // Unlink temporary files
 
94
        if ($this->_tempFileName != '') {
 
95
                @unlink($this->_tempFileName);
 
96
        }
 
97
    }
 
98
 
 
99
    /**
 
100
     * Get written data
 
101
     *
 
102
     * @return $data
 
103
     */
 
104
    public function getData() {
 
105
        if ($this->_tempFileName == '') {
 
106
                return $this->_xmlWriter->outputMemory(true);
 
107
        } else {
 
108
                $this->_xmlWriter->flush();
 
109
                return file_get_contents($this->_tempFileName);
 
110
        }
 
111
    }
 
112
 
 
113
    /**
 
114
     * Catch function calls (and pass them to internal XMLWriter)
 
115
     *
 
116
     * @param unknown_type $function
 
117
     * @param unknown_type $args
 
118
     */
 
119
    public function __call($function, $args) {
 
120
        try {
 
121
                @call_user_func_array(array($this->_xmlWriter, $function), $args);
 
122
        } catch (Exception $ex) {
 
123
                // Do nothing!
 
124
        }
 
125
    }
 
126
 
 
127
    /**
 
128
     * Fallback method for writeRaw, introduced in PHP 5.2
 
129
     *
 
130
     * @param string $text
 
131
     * @return string
 
132
     */
 
133
    public function writeRaw($text)
 
134
    {
 
135
        if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
 
136
            return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
 
137
        }
 
138
 
 
139
        return $this->text($text);
 
140
    }
 
141
}