Ejemplo n.º 1
0
 protected function getNodeForRedlandNode($redlandNode)
 {
     if (librdf_node_is_literal($redlandNode)) {
         return new Literal($redlandNode);
     } elseif (librdf_node_is_resource($redlandNode)) {
         return new NamedNode($redlandNode);
     } elseif (librdf_node_is_blank($redlandNode)) {
         return new BlankNode($redlandNode);
     }
 }
Ejemplo n.º 2
0
Archivo: Node.php Proyecto: bakulf/raop
 /**
  * Create a new Literal node.
  *
  * Both the $language and $datatype parameters are optional.
  *
  * The value of the literal node can either be a string or an XML literal
  * in the form of a DOMNodeList object.  If using XML, a datatype of
  * http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral is implied, so
  * the datatype parameter cannot be used with XML.  A literal cannot have
  * both a language and a datatype.
  *
  * @param   mixed       $value      The literal value, either a string, a DOMNodeList or a librdf_node resource
  * @param   string      $datatype   An optional datatype URI for the literal value
  * @param   string      $language   An option language for the literal value
  * @return  void
  * @throws  LibRDF_Error            If unabel to create a new node
  * @access  public
  */
 public function __construct()
 {
     $valuestr = "";
     $is_xml = 0;
     // possible parameter lists are either LibRDF_Node $resource or
     // string $value, $datatype=NULL, string $language=NULL
     $num_args = func_num_args();
     if ($num_args < 1 or $num_args > 3) {
         throw new LibRDF_Error("Invalid number of arguments");
     }
     $value = func_get_arg(0);
     if ($num_args >= 2) {
         $datatype = func_get_arg(1);
         if ($datatype) {
             $datatype = new LibRDF_URI($datatype);
         }
     } else {
         $datatype = NULL;
     }
     if ($num_args >= 3) {
         $language = func_get_arg(2);
     } else {
         $language = NULL;
     }
     if ($num_args == 1 and is_resource($value)) {
         if (!librdf_node_is_literal($value)) {
             throw new LibRDF_Error("Argument 1 not a valid librdf_node " . " literal node");
         } else {
             $this->node = $value;
         }
     } else {
         // value is XML, convert to a string and set the datatype
         if ($value instanceof DOMNodeList) {
             // XML values imply a datatype of
             // http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral, so
             // specifying a different datatype is an error
             if ($datatype !== NULL and $datatype->__toString() !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral") {
                 throw new LibRDF_Error("Cannot override datatype for XML literal");
             } else {
                 $datatype = NULL;
             }
             $valuestr = "";
             foreach ($value as $item) {
                 $valuestr .= $item->ownerDocument->saveXML($item);
             }
             $is_xml = 1;
         } else {
             $valuestr = (string) $value;
             $is_xml = 0;
         }
         if ($datatype !== NULL) {
             $datatype_uri = $datatype->getURI();
         } else {
             $datatype_uri = NULL;
         }
         if ($is_xml or $datatype === NULL and $language === NULL) {
             $this->node = librdf_new_node_from_literal(librdf_php_get_world(), $valuestr, $language, $is_xml);
         } else {
             $this->node = librdf_new_node_from_typed_literal(librdf_php_get_world(), $valuestr, $language, $datatype_uri);
         }
     }
     if (!$this->node) {
         throw new LibRDF_Error("Unable to create new literal node");
     }
 }
Ejemplo n.º 3
0
 function _node($node)
 {
     $r = array();
     if (librdf_node_is_resource($node)) {
         $r['type'] = 'uri';
         $r['value'] = librdf_uri_to_string(librdf_node_get_uri($node));
     } elseif (librdf_node_is_literal($node)) {
         $r['type'] = 'literal';
         $r['value'] = librdf_node_get_literal_value($node);
         $dt = librdf_node_get_literal_value_datatype_uri($node);
         if ($dt) {
             $r['datatype'] = librdf_uri_to_string($dt);
         }
     } elseif (librdf_node_is_blank($node)) {
         $r['type'] = 'bnode';
         $r['value'] = librdf_node_get_blank_identifier($node);
     }
     return $r;
 }