Source for file Literal.php

Documentation is available at Literal.php

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

Documentation generated on Mon, 26 Jun 2006 14:25:34 +0200 by phpDocumentor 1.3.0RC6