. * * $Id: SettingsDocument.php 136 2007-03-02 18:02:29Z nmarkgraf $ */ require_once 'OpenDocumentPHP/util/AbstractDocument.php'; /** * SettingsDocument class. * * OpenDocumentPHP does not support the settings document right now. But it is in * the OpenDocument documentation, so we have build a wrapper class for it. * * Because of that, no real functionality is added. Feel free to change it. ;-) * * @author Norman Markgraf (nmarkgraf(at)user.sourceforge.net) * @copyright Copyright in 2006, 2007 by The OpenDocumentPHP Team * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0. * @version $Revision: 136 $ * @package OpenDocumentPHP * @subpackage settings * @since 0.5.0 - 08. Feb. 2007 */ class SettingsDocument extends AbstractDocument { /** * Root element of the settings DOM document. * * @var DOMElement * @access private * @since 0.5.0 - 08. Feb. 2007 */ private $settings; /** * Constructor method. * * We construct an empty settings document here. It should look like: * * * * * * * * This is in general not a valid document, because the tag needs * some children (one or more config items). If there are no such children the * {@link saveXML()} method will remove the tag to match the * RelaxNG specification. * So currently the saved settings.xml should look more like: * * * * * * @since 0.5.0 - 08. Feb. 2007 */ function __construct() { parent :: __construct('office:document-settings'); /* * create a main (not root) element ( ... ) */ $this->settings = $this->createElementNS(self :: OFFICE, 'office:settings'); /* * and add it to the document root. This may be wrong, if we did not add * any further config items to the settings document. But we will correct this * later in the saveXML method. */ $this->root->appendChild($this->settings); } /** * Save the needed parts of the settings.xml as a XML. If we do not have * any config items in th settings document, we remove anything and leave * just the skeleton. * * @access private * @since 0.5.3 - 09. Jul. 2007 */ function saveXML() { /* * We must check if this->settings has any children, if not we *must* remove it from the tree. */ if ( !$this->settings->hasChildNodes() ) { $this->root->removeChild( $this->settings ); } /* * Now we can do the inhereted stuff. */ return parent::saveXML(); } /** * Loads a settings document into this SettingsDocument object. * * @access public * @since 0.5.2 - 22. Feb. 2007 */ function loadXML($source) { $ret = parent::loadXML($source); if ($ret === TRUE) { // We need to set $this->meta and $this->root !! $this->initXpath(); // We need to set $this->meta and $this->root !! $this->root = $this->documentElement; $result = $this->xpath->query('/office:document-settings/office:settings'); $tmp = $result; if ($tmp->length == 1) { $this->settings = $tmp->item( 0 ); } else { // This should never happend! $ret = FALSE; } } return $ret; } } ?>