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

Source for file OpenDocumentAbstract.php

Documentation is available at OpenDocumentAbstract.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 04. Jan. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * OpenDocumentAbstract class file.
  11.  * 
  12.  * PHP versions 5
  13.  *   
  14.  * LICENSE:
  15.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  *
  27.  * This software consists of voluntary contributions made by many individuals
  28.  * and is licensed under the GPL. For more information please see
  29.  * <http://opendocumentphp.org>.
  30.  * 
  31.  * $Id: OpenDocumentAbstract.php 256 2007-08-01 14:16:10Z nmarkgraf $
  32.  * 
  33.  * @category    File Formats
  34.  * @package        OpenDocumentPHP
  35.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  36.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  37.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  38.  * @version        SVN: $Id: OpenDocumentAbstract.php 256 2007-08-01 14:16:10Z nmarkgraf $
  39.  * @link           http://opendocumentphp.org
  40.  * @since         0.5.0 - 08. Feb. 2007
  41.  */
  42.  
  43. /**
  44.  *
  45.  */
  46. require_once 'OpenDocumentPHP/util/AbstractDocument.php';
  47. require_once 'OpenDocumentPHP/util/Fragment.php';
  48. require_once 'OpenDocumentPHP/util/ODPElement.php';
  49. require_once 'OpenDocumentPHP/global/FontFaceDeclFragment.php';
  50. require_once 'OpenDocumentPHP/global/AutomaticStylesFragment.php';
  51. require_once 'OpenDocumentPHP/content/ContentDocument.php';
  52. require_once 'OpenDocumentPHP/meta/MetaDocument.php';
  53. require_once 'OpenDocumentPHP/styles/StylesDocument.php';
  54. require_once 'OpenDocumentPHP/settings/SettingsDocument.php';
  55. require_once 'OpenDocumentPHP/OpenDocumentArchive.php';
  56.  
  57. /**
  58.  * OpenDocumentAbstract class.
  59.  *
  60.  * @category    File Formats
  61.  * @package        OpenDocumentPHP
  62.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  63.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  64.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  65.  * @version     Release: @package_version@
  66.  * @link           http://opendocumentphp.org
  67.  * @since         0.5.0 - 08. Feb. 2007
  68.  * @link           http://www.oasis-open.org/committees/download.php/12572/OpenDocument-v1.0-os.pdf Open Document Format for Office Applications Release 1.0
  69.  * @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
  70.  * @link         http://www.oasis-open.org/committees/download.php/20847/OpenDocument-v1.1-cs1.pdf Open Document Format for Office Applications Release 1.1
  71.  */
  72. abstract class OpenDocumentAbstract extends OpenDocumentArchive {
  73.     /**
  74.      * The content document as object.
  75.      * 
  76.      * @var         ContentDocument 
  77.      * @access        protected
  78.      * @since         0.5.0 - 08. Feb. 2007
  79.      */
  80.     protected $content;
  81.     /**
  82.      * The styles document as object.
  83.      * 
  84.      * @var         StylesDocument 
  85.      * @access        protected
  86.      * @since         0.5.0 - 08. Feb. 2007
  87.      */
  88.     protected $styles;
  89.     /**
  90.      * The meta document as object.
  91.      * 
  92.      * @var         MetaDocument 
  93.      * @access        protected
  94.      * @since         0.5.0 - 08. Feb. 2007
  95.      */
  96.     protected $meta;
  97.     /**
  98.      * The settings document as object.
  99.      * 
  100.      * @var         SettingsDocument 
  101.      * @access        protected
  102.      * @since         0.5.0 - 08. Feb. 2007
  103.      */
  104.     protected $settings;
  105.     /**
  106.      * Initialise the usual attributes of this class.
  107.      * 
  108.      * Calling this method will initialise fresh and new objects for the content,
  109.      * the meta, the styles and the settings document as part of this OpenDocument.
  110.      * 
  111.      * @access         protected
  112.      * @since         0.5.0 - 08. Feb. 2007
  113.      */
  114.     protected function init({
  115.         $this->content = new ContentDocument();
  116.         $this->meta = new MetaDocument();
  117.         $this->styles = new StylesDocument();
  118.         $this->settings = new SettingsDocument();
  119.     }
  120.     /**
  121.      * Retrieve the meta document as an object of the MetaDocument class.
  122.      * 
  123.      * @return        MetaDocument The meta document as object.
  124.      * @access         public
  125.      * @since         0.5.0 - 08. Feb. 2007
  126.      */
  127.     function getMeta({
  128.         return $this->meta;
  129.     }
  130.     /**
  131.      * Retrieve the body part of the content document as an object of the BodyFragment class.
  132.      * 
  133.      * @return        BodyFragment The body part of the content document as object.
  134.      * @access         public
  135.      * @since         0.5.0 - 08. Feb. 2007
  136.      * @deprecated  0.5.3 - 02. Jul. 2007
  137.      */
  138.     function getBody({
  139.         return $this->getContent()->getBody();
  140.     }
  141.     /**
  142.      * Retrieve the styles document as an object of the StylesDocument class.
  143.      *
  144.      * @return        StylesDocument The styles document as object.
  145.      * @access         public
  146.      * @since         0.5.0 - 08. Feb. 2007
  147.      */
  148.     function getStyles({
  149.         return $this->styles;
  150.     }
  151.     /**
  152.      * Retrieve the content document as an object of the ContentDocument class.
  153.      *
  154.      * @return        ContentDocument The meta document as object.
  155.      * @access         public
  156.      * @since         0.5.0 - 08. Feb. 2007
  157.      */
  158.     function getContent({
  159.         return $this->content;
  160.     }
  161.     /**
  162.      * Close the current OpenDocument.
  163.      *
  164.      * When ever you work with an OpenDocument, you should close it a the end.
  165.      *  
  166.      * <code>
  167.      * $text = new OpenDocumentText($fullpath);
  168.      * //... do something ...
  169.      * $text->close();
  170.      * </code>
  171.      *
  172.      * If you want to revert all modifications and do not write anything back to the archive you can
  173.      * use the first parameter of this function and set it to <b>false</b>.
  174.      * 
  175.      * <code>
  176.      * $text = new OpenDocumentText($fullpath);
  177.      * //... do something ...
  178.      * // But we do not want to write it back to the archive
  179.      * $text->close( false );
  180.      * </code>
  181.      * 
  182.      * @param        bool $write Should we write something back to the archive? - Default is <b>true</b>.
  183.      * @access         public
  184.      * @since         0.5.0 - 08. Feb. 2007
  185.      */
  186.     function close($write=true{
  187.         if ($write{
  188.             // append content.xml
  189.             $this->addFromString('content.xml'$this->content->saveXML()'text/xml');
  190.             // append meta.xml
  191.             $this->addFromString('meta.xml'$this->meta->saveXML()'text/xml');
  192.             // append settings.xml
  193.             $this->addFromString('settings.xml'$this->settings->saveXML()'text/xml');
  194.             // append styles.xml
  195.             $this->addFromString('styles.xml'$this->styles->saveXML()'text/xml');
  196.         }
  197.         parent :: close($write);
  198.     }
  199.     /**
  200.      * Load meta document.
  201.      *
  202.      * @access         protected
  203.      * @since         0.5.2 - 02. Mar. 2007
  204.      */
  205.     protected function loadMeta({
  206.         return $this->meta->loadXML($this->getFromName('meta.xml'));
  207.     }
  208.     /**
  209.      * Load settings document.
  210.      *
  211.      * @access         protected
  212.      * @since         0.5.2 - 02. Mar. 2007
  213.      */
  214.     protected function loadSettings({
  215.         return $this->settings->loadXML($this->getFromName('settings.xml'));
  216.     }
  217.     /**
  218.      * Load content document.
  219.      *
  220.      * @access         protected
  221.      * @since         0.5.2 - 02. Mar. 2007
  222.      */
  223.     protected function loadContent({
  224.         return $this->content->loadXML($this->getFromName('content.xml'));
  225.     }
  226.     /**
  227.      * Load styles document.
  228.      *
  229.      * @access         protected
  230.      * @since         0.5.2 - 02. Mar. 2007
  231.      */
  232.     protected function loadStyles({
  233.         return $this->styles->loadXML($this->getFromName('styles.xml'));
  234.     }
  235.     /**
  236.      * Open an OpenDocument and read the meta, settings, content and styles data
  237.      * out of the ususal xml files and stores them into their attributes.
  238.      *
  239.      * @param        string $filename Filename
  240.      * @param        int $flags File opening flags
  241.      * @param        string $mimetype Mimetype
  242.      * @return        bool If everything went fine, we got <b>true</b> as result, else we get <b>false</b>.
  243.      * @access         public
  244.      * @since         0.5.2 - 22. Feb. 2007
  245.      */
  246.     function open($filename$flags 0$mimetype ''{
  247.        /*
  248.         * Create all needed document classes
  249.         */
  250.         $this->init();
  251.         /*
  252.          * Try to open $filename
  253.          */
  254.         $ret parent :: open($filename$flags$mimetype);
  255.         if (($flags && self :: CREATE0{
  256.             // New!
  257.         else {
  258.             // Load old data ...
  259.             if ($ret === true{
  260.                 $ret $this->loadMeta();
  261.                 if ($ret === true{
  262.                     $ret $this->loadSettings();
  263.                     if ($ret === true{
  264.                         $ret $this->loadContent();
  265.                         if ($ret === true{
  266.                             $ret $this->loadStyles();
  267.                         }
  268.                     }
  269.                 }
  270.             }
  271.         }
  272.         return $ret;
  273.     }
  274. }
  275. ?>

Documentation generated on Wed, 18 Jun 2008 06:30:36 +0200 by phpDocumentor 1.3.2