OpenDocumentPHP
[ class tree: OpenDocumentPHP ] [ index: OpenDocumentPHP ] [ all elements ]

Source for file OpenDocumentAbstract.php

Documentation is available at OpenDocumentAbstract.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /*
  4.  * Created on 04.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  5.  *
  6.  * PHP versions 5.2 or better.
  7.  *
  8.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  9.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  10.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  11.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  12.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  13.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  14.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  15.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  16.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  18.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19.  *
  20.  * This software consists of voluntary contributions made by many individuals
  21.  * and is licensed under the GPL. For more information please see
  22.  * <http://opendocumentphp.org>.
  23.  *
  24.  * $Id: OpenDocumentAbstract.php 182 2007-06-11 13:32:34Z nmarkgraf $
  25.  */
  26. require_once 'OpenDocumentPHP/util/AbstractDocument.php';
  27. require_once 'OpenDocumentPHP/util/Fragment.php';
  28. require_once 'OpenDocumentPHP/util/ElementFragment.php';
  29. require_once 'OpenDocumentPHP/global/FontFaceDeclFragment.php';
  30. require_once 'OpenDocumentPHP/global/AutomaticStylesFragment.php';
  31. require_once 'OpenDocumentPHP/content/ContentDocument.php';
  32. require_once 'OpenDocumentPHP/meta/MetaDocument.php';
  33. require_once 'OpenDocumentPHP/styles/StylesDocument.php';
  34. require_once 'OpenDocumentPHP/settings/SettingsDocument.php';
  35. require_once 'OpenDocumentPHP/OpenDocumentArchive.php';
  36. /**
  37.  * OpenDocumentAbstract class.
  38.  *
  39.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  40.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  41.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  42.  * @version        $Revision: 182 $
  43.  * @package        OpenDocumentPHP
  44.  * @link           http://www.oasis-open.org/committees/download.php/12572/OpenDocument-v1.0-os.pdf Open Document Format for Office Applications Release 1.0
  45.  * @link         http://www.oasis-open.org/committees/download.php/19274/OpenDocument-v1.0ed2-cs1.pdf Open Document Format for Office Applications Release 1.0 2nd Edition
  46.  * @link         http://www.oasis-open.org/committees/download.php/20847/OpenDocument-v1.1-cs1.pdf Open Document Format for Office Applications Release 1.1
  47.  * @since         0.5.0 - 08.02.2007
  48.  */
  49. abstract class OpenDocumentAbstract extends OpenDocumentArchive {
  50.     /**
  51.      * @var         ContentDocument 
  52.      * @access        protected
  53.      * @since         0.5.0 - 08.02.2007
  54.      */
  55.     protected $content;
  56.     /**
  57.      * @var         StylesDocument 
  58.      * @access        protected
  59.      * @since         0.5.0 - 08.02.2007
  60.      */
  61.     protected $styles;
  62.     /**
  63.      * @var         MetaDocument 
  64.      * @access        protected
  65.      * @since         0.5.0 - 08.02.2007
  66.      */
  67.     protected $meta;
  68.     /**
  69.      * @var         SettingsDocument 
  70.      * @access        protected
  71.      * @since         0.5.0 - 08.02.2007
  72.      */
  73.     protected $settings;
  74.     /**
  75.      *
  76.      * @access         protected
  77.      * @since         0.5.0 - 08.02.2007
  78.      */
  79.     protected function init({
  80.         $this->content = new ContentDocument();
  81.         $this->meta = new MetaDocument();
  82.         $this->styles = new StylesDocument();
  83.         $this->settings = new SettingsDocument();
  84.     }
  85.     /**
  86.      *
  87.      * @access         public
  88.      * @since         0.5.0 - 08.02.2007
  89.      */
  90.     function getMeta({
  91.         return $this->meta;
  92.     }
  93.     /**
  94.      *
  95.      * @access         public
  96.      * @since         0.5.0 - 08.02.2007
  97.      */
  98.     function getBody({
  99.         return $this->getContent()->getBody();
  100.     }
  101.     /**
  102.      *
  103.      * @access         public
  104.      * @since         0.5.0 - 08.02.2007
  105.      */
  106.     function getStyles({
  107.         return $this->styles;
  108.     }
  109.     /**
  110.      *
  111.      * @access         public
  112.      * @since         0.5.0 - 08.02.2007
  113.      */
  114.     function getContent({
  115.         return $this->content;
  116.     }
  117.     /**
  118.      *
  119.      * @access         public
  120.      * @since         0.5.0 - 08.02.2007
  121.      */
  122.     function close({
  123.         // append content.xml
  124.         $this->addFromString('content.xml'$this->content->saveXML()'text/xml');
  125.         // append meta.xml
  126.         $this->addFromString('meta.xml'$this->meta->saveXML()'text/xml');
  127.         // append settings.xml
  128.         $this->addFromString('settings.xml'$this->settings->saveXML()'text/xml');
  129.         // append styles.xml
  130.         $this->addFromString('styles.xml'$this->styles->saveXML()'text/xml');
  131.         parent :: close();
  132.     }
  133.     /**
  134.      * Load meta document.
  135.      *
  136.      * @access         protected
  137.      * @since         0.5.2 - 02.03.2007
  138.      */
  139.     protected function loadMeta({
  140.         return $this->meta->loadXML($this->getFromName('meta.xml'));
  141.     }
  142.     /**
  143.      * Load settings document.
  144.      *
  145.      * @access         protected
  146.      * @since         0.5.2 - 02.03.2007
  147.      */
  148.     protected function loadSettings({
  149.         return $this->settings->loadXML($this->getFromName('settings.xml'));
  150.     }
  151.     /**
  152.      * Load content document.
  153.      *
  154.      * @access         protected
  155.      * @since         0.5.2 - 02.03.2007
  156.      */
  157.     protected function loadContent({
  158.         return $this->content->loadXML($this->getFromName('content.xml'));
  159.     }
  160.     /**
  161.      * Load styles document.
  162.      *
  163.      * @access         protected
  164.      * @since         0.5.2 - 02.03.2007
  165.      */
  166.     protected function loadStyles({
  167.         return $this->styles->loadXML($this->getFromName('styles.xml'));
  168.     }
  169.     /**
  170.      * Open an OpenDocument and read the meta.xml and settings data.
  171.      *
  172.      * @todo         content.xml and styles.xml should be loaded too.
  173.      * @access         public
  174.      * @since         0.5.2 - 22.02.2007
  175.      */
  176.     function open($filename$flags 0$mimetype ''{
  177.         $this->init();
  178.         $ret parent :: open($filename$flags$mimetype);
  179.         if (($flags && self :: CREATE0{
  180.             // New!
  181.         else {
  182.             // Load old data ...
  183.             if ($ret === true{
  184.                 $ret $this->loadMeta();
  185.                 if ($ret === true{
  186.                     $ret $this->loadSettings();
  187.                     if ($ret === true{
  188.                         $ret $this->loadContent();
  189.                         if ($ret === true{
  190.                             $ret $this->loadStyles();
  191.                         }
  192.                     }
  193.                 }
  194.             }
  195.         }
  196.         return $ret;
  197.     }
  198. }
  199. ?>

Documentation generated on Tue, 12 Jun 2007 10:00:21 +0200 by phpDocumentor 1.3.2