/**
  * Check if this element encodes an RDF list, and if yes return an
  * array of SMWExpElements corresponding to the collection elements in
  * the specified order. Otherwise return false.
  * The method only returns lists that can be encoded using
  * parseType="Collection" in RDF/XML, i.e. only lists of non-literal
  * resources.
  *
  * @return mixed array of SMWExpElement (but not SMWExpLiteral) or false
  */
 public function getCollection()
 {
     $rdftypeUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type')->getUri();
     $rdffirstUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'first')->getUri();
     $rdfrestUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'rest')->getUri();
     $rdfnilUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'nil')->getUri();
     // first check if we are basically an RDF List:
     if ($this->m_subject->isBlankNode() && count($this->m_children) == 3 && array_key_exists($rdftypeUri, $this->m_children) && count($this->m_children[$rdftypeUri]) == 1 && array_key_exists($rdffirstUri, $this->m_children) && count($this->m_children[$rdffirstUri]) == 1 && !end($this->m_children[$rdffirstUri]) instanceof SMWExpLiteral && array_key_exists($rdfrestUri, $this->m_children) && count($this->m_children[$rdfrestUri]) == 1) {
         $typedata = end($this->m_children[$rdftypeUri]);
         $rdflistUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'List')->getUri();
         if ($typedata->getSubject()->getUri() == $rdflistUri) {
             $first = end($this->m_children[$rdffirstUri]);
             $rest = end($this->m_children[$rdfrestUri]);
             if ($rest instanceof SMWExpData) {
                 $restlist = $rest->getCollection();
                 if ($restlist === false) {
                     return false;
                 } else {
                     array_unshift($restlist, $first);
                     return $restlist;
                 }
             } elseif ($rest instanceof SMWExpResource && $rest->getUri() == $rdfnilUri) {
                 return array($first);
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } elseif (count($this->m_children) == 0 && $this->m_subject->getUri() == $rdfnilUri) {
         return array();
     } else {
         return false;
     }
 }
 /**
  * Add to the output a serialization of a property assignment where an
  * SMWExpResource is the object. It is assumed that a suitable subject
  * block has already been openend.
  *
  * @param $expResourceProperty SMWExpNsResource the property to use
  * @param $expResource SMWExpResource the data value to use
  * @param $indent string specifying a prefix for indentation (usually a sequence of tabs)
  * @param $isClassTypeProp boolean whether the resource must be declared as a class
  */
 protected function serializeExpResource(SMWExpNsResource $expResourceProperty, SMWExpResource $expResource, $indent, $isClassTypeProp)
 {
     $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName();
     if (!$expResource->isBlankNode()) {
         if ($expResource instanceof SMWExpNsResource && $expResource->getNamespaceID() == 'wiki') {
             // very common case, reduce bandwidth
             $this->post_ns_buffer .= ' rdf:resource="&wiki;' . $expResource->getLocalName() . '"';
         } else {
             $uriValue = $this->makeAttributeValueString($expResource->getUri());
             $this->post_ns_buffer .= ' rdf:resource="' . $uriValue . '"';
         }
     }
     $this->post_ns_buffer .= "/>\n";
     if ($isClassTypeProp) {
         $this->requireDeclaration($expResource, SMW_SERIALIZER_DECL_CLASS);
     }
 }
Beispiel #3
0
 /**
  * State that a certain declaration is needed. The method checks if the 
  * declaration is already available, and records a todo otherwise.
  */
 protected function requireDeclaration(SMWExpResource $resource, $decltype)
 {
     // Do not declare predefined OWL language constructs:
     if ($resource instanceof SMWExpNsResource) {
         $nsId = $resource->getNamespaceId();
         if ($nsId == 'owl' || $nsId == 'rdf' || $nsId == 'rdfs') {
             return;
         }
     }
     // Do not declare blank nodes:
     if ($resource->isBlankNode()) {
         return;
     }
     $name = $resource->getUri();
     if (array_key_exists($name, $this->decl_done) && $this->decl_done[$name] & $decltype) {
         return;
     }
     if (!array_key_exists($name, $this->decl_todo)) {
         $this->decl_todo[$name] = $decltype;
     } else {
         $this->decl_todo[$name] = $this->decl_todo[$name] | $decltype;
     }
 }