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

Documentation generated on Fri, 13 Jan 2006 07:48:29 +0100 by phpDocumentor 1.3.0RC4