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

Source for file ODPElement.php

Documentation is available at ODPElement.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.  * ODPElement 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: Fragment.php 146 2007-03-05 09:53:21Z nmarkgraf $
  32.  * 
  33.  * @category    File Formats
  34.  * @package        OpenDocumentPHP
  35.  * @subpackage  util
  36.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  37.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  38.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  39.  * @version        SVN: $Id: Validator.php 201 2007-07-11 11:36:55Z nmarkgraf $
  40.  * @link           http://opendocumentphp.org
  41.  * @link        http://www.oasis-open.org/committees/download.php/20493/UCR.pdf OpenDocument Metadata Use Cases and Requirements
  42.  * @since         0.5.2 - 05. Mar. 2007
  43.  */
  44.  
  45. /**
  46.  * 
  47.  */
  48. require_once 'OpenDocumentPHP/util/Namespaces.php';
  49.  
  50. /**
  51.  * ODPElement class.
  52.  *  
  53.  * @category    File Formats
  54.  * @package        OpenDocumentPHP
  55.  * @subpackage  util
  56.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  57.  * @copyright     Copyright in 2006, 2007 by OpenDocumentPHP Team
  58.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  59.  * @version     Release: @package_version@
  60.  * @link           http://opendocumentphp.org
  61.  * @since         0.5.2 - 05. Mar. 2007
  62.  * @abstract
  63.  */
  64. class ODPElement extends DOMElement implements Namespaces {
  65.  
  66.     /**
  67.      * The DOMElement if this is just a cover object.
  68.      * 
  69.      * @access       private
  70.      * @var        DOMElement 
  71.      * @since      0.5.2 - 05. Mar. 2007
  72.      */
  73.     private $elem null;
  74.     
  75.     /**
  76.      * Constructor.
  77.      *
  78.      * This is a workaround, because DOMElements are not realy PHP classes.
  79.      * 
  80.      * @param         mixed  $tagelem Either a DOMElement or a string
  81.      * @param         string $value 
  82.      * @param         string $namespace 
  83.      * @since        0.5.2 - 07. Mar. 2007
  84.      */
  85.     function __construct($tagelem$value null$namespace null
  86.     {
  87.         if (is_string($tagelem)) {
  88.             /*
  89.              * This is a clean ODPElement
  90.              */
  91.             parent :: __construct($tagelem$value$namespace);
  92.             $this->elem null;
  93.         }
  94.         elseif ($tagelem instanceof DOMElement{
  95.             /*
  96.              * This is a cover ODPElement
  97.              */
  98.             $this->elem $tagelem;
  99.         }
  100.         elseif ($tagelem instanceof DOMDocument{
  101.             // We should call __setRoot to get a new ODPElement and add it 
  102.             // to this DOMDocument.
  103.         else {
  104.             // throw an ODPElement Exception! 
  105.         };
  106.     }
  107.     
  108.     /**
  109.      * Return this element as uncovered DOMElement.
  110.      * 
  111.      * @access         public
  112.      * @since         0.5.2 - 07. Mar. 2007
  113.      */
  114.     function getElement(
  115.     {
  116.         $ret $this->elem;
  117.         if (is_null($ret)) {
  118.             $ret $this;
  119.         }
  120.         return $ret;
  121.     }
  122.     
  123.     /**
  124.      * Retrieve elements by given tagname and namespace.
  125.      * 
  126.      * @param        string $namespace 
  127.      * @param        string $tag 
  128.      * @return         DOMNodeList List of all found elements.
  129.      * @access         public
  130.      * @since         0.5.2 - 16. Mar. 2007
  131.      */
  132.     function getElementsByTagNameNS($namespace$tag
  133.     {
  134.         $ret null;
  135.         if (is_null($this->elem)) {
  136.             $ret parent :: getElementsByTagNameNS($namespace$tag);
  137.         else {
  138.             $ret $this->elem->getElementsByTagNameNS($namespace$tag);
  139.         }
  140.         return $ret;
  141.     }
  142.     
  143.     /**
  144.      * Retrieve (first) element by given tagname and namespace.
  145.      * 
  146.      * @param        string $namespace 
  147.      * @param        string $tag 
  148.      * @return         DOMElement First found element if there is one,
  149.      * @access         public
  150.      * @since         0.5.2 - 07. Mar. 2007
  151.      */
  152.     function getElementByTagNameNS($namespace$tag
  153.     {
  154.         $ret $this->getElementsByTagNameNS($namespace$tag);
  155.         /*
  156.          * Check if we have got a DOMNodeList or nothing ...
  157.          */
  158.         if ((!is_null($ret)) && ($ret instanceof DOMNodeList)) {
  159.             /*
  160.              * If we got a correct anwser, check if we got items in the list
  161.              */
  162.             if ($ret->length 0{
  163.                 /*
  164.                  * We got some, so return the first one, as requested.
  165.                  */
  166.                 $ret $ret->item(0);
  167.             }
  168.         }
  169.         return $ret;
  170.     }
  171.     
  172.     /**
  173.      * Check if this element has an attribute with given namespace and tagname.
  174.      * 
  175.      * @access         public
  176.      * @since         0.5.2 - 07. Mar. 2007
  177.      */
  178.     function hasAttributeNS($namespace$tag
  179.     {
  180.         $ret null;
  181.         if (is_null($this->elem)) {
  182.             $ret parent :: hasAttributeNS($namespace$tag);
  183.         else {
  184.             $ret $this->elem->hasAttributeNS($namespace$tag);
  185.         }
  186.         return $ret;
  187.     }
  188.     
  189.     /**
  190.      * Set attribute with namespace.
  191.      * 
  192.      * @access         public
  193.      * @since         0.5.2 - 07. Mar. 2007
  194.      */
  195.     function removeAttributeNS($namespace$tag
  196.     {
  197.         $ret null;
  198.         if (is_null($this->elem)) {
  199.             $ret parent :: removeAttributeNS($namespace$tag);
  200.         else {
  201.             $ret $this->elem->removeAttributeNS($namespace$tag);
  202.         }
  203.         return $ret;
  204.     }
  205.     
  206.     /**
  207.      * Set attribute with namespace.
  208.      * 
  209.      * @access         public
  210.      * @since         0.5.2 - 07. Mar. 2007
  211.      */
  212.     function setAttributeNS($namespace$tag$value
  213.     {
  214.         $ret null;
  215.         if (is_null($this->elem)) {
  216.             $ret parent :: setAttributeNS($namespace$tag$value);
  217.         else {
  218.             $ret $this->elem->setAttributeNS($namespace$tag$value);
  219.         }
  220.         return $ret;
  221.     }
  222.     /* *** FIX ME ***
  223.     function getAttributeNodeNS();
  224.     function setAttributeNodeNS();
  225.     function cloneNode();
  226.     function hasChildNodes();
  227.     function hasAttributes();
  228.     function insertBefore();
  229.     function isDefaultNamespace();
  230.     function isSameNode();
  231.     function isSupported();
  232.     function lookupNamespaceURI();
  233.     function lookupPrefix();
  234.     function normalize();
  235.     function removeChild();
  236.     function replaceChild();
  237.     */
  238.     /**
  239.      * Set attribute with namespace.
  240.      * 
  241.      * @access         public
  242.      * @since         0.5.2 - 07. Mar. 2007
  243.      */
  244.     function appendChild($child
  245.     {
  246.         $ret null;
  247.         /*
  248.          * If the child is a ODPElement, get the uncoverd child first.
  249.          */
  250.         if ($child instanceof ODPElement{
  251.             /*
  252.              * Get uncovered part first.
  253.              */
  254.             $uc_child $child->getElement();
  255.         else {
  256.             /*
  257.              * This is a normal DOMNode, so it is always un-covered.
  258.              */
  259.             $uc_child $child;
  260.         }        
  261.         /*
  262.          * If this is a covered DOMElement, append the child it to its real DOMElement part.
  263.          */                   
  264.         if (is_null($this->elem)) {
  265.             /*
  266.              * not covered ODPElement
  267.              */
  268.             $ret parent :: appendChild($uc_child);
  269.         else {
  270.             /*
  271.              * covered ODPElement
  272.              */
  273.             $ret $this->elem->appendChild($uc_child);
  274.         }
  275.         return $ret;
  276.     }
  277.     
  278.     /**
  279.      * Check if the current element has a child $tag with $namespace.
  280.      * 
  281.      * @return        bool True, if there is such an element else false.
  282.      * @access         public
  283.      * @since         0.5.2 - 05. Mar. 2007
  284.      */
  285.     function hasChildNS($namespace$tag
  286.     {
  287.         // Get the list and if it has more than one Element return TRUE:
  288.         return ($this->getElementByTagNameNS($namespace$tag)->length 0);
  289.     }
  290.     
  291.     /**
  292.      * Retrieve a child by its namespace and tag from the current node.
  293.      * 
  294.      * @return        bool True, if there is such an element else false.
  295.      * @access         public
  296.      * @since         0.5.2 - 05. Mar. 2007
  297.      */
  298.     function getChildNS($namespace$tag{
  299.         $ret true;
  300.         // read all possible nodes with this tag and namespace in to a node list
  301.         $nodeList $this->getElementByTagNameNS($namespace$tag);
  302.         if ($nodelist->length != 1{
  303.             // There is no or to many nodes in the node list.
  304.             $ret false;
  305.         else {
  306.             // Get first (and only) item of the node list.
  307.             $ret $nodeList->item(0);
  308.         }
  309.         return $ret;
  310.     }
  311.     
  312.     /**
  313.      * Put an attribute with namespace, tag and value.
  314.      * 
  315.      * If an old attribute exists, it will be removed first.
  316.      *  
  317.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  318.      * @access         public
  319.      * @since         0.5.2 - 05. Mar. 2007
  320.      */
  321.     function putAttributeNS($namespace$tag$value
  322.     {
  323.         $ret true;
  324.         if ($this->hasAttributeNS($namespace$tag)) {
  325.             $ret $this->removeAttributeNS($namespace$tag);
  326.         }
  327.         $this->setAttributeNS($namespace$tag$value);
  328.         return $ret;
  329.     }
  330.     
  331.     /**
  332.      * Retrieve an attribute with namespace, tag and value.
  333.      * If a default value is given and the attribute does not exists, it will be
  334.      * created.
  335.      *
  336.      * @param        string $namespace 
  337.      * @param        string $tag 
  338.      * @param        string $value Default value
  339.      * @access         public
  340.      * @since         0.5.2 - 19. Mar. 2007
  341.      */
  342.     function getAttributeNS($namespace$tag$value null
  343.     {
  344.         /*
  345.          * Set up default value
  346.          */
  347.         $ret $value;
  348.         if (is_null($ret)) {
  349.             /*
  350.              * If there is no default value, setup false instead.
  351.              */
  352.             $ret false;
  353.         }
  354.         if ($this->hasAttributeNS($namespace$tag)) {
  355.             $ret parent :: getAttributeNS($namespace$tag);
  356.         else {
  357.             if (!is_null($value)) {
  358.                 $this->setAttributeNS($namespace$tag$value);
  359.             }
  360.         }
  361.         return $ret;
  362.     }
  363.     
  364.     /**
  365.      * Set a Manifest attribute to the current ODPElement.
  366.      * 
  367.      * '<... manifest:$tagname="$value"...>'
  368.      * 
  369.      * @param         string $tagname Tagname without prefix.
  370.      * @param        string $value Value of the attribute.
  371.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  372.      * @access         public
  373.      * @since         0.5.2 - 16. Mar. 2007
  374.      */
  375.     function setManifestAttribute($tag$value
  376.     {
  377.         return $this->setAttributeNS(self :: MANIFEST'manifest:' $tag$value);
  378.     }
  379.     
  380.     /**
  381.      * Put (set with remove old) a FO attribute to the current ODPElement.
  382.      * 
  383.      * '<... fo:$tagname="$value"...>'
  384.      * 
  385.      * @param         string $tagname Tagname without prefix.
  386.      * @param        string $value Value of the attribute.
  387.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  388.      * @access         public
  389.      * @since         0.5.2 - 16. Mar. 2007
  390.      */
  391.     function putFOAttribute($tagname$value
  392.     {
  393.         return $this->putAttributeNS(self :: FO'fo:' $tagname$value);
  394.     }
  395.     
  396.     /**
  397.      * Put (set with remove old) a sytle attribute to the current ODPElement.
  398.      * 
  399.      * '<... style:$tagname="$value"...>'
  400.      * 
  401.      * @param         string $tagname Tagname without prefix.
  402.      * @param        string $value Value of the attribute.
  403.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  404.      * @access         public
  405.      * @since         0.5.2 - 16. Mar. 2007
  406.      */
  407.     function putStyleAttribute($tagname$value
  408.     {
  409.         return $this->putAttributeNS(self :: STYLE'style:' $tagname$value);
  410.     }
  411.     
  412.     /**
  413.      * Retrieve a style attribute of the current element.
  414.      * 
  415.      * '<... style:$tagname="$ret"...>'
  416.      * @access         public
  417.      * @since         0.5.2 - 19. Mar. 2007
  418.      */
  419.     function getStyleAttribute($tagname$value null
  420.     {
  421.         return $this->getAttributeNS(self :: STYLE$tagname$value);
  422.     }
  423.     
  424.     /**
  425.      * Put (set with remove old) a draw attribute to the current ODPElement.
  426.      * 
  427.      * '<... draw:$tagname="$value"...>'
  428.      * 
  429.      * @param         string $tagname Tagname without prefix.
  430.      * @param        string $value Value of the attribute.
  431.      * @return      mixed <b>True</b> if there was no old attibute, else the old attribute node.
  432.      * @access         public
  433.      * @since         0.5.2 - 21. Mar. 2007
  434.      */
  435.     function putDrawAttribute($tagname$value
  436.     {
  437.         return $this->putAttributeNS(self :: DRAW'draw:' $tagname$value);
  438.     }
  439.     
  440.     /**
  441.      * Retrieve a draw attribute of the current element.
  442.      * 
  443.      * '<... draw:$tagname="$ret"...>'
  444.      * @access         public
  445.      * @since         0.5.2 - 21. Mar. 2007
  446.      */
  447.     function getDrawAttribute($tagname$value null
  448.     {
  449.         return $this->getAttributeNS(self :: DRAW$tagname$value);
  450.     }
  451. }
  452. ?>

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