Exemplo n.º 1
0
 /**
  * Serializes a given model or (if supported) all models into a given format.
  */
 public function exportAction()
 {
     if (!$this->_owApp->erfurt->getAc()->isActionAllowed(Erfurt_Ac_Default::ACTION_MODEL_EXPORT)) {
         $this->_owApp->appendMessage(new OntoWiki_Message('Model export not allowed.', OntoWiki_Message::ERROR));
         $this->_redirect($_SERVER['HTTP_REFERER'], array('code' => 302));
         return;
     }
     // Check whether the f parameter is given. If not: default to rdf/xml
     if (!isset($this->_request->f)) {
         $format = 'rdfxml';
     } else {
         $format = $this->_request->f;
     }
     $format = Erfurt_Syntax_RdfSerializer::normalizeFormat($format);
     $store = $this->_erfurt->getStore();
     // Check whether given format is supported. If not: 400 Bad Request.
     if (!in_array($format, array_keys(Erfurt_Syntax_RdfSerializer::getSupportedFormats()))) {
         $response = $this->getResponse();
         $response->setRawHeader('HTTP/1.0 400 Bad Request');
         throw new OntoWiki_Controller_Exception("Format '{$format}' not supported.");
     }
     // Check whether a model uri is given
     if (isset($this->_request->m)) {
         $modelUri = $this->_request->m;
         // Check whether model exists. If not: 404 Not Found.
         if (!$store->isModelAvailable($modelUri, false)) {
             $response = $this->getResponse();
             $response->setRawHeader('HTTP/1.0 404 Not Found');
             throw new OntoWiki_Controller_Exception("Model '{$modelUri}' not found.");
         }
         // Check whether model is available (with acl). If not: 403 Forbidden.
         if (!$store->isModelAvailable($modelUri)) {
             $response = $this->getResponse();
             $response->setRawHeader('HTTP/1.0 403 Forbidden');
             throw new OntoWiki_Controller_Exception("Model '{$modelUri}' not available.");
         }
         $filename = 'export' . date('Y-m-d_Hi');
         $description = Erfurt_Syntax_RdfSerializer::getFormatDescription($format);
         $contentType = $description['contentType'];
         $filename .= $description['fileExtension'];
         $this->_helper->viewRenderer->setNoRender();
         $this->_helper->layout->disableLayout();
         $response = $this->getResponse();
         $response->setHeader('Content-Type', $contentType, true);
         $response->setHeader('Content-Disposition', 'filename="' . $filename . '"');
         $serializer = Erfurt_Syntax_RdfSerializer::rdfSerializerWithFormat($format);
         echo $serializer->serializeGraphToString($modelUri);
         return;
     } else {
         // Else use all available models.
         // TODO Exporters need to support this feature...
         $response = $this->getResponse();
         $response->setRawHeader('HTTP/1.0 400 Bad Request');
         throw new OntoWiki_Controller_Exception("No Graph URI given.");
     }
 }