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

Source for file ODPElement.php

Documentation is available at ODPElement.php

  1. <?php
  2. /*
  3.  * Created on 05.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  4.  *
  5.  * PHP versions 5.2 or better.
  6.  *
  7.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  9.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  10.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  11.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  12.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  13.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  14.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  15.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  16.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  17.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18.  *
  19.  * This software consists of voluntary contributions made by many individuals
  20.  * and is licensed under the GPL. For more information please see
  21.  * <http://opendocumentphp.org>.
  22.  * 
  23.  * $Id: Fragment.php 146 2007-03-05 09:53:21Z nmarkgraf $
  24.  */
  25. /**
  26.  * ODPElement class.
  27.  *  
  28.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  29.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  30.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  31.  * @version        $Revision: 146 $
  32.  * @package        OpenDocumentPHP
  33.  * @subpackage  util
  34.  * @abstract
  35.  * @since         0.5.2 - 05.03.2007
  36.  */
  37. class ODPElement extends DOMElement {
  38.     /**
  39.      * namespace OpenDocument meta
  40.      */
  41.     const META = 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0';
  42.     /**
  43.      * namespace OpenDocument office
  44.      */
  45.     const OFFICE = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
  46.     /**
  47.      * namespace OpenDocument manifest
  48.      */
  49.     const MANIFEST = 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0';
  50.     /**
  51.      * namespace OpenDocument style
  52.      */
  53.     const STYLE = 'urn:oasis:names:tc:opendocument:xmlns:style:1.0';
  54.     /**
  55.      * namespace OpenDocument text
  56.      */
  57.     const TEXT = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0';
  58.     /**
  59.      * namespace OpenDocument draw
  60.      */
  61.     const DRAW = 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0';
  62.     /**
  63.      * namespace OpenDocument table
  64.      */
  65.     const TABLE = 'urn:oasis:names:tc:opendocument:xmlns:table:1.0';
  66.     /**
  67.      * namespace OpenDocument number
  68.      */
  69.     const NUMBER = 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0';
  70.     /**
  71.      * namespace OpenDocument chart
  72.      */
  73.     const CHART = 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0';
  74.     /**
  75.      * namespace OpenDocument form
  76.      */
  77.     const FORM = 'urn:oasis:names:tc:opendocument:xmlns:form:1.0';
  78.     /**
  79.      * namespace OpenDocument config
  80.      */
  81.     const CONFIG = 'urn:oasis:names:tc:opendocument:xmlns:config:1.0';
  82.     /**
  83.      * namespace OpenDocument presentation
  84.      */
  85.     const PRESENTATION = 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0';
  86.     /**
  87.      * namespace OpenDocument dr3d
  88.      */
  89.     const DR3D = 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0';
  90.     /**
  91.      * namespace OpenDocument animation
  92.      */
  93.     const ANIM = 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0';
  94.     /**
  95.      * namespace OpenDocument script
  96.      */
  97.     const SCRIPT = 'urn:oasis:names:tc:opendocument:xmlns:script:1.0';
  98.     /**
  99.      * namespace OpenDocument svg
  100.      */
  101.     const SVG = 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0';
  102.     /**
  103.      * namespace OpenDocument fo (formation objects)
  104.      */
  105.     const FO = 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0';
  106.     /**
  107.      * namespace OpenDocument smil
  108.      */
  109.     const SMIL = 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0';
  110.     /**
  111.      * namespace Dublin Core
  112.      */
  113.     const DC = 'http://purl.org/dc/elements/1.1/';
  114.     /**
  115.      * namespace XLink
  116.      */
  117.     const XLINK = 'http://www.w3.org/1999/xlink';
  118.     /**
  119.      * namespace XForms
  120.      */
  121.     const XFORMS = 'http://www.w3.org/2002/xforms';
  122.     /**
  123.      * namespace MathML
  124.      */
  125.     const MATHML = 'http://www.w3.org/1998/Math/MathML';
  126.     /**
  127.      * The DOMElement if this is just a cover object.
  128.      * @access    private
  129.      */
  130.     private $elem NULL;
  131.     /**
  132.      * Constructor.
  133.      *
  134.      * This is a workaround, because DOMElements are not realy PHP classes.
  135.      * 
  136.      * @param         mixed  $tagelem Either a DOMElement or a string
  137.      * @param         string $value 
  138.      * @param         string $namespace 
  139.      * @since        0.5.2 - 07.03.2007
  140.      */
  141.     function __construct($tagelem$value NULL$namespace NULL{
  142.         if (is_string($tagelem)) {
  143.             // This is a clean ODPElement
  144.             parent :: __construct($tagelem$value$namespace);
  145.             $this->elem NULL;
  146.         }
  147.         elseif ($tagelem instanceof DOMElement{
  148.             // This is a cover ODPElement
  149.             $this->elem $tagelem;
  150.         }
  151.         elseif ($tagelem instanceof DOMDocument{
  152.             // We should call __setRoot to get a new ODPElement and add it 
  153.             // to this DOMDocument.
  154.         else {
  155.             // throw an ODPElement Exception! 
  156.         };
  157.     }
  158.     /**
  159.      * Return this element as uncovered DOMElement.
  160.      * 
  161.      * @access         public
  162.      * @since         0.5.2 - 07.03.2007
  163.      */
  164.     function getElement({
  165.         $ret $this->elem;
  166.         if (is_null($ret)) {
  167.             $ret $this;
  168.         }
  169.         return $ret;
  170.     }
  171.     /**
  172.      * Retrieve elements by given tagname and namespace.
  173.      * 
  174.      * @param        string $namespace 
  175.      * @param        string $tag 
  176.      * @return         DOMNodeList List of all found elements.
  177.      * @access         public
  178.      * @since         0.5.2 - 16.03.2007
  179.      */
  180.     function getElementsByTagNameNS($namespace$tag{
  181.         $ret NULL;
  182.         if (is_null($this->elem)) {
  183.             $ret parent :: getElementsByTagNameNS($namespace$tag);
  184.         else {
  185.             $ret $this->elem->getElementsByTagNameNS($namespace$tag);
  186.         }
  187.         return $ret;
  188.     }
  189.     /**
  190.      * Retrieve (first) element by given tagname and namespace.
  191.      * 
  192.      * @param        string $namespace 
  193.      * @param        string $tag 
  194.      * @return         DOMElement First found element if there is one,
  195.      * @access         public
  196.      * @since         0.5.2 - 07.03.2007
  197.      */
  198.     function getElementByTagNameNS($namespace$tag{
  199.         $ret $this->getElementsByTagNameNS($namespace$tag);
  200.         // Check if we got a DOMNodeList or nothing ...
  201.         if ((!is_null($ret)) && ($ret instanceof DOMNodeList)) {
  202.             // If we got a correct anwser, check if we got items in the list
  203.             if ($ret->length 0{
  204.                 // We got some, so return the first one, as requested.
  205.                 $ret $ret->item(0);
  206.             }
  207.         }
  208.         return $ret;
  209.     }
  210.     /**
  211.      * Check if this element has an attribute with given namespace and tagname.
  212.      * 
  213.      * @access         public
  214.      * @since         0.5.2 - 07.03.2007
  215.      */
  216.     function hasAttributeNS($namespace$tag{
  217.         $ret NULL;
  218.         if (is_null($this->elem)) {
  219.             $ret parent :: hasAttributeNS($namespace$tag);
  220.         else {
  221.             $ret $this->elem->hasAttributeNS($namespace$tag);
  222.         }
  223.         return $ret;
  224.     }
  225.     /**
  226.      * Set attribute with namespace.
  227.      * 
  228.      * @access         public
  229.      * @since         0.5.2 - 07.03.2007
  230.      */
  231.     function removeAttributeNS($namespace$tag{
  232.         $ret NULL;
  233.         if (is_null($this->elem)) {
  234.             $ret parent :: removeAttributeNS($namespace$tag);
  235.         else {
  236.             $ret $this->elem->removeAttributeNS($namespace$tag);
  237.         }
  238.         return $ret;
  239.     }
  240.     /**
  241.      * Set attribute with namespace.
  242.      * 
  243.      * @access         public
  244.      * @since         0.5.2 - 07.03.2007
  245.      */
  246.     function setAttributeNS($namespace$tag$value{
  247.         $ret NULL;
  248.         if (is_null($this->elem)) {
  249.             $ret parent :: setAttributeNS($namespace$tag$value);
  250.         else {
  251.             $ret $this->elem->setAttributeNS($namespace$tag$value);
  252.         }
  253.         return $ret;
  254.     }
  255.     /* *** FIX ME ***
  256.     function getAttributeNodeNS();
  257.     function setAttributeNodeNS();
  258.     function cloneNode();
  259.     function hasChildNodes();
  260.     function hasAttributes();
  261.     function insertBefore();
  262.     function isDefaultNamespace();
  263.     function isSameNode();
  264.     function isSupported();
  265.     function lookupNamespaceURI();
  266.     function lookupPrefix();
  267.     function normalize();
  268.     function removeChild();
  269.     function replaceChild();
  270.     */
  271.     /**
  272.      * Set attribute with namespace.
  273.      * 
  274.      * @access         public
  275.      * @since         0.5.2 - 07.03.2007
  276.      */
  277.     function appendChild($child{
  278.         $ret NULL;
  279.         if ($child instanceof ODPElement{
  280.             $uc_child $child->getElement();
  281.             if (is_null($this->elem)) {
  282.                 $ret parent :: appendChild($uc_child);
  283.             else {
  284.                 $ret $this->elem->appendChild($uc_child);
  285.             }
  286.         else {
  287.             $ret parent :: appendChild($child);
  288.         }
  289.         return $ret;
  290.     }
  291.     /**
  292.      * Check if the current element has a child $tag with $namespace.
  293.      * 
  294.      * @return        bool True, if there is such an element else false.
  295.      * @access         public
  296.      * @since         0.5.2 - 05.03.2007
  297.      */
  298.     function hasChildNS($namespace$tag{
  299.         // Get the list and if it has more than one Element return TRUE:
  300.         return ($this->getElementByTagNameNS($namespace$tag)->length 0);
  301.     }
  302.     /**
  303.      * Retrieve a child by its namespace and tag from the current node.
  304.      * 
  305.      * @return        bool True, if there is such an element else false.
  306.      * @access         public
  307.      * @since         0.5.2 - 05.03.2007
  308.      */
  309.     function getChildNS($namespace$tag{
  310.         $ret true;
  311.         // read all possible nodes with this tag and namespace in to a node list
  312.         $nodeList $this->getElementByTagNameNS($namespace$tag);
  313.         if ($nodelist->length != 1{
  314.             // There is no or to many nodes in the node list.
  315.             $ret false;
  316.         else {
  317.             // Get first (and only) item of the node list.
  318.             $ret $nodeList->item(0);
  319.         }
  320.         return $ret;
  321.     }
  322.     /**
  323.      * Put an attribute with namespace, tag and value.
  324.      * If an old attribute exists, it will be removed first.
  325.      *  
  326.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  327.      * @access         public
  328.      * @since         0.5.2 - 05.03.2007
  329.      */
  330.     function putAttributeNS($namespace$tag$value{
  331.         $ret true;
  332.         if ($this->hasAttributeNS($namespace$tag)) {
  333.             $ret $this->removeAttributeNS($namespace$tag);
  334.         }
  335.         $this->setAttributeNS($namespace$tag$value);
  336.         return $ret;
  337.     }
  338.     /**
  339.      * Retrieve an attribute with namespace, tag and value.
  340.      * If a default value is given and the attribute does not exists, it will be
  341.      * created.
  342.      *
  343.      * @param        string $namespace 
  344.      * @param        string $tag 
  345.      * @param        string $value Default value
  346.      * @access         public
  347.      * @since         0.5.2 - 19.03.2007
  348.      */
  349.     function getAttributeNS($namespace$tag$value null{
  350.         // Set up default value
  351.         $ret $value;
  352.         if (is_null($ret)) {
  353.             // If there is no default value, setup false instead.
  354.             $ret false;
  355.         }
  356.         if ($this->hasAttributeNS($namespace$tag)) {
  357.             $ret parent :: getAttributeNS($namespace$tag);
  358.         else {
  359.             if (!is_null($value)) {
  360.                 $this->setAttributeNS($namespace$tag$value);
  361.             }
  362.         }
  363.         return $ret;
  364.     }
  365.     /**
  366.      * Set a Manifest attribute to the current ODPElement.
  367.      * 
  368.      * '<... manifest:$tagname="$value"...>'
  369.      * 
  370.      * @param         string $tagname Tagname without prefix.
  371.      * @param        string $value Value of the attribute.
  372.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  373.      * @access         public
  374.      * @since         0.5.2 - 16.03.2007
  375.      */
  376.     function setManifestAttribute($tag$value{
  377.         return $this->setAttributeNS(self :: MANIFEST'manifest:' $tag$value);
  378.     }
  379.     /**
  380.      * Put (set with remove old) a FO attribute to the current ODPElement.
  381.      * 
  382.      * '<... fo:$tagname="$value"...>'
  383.      * 
  384.      * @param         string $tagname Tagname without prefix.
  385.      * @param        string $value Value of the attribute.
  386.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  387.      * @access         public
  388.      * @since         0.5.2 - 16.03.2007
  389.      */
  390.     function putFOAttribute($tagname$value{
  391.         return $this->putAttributeNS(self :: FO'fo:' $tagname$value);
  392.     }
  393.     /**
  394.      * Put (set with remove old) a sytle attribute to the current ODPElement.
  395.      * 
  396.      * '<... style:$tagname="$value"...>'
  397.      * 
  398.      * @param         string $tagname Tagname without prefix.
  399.      * @param        string $value Value of the attribute.
  400.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  401.      * @access         public
  402.      * @since         0.5.2 - 16.03.2007
  403.      */
  404.     function putStyleAttribute($tagname$value{
  405.         return $this->putAttributeNS(self :: STYLE'style:' $tagname$value);
  406.     }
  407.     /**
  408.      * Retrieve a style attribute of the current element.
  409.      * 
  410.      * '<... style:$tagname="$ret"...>'
  411.      * @access         public
  412.      * @since         0.5.2 - 19.03.2007
  413.      */
  414.     function getStyleAttribute($tagname$value null{
  415.         return $this->getAttributeNS(self :: STYLE$tagname$value);
  416.     }
  417.     /**
  418.      * Put (set with remove old) a draw attribute to the current ODPElement.
  419.      * 
  420.      * '<... draw:$tagname="$value"...>'
  421.      * 
  422.      * @param         string $tagname Tagname without prefix.
  423.      * @param        string $value Value of the attribute.
  424.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  425.      * @access         public
  426.      * @since         0.5.2 - 21.03.2007
  427.      */
  428.     function putDrawAttribute($tagname$value{
  429.         return $this->putAttributeNS(self :: DRAW'draw:' $tagname$value);
  430.     }
  431.     /**
  432.      * Retrieve a draw attribute of the current element.
  433.      * 
  434.      * '<... draw:$tagname="$ret"...>'
  435.      * @access         public
  436.      * @since         0.5.2 - 21.03.2007
  437.      */
  438.     function getDrawAttribute($tagname$value null{
  439.         return $this->getAttributeNS(self :: DRAW$tagname$value);
  440.     }
  441. }
  442. ?>

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