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

Source for file MetaDocument.php

Documentation is available at MetaDocument.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 05.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * MetaDocument class.
  11.  *  
  12.  * In this container class we will store all the meta data and build a DOM document
  13.  * out of it.
  14.  *
  15.  * PHP Version 5
  16.  *  
  17.  * LICENSE:
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * This software consists of voluntary contributions made by many individuals
  31.  * and is licensed under the GPL. For more information please see
  32.  * <http://opendocumentphp.org>.
  33.  * 
  34.  * $Id: MetaDocument.php 236 2007-07-24 07:43:40Z nmarkgraf $
  35.  * 
  36.  * @category    File Formats
  37.  * @package        OpenDocumentPHP
  38.  * @subpackage  meta
  39.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  40.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  41.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  42.  * @version        SVN: $Id: MetaDocument.php 236 2007-07-24 07:43:40Z nmarkgraf $
  43.  * @link           http://opendocumentphp.org
  44.  * @link        http://www.oasis-open.org/committees/download.php/20493/UCR.pdf OpenDocument Metadata Use Cases and Requirements
  45.  * @since         0.5.0 - 08. Feb. 2007
  46.  */
  47.  
  48. /**
  49.  * 
  50.  */
  51. require_once 'OpenDocumentPHP/meta/DublinCoreFragment.php';
  52. require_once 'OpenDocumentPHP/meta/MetaFragment.php';
  53. require_once 'OpenDocumentPHP/util/AbstractDocument.php';
  54.  
  55. /**
  56.  * MetaDocument class.
  57.  *  
  58.  * In this container class we will store all the meta data and build a DOM document
  59.  * out of it.
  60.  *
  61.  * You can find more informations about this in the
  62.  * {@link http://www.oasis-open.org/committees/download.php/12572/OpenDocument-v1.0-os.pdf OpenDocument format handbook v1.0}
  63.  * page 40ff.
  64.  *
  65.  * Also you should now something about Dublin Meta core data.
  66.  * Take a look at the {@link http://dublincore.org/ Dublin core webpage} or read
  67.  * {@link http://en.wikipedia.org/wiki/Dublin_Core Dublin core in Wikipedia},
  68.  * {@link http://dublincore.org/documents/usageguide/qualifiers.shtml Dublin core qualifiers}
  69.  * or {@link http://de.wikipedia.org/wiki/Dublin_Core Dublin core in german Wikipedia}.
  70.  *
  71.  * To put some dublin core meta data in the MetaDocument, request a DublinCoreFragment and
  72.  * add the meta data there.
  73.  * 
  74.  * You can also add OpenDocument meta data to the MetaFragment.
  75.  *
  76.  * This is an example of a meta.xml file:
  77.  * <code>
  78.  * <?xml version="1.0" encoding="UTF-8"?>
  79.  * <office:document-meta
  80.  *      xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  81.  *      xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  82.  *      xmlns:dc="http://purl.org/dc/elements/1.1/"
  83.  *      xmlns:xlink="http://www.w3.org/1999/xlink">
  84.  *   <office:meta>
  85.  *     <meta:generator>OpenOffice.org/1.9.118$Win32 OpenOffice.org_project/680m118$Build-8936</meta:generator>
  86.  *     <meta:initial-creator>Peter Funny</meta:initial-creator>
  87.  *     <meta:creation-date>2005-09-27T16:53:48</meta:creation-date>
  88.  *     <dc:creator>Peter Funny</dc:creator>
  89.  *     <dc:date>2005-09-29T18:12:57</dc:date>
  90.  *     <meta:printed-by>Peter Funny</meta:printed-by>
  91.  *     <meta:print-date>2005-09-29T17:57:42</meta:print-date>
  92.  *     <dc:language>en-EN</dc:language>
  93.  *     <meta:editing-cycles>11</meta:editing-cycles>
  94.  *     <meta:editing-duration>PT6H11M44S</meta:editing-duration>
  95.  *     <meta:user-defined meta:name="Info 1"/>
  96.  *     <meta:user-defined meta:name="Info 2"/>
  97.  *     <meta:user-defined meta:name="Info 3"/>
  98.  *     <meta:user-defined meta:name="Info 4"/>
  99.  *     <meta:document-statistic
  100.  *           meta:table-count="0"
  101.  *           meta:image-count="4"
  102.  *           meta:object-count="0"
  103.  *           meta:page-count="5"
  104.  *           meta:paragraph-count="92"
  105.  *           meta:word-count="1460"
  106.  *           meta:character-count="10405"/>
  107.  *   </office:meta>
  108.  * </office:document-meta>
  109.  * </code>
  110.  * 
  111.  * @category    File Formats
  112.  * @package        OpenDocumentPHP
  113.  * @subpackage  meta
  114.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  115.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  116.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  117.  * @version     Release: @package_version@
  118.  * @link           http://opendocumentphp.org
  119.  * @link        http://www.oasis-open.org/committees/download.php/20493/UCR.pdf OpenDocument Metadata Use Cases and Requirements
  120.  * @since         0.5.0 - 08. Feb. 2007
  121.  */
  122. class MetaDocument extends AbstractDocument 
  123. {
  124.     /**
  125.      * Root element of the meta DOM document.
  126.      * 
  127.      * @var         DOMElement 
  128.      * @access         private
  129.      * @since         0.5.0 - 08.02.2007
  130.      */
  131.     private $meta;
  132.     
  133.     /**
  134.      * DublinCoreFragment is the container for dublin core meta datas.
  135.      * 
  136.      * @var         DublinCoreFragment 
  137.      * @access         private
  138.      * @since         0.5.0 - 08.02.2007
  139.      */
  140.     private $dublinCore;
  141.     
  142.     /**
  143.      * MetaFragment is the container for OpenDocument meta datas.
  144.      * 
  145.      * @var         MetaFragment 
  146.      * @access         private
  147.      * @since         0.5.0 - 08.02.2007
  148.      */
  149.     private $metaCore;
  150.     
  151.     /**
  152.      * Link to the DOMElement which is the root of this DOM document.
  153.      * 
  154.      * @var         DOMElement 
  155.      * @access        protected
  156.      * @since         0.5.0 - 08.02.2007
  157.      */
  158.     protected $root;    
  159.     
  160.     /**
  161.      * Construtor method.
  162.      * 
  163.      * Creates two container classes to store/get dublin core and open document
  164.      * meta datas.
  165.      * 
  166.      * @since         0.5.0 - 08.02.2007
  167.      */
  168.     function __construct(
  169.     {
  170.         parent :: __construct('office:document-meta');
  171.         //
  172.         $this->meta $this->createElementNS(self :: OFFICE'office:meta');
  173.         $this->root->appendChild($this->meta);
  174.         $this->dublinCore new DublinCoreFragment($this$this->meta);
  175.         $this->metaCore new MetaFragment($this$this->meta);
  176.         // Setup MetaFragment, because it is empty and should not be.
  177.         $this->metaCore->initMetaFragment();
  178.     }
  179.     
  180.     /**
  181.      * Retrieve a DublinCoreFragment to store/get dublin core meta date in it.
  182.      * 
  183.      * @return         DublinCoreFragment 
  184.      * @access        public
  185.      * @since         0.5.0 - 08.02.2007
  186.      */
  187.     function getDublinCoreFragment(
  188.     {
  189.         return $this->dublinCore;
  190.     }
  191.     
  192.     /**
  193.      * Retrieve a MetaFragment to store/get opendocument meta data in it.
  194.      * 
  195.      * @return         MetaFragment 
  196.      * @access        public
  197.      * @since         0.5.0 - 08.02.2007
  198.      */
  199.     function getMetaFragment(
  200.     {
  201.         return $this->metaCore;
  202.     }
  203.     
  204.     /**
  205.      * Loads an meta document into this MetaDocument.
  206.      * 
  207.      * @access     public
  208.      * @since     0.5.2 - 22.02.2007
  209.      */
  210.     function loadXML($source
  211.     {
  212.         /*
  213.          * First we load the document by the parent method
  214.          */
  215.         $ret parent::loadXML($source);
  216.         
  217.         if ($ret === TRUE{
  218.             /*
  219.              * If it was loaded correctly, we need to set up some
  220.              * local attributes. Therefore we first init the XPath stuff
  221.              */                
  222.             $this->initXpath();
  223.             /*
  224.              * Now we need the document root element to fill $this->root 
  225.              */
  226.             $this->root = $this->documentElement;
  227.             /*
  228.              * We now setup the $this->meta element... 
  229.              * First we ask XPath to give us the <office:meta> tag. 
  230.              */                        
  231.             $tmp $this->xpath->query('/office:document-meta/office:meta');            
  232.                         
  233.             if ($tmp->length == 1{
  234.                 /*
  235.                  * The only result is the meta tag in this case. So we can put
  236.                  * it in the $this->meta attribute.
  237.                  */            
  238.                 $this->meta $tmp->item(0);
  239.                 /*
  240.                  * Now we set up the dublin core part of the meta document
  241.                  */
  242.                 $this->dublinCore new DublinCoreFragment($this$this->meta);
  243.                 /*
  244.                  * And now the (OpenDocument) meta part of the meta document
  245.                  */
  246.                 $this->metaCore new MetaFragment($this$this->meta);
  247.             else {
  248.                 /*
  249.                  * Something strange happend and this should never occure.
  250.                  * *** EXCEPTION HANDLING ***
  251.                  */
  252.                 $ret FALSE;
  253.             }            
  254.         
  255.         return $ret;
  256.     }
  257. }
  258. ?>

Documentation generated on Wed, 18 Jun 2008 06:29:42 +0200 by phpDocumentor 1.3.2