[Fusionforge-commits] r15977 - in trunk/src: common/include docs plugins/doaprdf/include plugins/oslc/include

Olivier Berger olberger at fusionforge.org
Tue Jul 10 13:29:40 CEST 2012


Author: olberger
Date: 2012-07-10 13:29:39 +0200 (Tue, 10 Jul 2012)
New Revision: 15977

Modified:
   trunk/src/common/include/rdfutils.php
   trunk/src/docs/README.Plugins
   trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
   trunk/src/plugins/oslc/include/oslcPlugin.class.php
Log:
Implement new style project_rdf_metadata hook using real ARC2 resources

Modified: trunk/src/common/include/rdfutils.php
===================================================================
--- trunk/src/common/include/rdfutils.php	2012-07-10 11:29:29 UTC (rev 15976)
+++ trunk/src/common/include/rdfutils.php	2012-07-10 11:29:39 UTC (rev 15977)
@@ -49,3 +49,4 @@
 // mode: php
 // c-file-style: "bsd"
 // End:
+

Modified: trunk/src/docs/README.Plugins
===================================================================
--- trunk/src/docs/README.Plugins	2012-07-10 11:29:29 UTC (rev 15976)
+++ trunk/src/docs/README.Plugins	2012-07-10 11:29:39 UTC (rev 15977)
@@ -509,8 +509,8 @@
                in $params['content_type'] the actual content-type to return
 
   Hook Name  : project_rdf_metadata
-  Parameters : $params['prefixes'] : already used RDF prefixes in the form URL => shortname, $params['xml'] already returned xml bits
-  Description: returns in $params['prefixes'] and $params['xml'] added prefixes and added bits of RDF+XML to be included in the project's DOAP description 
+  Parameters : $params['prefixes'] : already used RDF prefixes in the form URL => shortname, $params['in_Resource'] : already constructed ARC2_Resource instances (read-only)
+  Description: returns in $params['prefixes'] added prefixes, and in the array $params['out_Resources'] new ARC2_Resources including new triples to be included in the project's DOAP description 
 
   Hook Name  : role_adduser
   Parameters : $params['user'] : user added to the role, $params['role'] : role added to the user

Modified: trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
===================================================================
--- trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-07-10 11:29:29 UTC (rev 15976)
+++ trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-07-10 11:29:39 UTC (rev 15977)
@@ -25,7 +25,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+
 require_once('common/include/ProjectManager.class.php');
+require_once('common/include/rdfutils.php');
 
 class doaprdfPlugin extends Plugin {
 	public function __construct($id=0) {
@@ -58,6 +60,8 @@
 		$group_id = $params['group_id'];
 
 		if($accept == 'application/rdf+xml') {
+			
+			// connect to FusionForge internals
 			$pm = ProjectManager::instance();
 			$project = $pm->getProject($group_id);
 			$project_shortdesc = $project->getPublicName();
@@ -68,58 +72,88 @@
 				$tags_list = $group->getTags();
 			}
 			
+			// We will return RDF+XML
 			$params['content_type'] = 'application/rdf+xml';
 
-			// invoke the 'project_rdf_metadata' hook so as to complement the RDF description
-			// Invoke plugins' hooks 'script_accepted_types' to discover which alternate content types they would accept for /users/...
+			// Construct an ARC2_Resource containing the project's RDF (DOAP) description
+			$ns = array(
+					'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+					'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+					'doap' => 'http://usefulinc.com/ns/doap#',
+					'dcterms' => 'http://purl.org/dc/terms/' /*,
+					'oslc' => 'http://open-services.net/ns/core#' */
+			);
+			
+			$conf = array(
+					'ns' => $ns
+					/*,
+					'serializer_type_nodes' => true*/
+			);
+			
+			$res = ARC2::getResource($conf);
+			$res->setURI('');
+				
+			//$res->setRel('rdf:type', 'doap:Project');
+			rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');
+				
+			$res->setProp('doap:name', $projectname);
+			$res->setProp('doap:shortdesc', $project_shortdesc);
+			if($project_description) {
+				$res->setProp('doap:description', $project_description);
+			}
+			if($tags_list) {
+				$tags = split(', ',$tags_list);
+				$res->setProp('dcterms:subject', $tags);
+			}
+
+			// Now, we need to collect complementary RDF descriptiosn of the project via other plugins 
+			// invoke the 'project_rdf_metadata' hook so as to complement the RDF description
 			$hook_params = array();
-			$hook_params['prefixes'] = array(
-							'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
-							'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
-							'http://usefulinc.com/ns/doap#' => 'doap',
-							'http://purl.org/dc/terms/' => 'dcterms'
+			
+			$hook_params['prefixes'] = array();
+			foreach($ns as $prefix => $url) {
+				$hook_params['prefixes'][$url] = $prefix;
+			}
+			/*
+			$hook_params['prefixes'] = array(
+					'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
+					'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
+					'http://usefulinc.com/ns/doap#' => 'doap',
+					'http://purl.org/dc/terms/' => 'dcterms'
 			);
-			$hook_params['xml'] = array();
-			$hook_params['group'] = $group_id;
+			*/
+			$hook_params['group'] = $group_id;
 			
-			plugin_hook_by_reference('project_rdf_metadata', $hook_params);
-			
-			$xml = '<?xml version="1.0"?>
-				<rdf:RDF';
+			// pass the resource in case it could be useful (read-only in principle)
+			$hook_params['in_Resource'] = $res;
+
+			$hook_params['out_Resources'] = array();
+			
+			plugin_hook_by_reference('project_rdf_metadata', $hook_params);
+
+			// add new prefixes to the list
 			foreach($hook_params['prefixes'] as $url => $prefix) {
-				$xml .= ' xmlns:'. $prefix . '="'. $url .'"';
-			}
-      		
-      		$xml .='>
+				if (!isset($ns[$prefix])) {
+					$ns[$prefix] = $url;
+				}
+			}
 
-      			<doap:Project rdf:about="">
-      				<doap:name>'. $projectname .'</doap:name>';
-			$xml .= '<doap:shortdesc>'. $project_shortdesc . '</doap:shortdesc>';
-      		if($project_description) {
-				$xml .= '<doap:description>'. $project_description . '</doap:description>';
-			}
-			if($tags_list) {
-				$tags = split(', ',$tags_list);
-				foreach($tags as $tag) {
-					$xml .= '<dcterms:subject>'.$tag.'</dcterms:subject>';
-				}
-			}
+			$merged_index = $res->index;
+			foreach($hook_params['out_Resources'] as $out_res) {
+				$merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
+			}
+
+			$conf = array(
+					'ns' => $ns,
+					'serializer_type_nodes' => true
+			);
 			
-			if (count($hook_params['xml'])) {
-				foreach($hook_params['xml'] as $fragment) {
-					$xml .= $fragment;
-				}
-			}
-			
-			$xml .='</doap:Project>
-    			</rdf:RDF>';
-			
-			$doc = new DOMDocument();
-			$doc->preserveWhiteSpace = false;
-			$doc->formatOutput   = true;
-			$doc->loadXML($xml);
-			 
-			$params['content'] = $doc->saveXML();
+			$ser = ARC2::getRDFXMLSerializer($conf);
+			
+			/* Serialize a resource index */
+			$doc = $ser->getSerializedIndex($merged_index);
+
+			$params['content'] = $doc;
 		}
 	}
 }

Modified: trunk/src/plugins/oslc/include/oslcPlugin.class.php
===================================================================
--- trunk/src/plugins/oslc/include/oslcPlugin.class.php	2012-07-10 11:29:29 UTC (rev 15976)
+++ trunk/src/plugins/oslc/include/oslcPlugin.class.php	2012-07-10 11:29:39 UTC (rev 15977)
@@ -21,6 +21,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+require_once('common/include/rdfutils.php');
+
 class oslcPlugin extends Plugin {
 	public function __construct($id=0) {
 		$this->Plugin($id) ;
@@ -152,14 +154,22 @@
 			}
 		}
 		elseif($hookname == "project_rdf_metadata") {
+
+			# TODO : create another resource
+			$group_id=$params['group'];
+
+			if (! isset($params['prefixes']['http://open-services.net/ns/core#'])) {
+				$params['prefixes']['http://open-services.net/ns/core#'] = 'oslc';
+			}
 			
-			$group_id=$params['group'];
 			$serviceprovider = util_make_url ("/plugins/oslc/cm/oslc-cm-services/".$group_id);
 
-			if (! $params['prefixes']['http://open-services.net/ns/core#']) {
-				$params['prefixes']['http://open-services.net/ns/core#'] = 'oslc';
-			}
-			$params['xml'][] = '<oslc:serviceProvider rdf:resource="'.$serviceprovider.'"/>';
+			$res = $params['in_Resource'];
+
+			rdfutils_setPropToUri($res, 'oslc:serviceProvider', $serviceprovider);
+            
+			$params['out_Resources'][] = $res;
+			
 		}
 		elseif ($hookname == "blahblahblah") {
 			// ...




More information about the Fusionforge-commits mailing list