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

Source for file SettingsDocument.php

Documentation is available at SettingsDocument.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 05. Jan. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net) 
  7.  */
  8.  
  9. /**
  10.  * SettingsDocument class file.
  11.  * 
  12.  * OpenDocumentPHP does not support the settings document right now. But it is in
  13.  * the OpenDocument documentation, so we have build a wrapper class for it.
  14.  *  
  15.  * Because of that, no real functionality is added. Feel free to change it. ;-)
  16.  *
  17.  * PHP versions 5
  18.  *   
  19.  * LICENSE:
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * This software consists of voluntary contributions made by many individuals
  33.  * and is licensed under the GPL. For more information please see
  34.  * <http://opendocumentphp.org>.
  35.  * 
  36.  * $Id: SettingsDocument.php 236 2007-07-24 07:43:40Z nmarkgraf $
  37.  *
  38.  * @category    File Formats
  39.  * @package        OpenDocumentPHP
  40.  * @subpackage    settings
  41.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  42.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  43.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  44.  * @version        SVN: $Id: SettingsDocument.php 236 2007-07-24 07:43:40Z nmarkgraf $
  45.  * @link           http://opendocumentphp.org
  46.  * @since         0.5.0 - 08. Feb. 2007
  47.  */
  48.  
  49. /**
  50.  * 
  51.  */
  52. require_once 'OpenDocumentPHP/util/AbstractDocument.php';
  53.  
  54. /**
  55.  * SettingsDocument class.
  56.  * 
  57.  * OpenDocumentPHP does not support the settings document right now. But it is in
  58.  * the OpenDocument documentation, so we have build a wrapper class for it.
  59.  *  
  60.  * Because of that, no real functionality is added. Feel free to change it. ;-)
  61.  * 
  62.  * @category    File Formats
  63.  * @package        OpenDocumentPHP
  64.  * @subpackage    settings
  65.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  66.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  67.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  68.  * @version     Release: @package_version@
  69.  * @link           http://opendocumentphp.org
  70.  * @since         0.5.0 - 08. Feb. 2007
  71.  */
  72.     /**
  73.      * Root element of the settings DOM document.
  74.      * 
  75.      * @var         DOMElement 
  76.      * @access        private
  77.      * @since         0.5.0 - 08. Feb. 2007
  78.      */
  79.     private $settings;
  80.     /**
  81.      * Constructor method.
  82.      * 
  83.      * We construct an empty settings document here. It should look like:
  84.      * <code>
  85.      *  <?xml version="1.0" encoding="UTF-8"?>
  86.      *     <office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.0">
  87.      *         <office:settings/>
  88.      *    </office:document-settings>
  89.      * </code>
  90.      * 
  91.      * This is in general not a valid document, because the <office:settings> tag needs
  92.      * some children (one or more config items). If there are no such children the
  93.      * {@link saveXML()} method will remove the <office:settings/> tag to match the
  94.      * RelaxNG specification.
  95.      * So currently the saved settings.xml should look more like:
  96.      * <code>
  97.      *  <?xml version="1.0" encoding="UTF-8"?>
  98.      *     <office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.0" /
  99.      * </code>
  100.      *       
  101.      * 
  102.      * @since         0.5.0 - 08. Feb. 2007
  103.      */
  104.     function __construct({
  105.         parent :: __construct('office:document-settings');
  106.         /*
  107.          * create a main (not root) element ( <office:settings>...</office:settings> )
  108.          */ 
  109.         $this->settings $this->createElementNS(self :: OFFICE'office:settings');
  110.         /*
  111.          * and add it to the document root. This may be wrong, if we did not add
  112.          * any further config items to the settings document. But we will correct this
  113.          * later in the saveXML method.
  114.          */
  115.         $this->root->appendChild($this->settings);
  116.     }
  117.     
  118.     /**
  119.      * Save the needed parts of the settings.xml as a XML. If we do not have
  120.      * any config items in th settings document, we remove anything and leave
  121.      * just the skeleton.
  122.      *  
  123.      * @access        private
  124.      * @since        0.5.3 - 09. Jul. 2007
  125.      */
  126.     function saveXML({
  127.         /*
  128.          * We must check if this->settings has any children, if not we *must* remove it from the tree.
  129.          */
  130.         if !$this->settings->hasChildNodes() ) {
  131.             $this->root->removeChild$this->settings );
  132.         }
  133.         /*
  134.          * Now we can do the inhereted stuff.
  135.          */
  136.         return parent::saveXML();
  137.     }
  138.     /**
  139.      * Loads a settings document into this SettingsDocument object.
  140.      * 
  141.      * @access     public
  142.      * @since     0.5.2 - 22. Feb. 2007
  143.      */
  144.     function loadXML($source{
  145.         /*
  146.          * First we load the document by the parent method
  147.          */
  148.         $ret parent::loadXML($source);
  149.         
  150.         if ($ret === TRUE{
  151.             /*
  152.              * If it was loaded correctly, we need to set up some
  153.              * local attributes. Therefore we first init the XPath stuff
  154.              */                
  155.             $this->initXpath();
  156.             /*
  157.              * Now we need the document root element to fill $this->root 
  158.              */
  159.             $this->root = $this->documentElement;
  160.             /*
  161.              * We now setup the $this->settings element... 
  162.              * First we ask XPath to give us the <office:settings> tag. 
  163.              */            
  164.             $tmp $this->xpath->query('/office:document-settings/office:settings');            
  165.             
  166.             if ($tmp->length == 1{
  167.                 /*
  168.                  * The only result is the settings tag in this case. So we can put
  169.                  * it in the $this->settings attribute.
  170.                  */
  171.                 $this->settings $tmp->item);
  172.             elseif ($tmp->length == 0{
  173.                 /*
  174.                  * We got an empty seetings document. This could happen. We need
  175.                  * to setup a <office:settings> element and add it to the document.
  176.                  * If no other config item will be added to this, the saveXML 
  177.                  * method will eliminate this empty tag.
  178.                  */
  179.                 $this->settings $this->createElementNS(self :: OFFICE'office:settings');
  180.                 $this->root->appendChild($this->settings);                
  181.             else {
  182.                 /*
  183.                  * Something strange happend and this should never occure.
  184.                  * *** EXCEPTION HANDLING ***
  185.                  */
  186.                 $ret FALSE;            
  187.             }
  188.         }
  189.         return $ret;
  190.     }
  191. }
  192. ?>

Documentation generated on Wed, 18 Jun 2008 06:31:56 +0200 by phpDocumentor 1.3.2