00001 <?php
00017 class SMWRDFResultPrinter extends SMWResultPrinter {
00018
00022 protected $syntax;
00023
00032 protected function handleParameters( array $params, $outputmode ) {
00033 parent::handleParameters( $params, $outputmode );
00034 $this->syntax = $params['syntax'];
00035 }
00036
00037 public function getMimeType( $res ) {
00038 return $this->syntax == 'turtle' ? 'application/x-turtle' : 'application/xml';
00039 }
00040
00041 public function getFileName( $res ) {
00042 return $this->syntax == 'turtle' ? 'result.ttl' : 'result.rdf';
00043 }
00044
00045 public function getQueryMode( $context ) {
00046 return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
00047 }
00048
00049 public function getName() {
00050 return wfMsg( 'smw_printername_rdf' );
00051 }
00052
00053 protected function getResultText( SMWQueryResult $res, $outputmode ) {
00054 if ( $outputmode == SMW_OUTPUT_FILE ) {
00055 $serializer = $this->syntax == 'turtle' ? new SMWTurtleSerializer() : new SMWRDFXMLSerializer();
00056 $serializer->startSerialization();
00057 $serializer->serializeExpData( SMWExporter::getOntologyExpData( '' ) );
00058
00059 while ( $row = $res->getNext() ) {
00060 $subjectDi = reset( $row )->getResultSubject();
00061 $data = SMWExporter::makeExportDataForSubject( $subjectDi );
00062
00063 foreach ( $row as $resultarray ) {
00064 $printreq = $resultarray->getPrintRequest();
00065 $property = null;
00066
00067 switch ( $printreq->getMode() ) {
00068 case SMWPrintRequest::PRINT_PROP:
00069 $property = $printreq->getData()->getDataItem();
00070 break;
00071 case SMWPrintRequest::PRINT_CATS:
00072 $property = new SMWDIProperty( '_TYPE' );
00073 break;
00074 case SMWPrintRequest::PRINT_CCAT:
00075
00076 break;
00077 case SMWPrintRequest::PRINT_THIS:
00078
00079 break;
00080 }
00081
00082 if ( !is_null( $property ) ) {
00083 SMWExporter::addPropertyValues( $property, $resultarray->getContent() , $data, $subjectDi );
00084 }
00085 }
00086 $serializer->serializeExpData( $data );
00087 }
00088
00089 $serializer->finishSerialization();
00090
00091 return $serializer->flushContent();
00092 } else {
00093 if ( $this->getSearchLabel( $outputmode ) ) {
00094 $label = $this->getSearchLabel( $outputmode );
00095 } else {
00096 $label = wfMsgForContent( 'smw_rdf_link' );
00097 }
00098
00099 $link = $res->getQueryLink( $label );
00100 $link->setParameter( 'rdf', 'format' );
00101 $link->setParameter( $this->syntax, 'syntax' );
00102
00103 if ( array_key_exists( 'limit', $this->params ) ) {
00104 $link->setParameter( $this->params['limit'], 'limit' );
00105 } else {
00106 $link->setParameter( 100, 'limit' );
00107 }
00108
00109 $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML );
00110
00111 return $link->getText( $outputmode, $this->mLinker );
00112 }
00113 }
00114
00115 public function getParameters() {
00116 $params = array();
00117
00118 $params['syntax'] = new Parameter( 'syntax' );
00119 $params['syntax']->setMessage( 'smw_paramdesc_rdfsyntax' );
00120 $params['syntax']->addCriteria( new CriterionInArray( 'rdfxml', 'turtle' ) );
00121 $params['syntax']->setDefault( 'rdfxml' );
00122
00123 return array_merge( parent::getParameters(), $this->exportFormatParameters(), $params );
00124 }
00125
00126 }