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

Source for file MetaDocument.php

Documentation is available at MetaDocument.php

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

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