You are here

public function RestWSFormatRDF::addRdfElement in RESTful Web Services 7.2

Same name and namespace in other branches
  1. 7 restws.formats.inc \RestWSFormatRDF::addRdfElement()

Adds an RDF element for the given property of the wrapper using the RDF mapping.

1 call to RestWSFormatRDF::addRdfElement()
RestWSFormatRDF::addToXML in ./restws.formats.inc
Adds the data of the given wrapper to the given XML element.

File

./restws.formats.inc, line 782
RESTful web services module formats.

Class

RestWSFormatRDF
A simple formatter for RDF. Requires the RDF module for the mapping.

Code

public function addRdfElement(DOMDOcument $doc, EntityMetadataWrapper $wrapper, $name) {
  if ($wrapper instanceof EntityDrupalWrapper) {
    $entity = $wrapper
      ->value();
    if (!empty($entity->rdf_mapping[$name])) {

      // Just make use of the first predicate for now.
      $predicate = reset($entity->rdf_mapping[$name]['predicates']);
      list($ns, $qname) = explode(':', $predicate);
      $element = $doc
        ->createElementNS($this->namespaces[$ns], $predicate);
      if (!empty($entity->rdf_mapping[$name]['datatype'])) {
        $element
          ->setAttributeNS($this->namespaces['rdf'], 'rdf:datatype', $entity->rdf_mapping[$name]['datatype']);
      }
    }
  }
  if (!isset($element)) {

    // For other elements just use the site URL as namespace.
    $element = $doc
      ->createElementNS(url('', array(
      'absolute' => TRUE,
    )), 'site:' . (is_numeric($name) ? 'item' : $name));
  }
  return $element;
}