Source for file Literal.php

Documentation is available at Literal.php

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

Documentation generated on Fri, 17 Dec 2004 16:15:32 +0100 by phpDocumentor 1.3.0RC3