Source for file AbstractDocument.php
Documentation is available at AbstractDocument.php
* Created on 05.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the GPL. For more information please see
* <http://opendocumentphp.org>.
* $Id: AbstractDocument.php 161 2007-03-19 09:35:16Z nmarkgraf $
require_once 'OpenDocumentPHP/util/ODPElement.php';
require_once 'OpenDocumentPHP/styles/properties/ParagraphProperties.php';
require_once 'OpenDocumentPHP/styles/properties/TextProperties.php';
require_once 'OpenDocumentPHP/styles/DefaultStyle.php';
require_once 'OpenDocumentPHP/styles/Style.php';
* AbstractDocument class.
* @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: 161 $
* @package OpenDocumentPHP
* @since 0.5.0 - 08.02.2007
* namespace OpenDocument meta
const META = 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0';
* namespace OpenDocument office
const OFFICE = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
* namespace OpenDocument manifest
const MANIFEST = 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0';
* namespace OpenDocument style
const STYLE = 'urn:oasis:names:tc:opendocument:xmlns:style:1.0';
* namespace OpenDocument text
const TEXT = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0';
* namespace OpenDocument draw
const DRAW = 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0';
* namespace OpenDocument table
const TABLE = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0';
* namespace OpenDocument number
const NUMBER = 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0';
* namespace OpenDocument chart
const CHART = 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0';
* namespace OpenDocument form
const FORM = 'urn:oasis:names:tc:opendocument:xmlns:form:1.0';
* namespace OpenDocument config
const CONFIG = 'urn:oasis:names:tc:opendocument:xmlns:config:1.0';
* namespace OpenDocument presentation
const PRESENTATION = 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0';
* namespace OpenDocument dr3d
const DR3D = 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0';
* namespace OpenDocument animation
const ANIM = 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0';
* namespace OpenDocument script
const SCRIPT = 'urn:oasis:names:tc:opendocument:xmlns:script:1.0';
* namespace OpenDocument svg
const SVG = 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0';
* namespace OpenDocument fo (formation objects)
const FO = 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0';
* namespace OpenDocument smil
const SMIL = 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0';
const DC = 'http://purl.org/dc/elements/1.1/';
const XLINK = 'http://www.w3.org/1999/xlink';
const XFORMS = 'http://www.w3.org/2002/xforms';
const MATHML = 'http://www.w3.org/1998/Math/MathML';
* Link to the DOMElement which is the root of this DOM document.
* @since 0.5.0 - 08.02.2007
* @since 0.5.2 - 26.02.2007
* @since 0.5.0 - 08.02.2007
parent :: __construct('1.0', 'UTF-8');
$this->formatOutput = true;
// echo "config found!\n";
if ($config->canSetParameter('canonical-form', 'true')) {
$config->setParameter('canonical-form', 'true');
// echo "canonical-form setted!\n";
if ($config->canSetParameter('datatype-normalizlation', 'true')) {
$config->setParameter('datatype-normalizlation', 'true');
// echo "datatype-normalizlation setted!\n";
// I am not sure that this will work, but I try it:
$this->registerNodeClass('DOMDocument', 'AbstractDocument');
$this->registerNodeClass('DOMElement', 'ODPElement');
* Set the root Element of this document.
* @since 0.5.1 - 08.02.2007
protected function _setRoot($documentRoot = NULL) {
if (isset ($documentRoot) && $documentRoot !== 0) {
$this->root = $this->createElementNS(self :: OFFICE, $documentRoot);
$this->root->setAttributeNS(self :: OFFICE, 'office:version', '1.0');
$this->appendChild($this->root);
* Retrieve the value of an element by its namespace and tag.
* @since 0.5.0 - 08.02.2007
* @param string $namespace Namespace of the element.
* @param string $elemet Tag of the element.
* @return mixed The value of the element as string or the boolean 'false',
* if no element was found.
$nodelist = $this->getElementsByTagNameNS($namespace, $element);
if ($nodelist->length === 1) {
$retValue = $nodelist->item(0)->nodeValue;
* Dumps the internal XML tree back into a string.
* Creates an XML document from the DOM representation. This function
* is usually called after building a new DOM document from scratch.
* @since 0.5.0 - 08.02.2007
* @param DOMNode $node Use this parameter to output only a specific node
* without XML declaration rather than the entire document.
* @param int $options Additional Options. Currently only LIBXML_NOEMPTYTAG
function saveXML($node = NULL, $options = NULL) {
$this->normalizeDocument();
return parent :: saveXML($node, $options);
return parent :: saveXML($node);
return parent :: saveXML();
* This function is not needed, so we always return false!
* @since 0.5.0 - 08.02.2007
* This function is not needed, so we always return false!
* @since 0.5.0 - 08.02.2007
* This function is not needed, so we always return false!
* @since 0.5.0 - 08.02.2007
* This function is not needed, so we always return false!
* @since 0.5.0 - 08.02.2007
* Initialize xpath. You must do this before using xpath.
* @since 0.5.2 - 26.02.2007
if (!isset ($this->xpath)) {
$this->xpath = new DOMXpath($this);
$this->xpath->registerNamespace('office', self :: OFFICE);
$this->xpath->registerNamespace('meta', self :: META);
$this->xpath->registerNamespace('text', self :: TEXT);
$this->xpath->registerNamespace('dc', self :: DC);
$this->xpath->registerNamespace('xlink', self :: XLINK);
$this->xpath->registerNamespace('style', self :: STYLE);
$this->xpath->registerNamespace('draw', self :: DRAW);
$this->xpath->registerNamespace('table', self :: TABLE);
$this->xpath->registerNamespace('mathml', self :: MATHML);
* Create an DOMElement in the Office namespace with tag $tag.
* $this->createOfficeElement('document');
* will create an DOMElement like:
* <office:document xmlns:office="" />
* @param string $tag Tag of the new DOMElement
* @param string $value If seted, this is the node value.
* @since 0.5.2 - 05.03.2007
return $this->createElementNS(self :: OFFICE, 'office:' . $tag, $value);
* Create an DOMElement in the Meta namespace with tag $tag.
* @param string $tag Tag of the new DOMElement
* @param string $value If seted, this is the node value.
* @since 0.5.2 - 05.03.2007
return $this->createElementNS(self :: META, 'meta:' . $tag, $value);
* Create an DOMElement in the Meta namespace with tag $tag.
* @param string $tag Tag of the new DOMElement
* @param string $value If seted, this is the node value.
* @since 0.5.2 - 05.03.2007
$ret = $this->createElementNS(self :: STYLE, 'style:' . $tag);
$ret = $this->createElementNS(self :: STYLE, 'style:' . $tag, $value);
return $this->createElementNS(self :: STYLE, 'style:' . $tag, $value);
* Create an DOMElement in the DC namespace with tag $tag.
* @param string $tag Tag of the new DOMElement
* @param string $value If seted, this is the node value.
* @since 0.5.2 - 05.03.2007
return $this->createElementNS(self :: DC, 'dc:' . $tag, $value);
* Create an DOMElement in the Manifest namespace with tag $tag.
* @param string $tag Tag of the new DOMElement
* @param string $value If seted, this is the node value.
* @since 0.5.2 - 05.03.2007
return $this->createElementNS(self :: MANIFEST, 'manifest:' . $tag, $value);
* Create an ODPElement as '<style:text-properties>'.
* @since 0.5.2 - 16.03.2007
$ret = new TextProperties('style:text-properties', NULL, self::STYLE );
$ret = $this->adoptNode($ret);
//But we must use: _PHP IS A MESS_ */
* Create an ODPElement as '<style:paragraph-properties>'.
* @since 0.5.2 - 16.03.2007
$ret = new ParagraphProperties('style:paragraph-properties', NULL, self::STYLE );
$ret = $this->adoptNode($ret);
//But we must use: _PHP IS A MESS_ */
* Create an ODPElement as '<style:graphic-properties>'.
* @since 0.5.2 - 16.03.2007
$ret = new GraphicProperties('style:graphic-properties', NULL, self::STYLE );
$ret = $this->adoptNode($ret);
// Alternativly this should work too:
$this->registerNodeClass('DOMElement', 'GraphicProperties');
$this->registerNodeClass('DOMElement', NULL);
//But we must use: _PHP IS A MESS_
$ret= new GraphicProperties($this->createStyleElement('graphic-properties'));
* Create an ODPElement as '<style:default-style>'.
* @since 0.5.2 - 19.03.2007
$ret = new ParagraphProperties('style:paragraph-properties', NULL, self::STYLE );
$ret = $this->adoptNode($ret);
//But we must use: _PHP IS A MESS_ */
* Create an ODPElement as '<style:style>'.
* @since 0.5.2 - 19.03.2007
$ret = new ParagraphProperties('style:paragraph-properties', NULL, self::STYLE );
$ret = $this->adoptNode($ret);
//But we must use: _PHP IS A MESS_ */
|