Source for file Literal.php

Documentation is available at Literal.php

  1. <?php
  2. require_once RDFAPI_INCLUDE_DIR 'model/Node.php';
  3.  
  4. // ----------------------------------------------------------------------------------
  5. // Class: Literal
  6. // ----------------------------------------------------------------------------------
  7.  
  8. /**
  9.  * An RDF literal.
  10.  * The literal supports the xml:lang and rdf:datatype property.
  11.  * For XML datatypes see: http://www.w3.org/TR/xmlschema-2/
  12.  *
  13.  * @version  $Id: fsource_model__modelLiteral.php.html 443 2007-06-01 16:25:38Z cax $
  14.  * @author Chris Bizer <chris@bizer.de>
  15.  * @author Daniel Westphal <dawe@gmx.de>
  16.  *
  17.  * @package model
  18.  * @access    public
  19.  *
  20.  */
  21.  class Literal extends Node {
  22.  
  23.     /**
  24.     * Label of the literal
  25.     * @var        string 
  26.     * @access    private
  27.     */
  28.     var $label;
  29.    /**
  30.     * Language of the literal
  31.     * @var        string 
  32.     * @access    private
  33.     */
  34.     var $lang;
  35.  
  36.    /**
  37.     * Datatype of the literal
  38.     * @var        string 
  39.     * @access    private
  40.     */
  41.     var $dtype;
  42.  
  43.  
  44.    /**
  45.     * Constructor
  46.     *
  47.     * @param    string    $str            label of the literal
  48.     * @param     string $language        optional language identifier
  49.     *
  50.     */
  51.     function Literal($str$language NULL{
  52.         $this->dtype NULL;
  53.         $this->label $str;
  54.  
  55.         if ($language != NULL{
  56.             $this->lang $language;
  57.         else {
  58.             $this->lang NULL;
  59.         }
  60.  
  61.  
  62.     }
  63.  
  64.   /**
  65.    * Returns the string value of the literal.
  66.    *
  67.    * @access    public
  68.    * @return    string value of the literal
  69.    */
  70.   function getLabel({
  71.  
  72.     return $this->label;
  73.   }
  74.  
  75.   /**
  76.    * Returns the language of the literal.
  77.    *
  78.    * @access    public
  79.    * @return    string language of the literal
  80.    */
  81.   function getLanguage({
  82.  
  83.     return $this->lang;
  84.   }
  85.  
  86.   /**
  87.    * Sets the language of the literal.
  88.    *
  89.    * @access    public
  90.    * @param        string $lang 
  91.    */
  92.   function setLanguage($lang{
  93.  
  94.     $this->lang $lang;
  95.   }
  96.  
  97.   /**
  98.    * Returns the datatype of the literal.
  99.    *
  100.    * @access    public
  101.    * @return    string datatype of the literal
  102.    */
  103.   function getDatatype({
  104.  
  105.     return $this->dtype;
  106.   }
  107.  
  108.   /**
  109.    * Sets the datatype of the literal.
  110.    * Instead of datatype URI, you can also use an datatype shortcuts like STRING or INTEGER.
  111.    * The array $short_datatype with the possible shortcuts is definded in ../constants.php
  112.    *
  113.    * @access    public
  114.    * @param        string URI of XML datatype or datatype shortcut
  115.    *
  116.    */
  117.   function setDatatype($datatype{
  118.     GLOBAL $short_datatype;
  119.     if  (stristr($datatype,DATATYPE_SHORTCUT_PREFIX))  {
  120.         $this->dtype $short_datatype[substr($datatype,strlen(DATATYPE_SHORTCUT_PREFIX)) ];}
  121.     else
  122.         $this->dtype $datatype;
  123.   }
  124.  
  125.   /**
  126.    * Checks if ihe literal equals another literal.
  127.    * Two literals are equal, if they have the same label and they
  128.    * have the same language/datatype or both have no language/datatype property set.
  129.    *
  130.    * @access    public
  131.    * @param        object    literal $that 
  132.    * @return    boolean 
  133.    */
  134.   function equals ($that{
  135.  
  136.     if (($that == NULLor !(is_a($that'Literal'))) {
  137.       return false;
  138.     }
  139.  
  140.     if ( ($this->label == $that->getLabel()) && ( ( ($this->lang == $that->getLanguage()) ||
  141.        ($this->lang == NULL && $that->getLanguage(== NULL) )  &&
  142.  
  143.        (
  144.        ($this->dtype == $that->getDatatype(||
  145.        ($this->dtype == NULL && $that->getDatatype(== NULL)) ) ) )
  146.          {
  147.             return true;
  148.          }
  149.  
  150.     return false;
  151.   }
  152.  
  153.   /**
  154.    * Dumps literal.
  155.    *
  156.    * @access    public
  157.    * @return    string 
  158.    */
  159.   function toString({
  160.     $dump 'Literal("' $this->label .'"';
  161.     if ($this->lang != NULL)
  162.         $dump .= ', lang="' $this->lang .'"';
  163.     if ($this->dtype != NULL)
  164.         $dump .= ', datatype="' $this->dtype .'"';
  165.     $dump .= ')';
  166.     return $dump;
  167.   }
  168.  
  169.  
  170. // end: Literal
  171.  
  172. ?>

Documentation generated on Fri, 1 Jun 2007 16:49:39 +0200 by phpDocumentor 1.3.2