[Fusionforge-general] Support for alternate representations (RDF for instance) - Was: Re: [Fusionforge-commits] r15978 - in trunk/src: docs plugins/doaprdf/include www/include

Olivier Berger olivier.berger at it-sudparis.eu
Wed Jul 11 10:31:56 CEST 2012


Hi.

As per that just committed patch on the trunk, I've introduced the
ability to instruct consumers of some web pages (/projects or /users
only, for the moment) that some plugins (or anything using the
'alt_representations' hook) that an alternate representation is
available with a different content-type at the some other URL.

The use case is to implement the Autodiscovery Linked Data pattern [0]
for the /projects pages, when the doaprdf plugin is activated (first one
to use this new hook).

The result is that when browsing https://myforge.example.com/projects/myproj/ there's an HTML
header link like :
 <link rel="meta" type="application/rdf+xml" title="DOAP RDF Data" href=""/>

This then tells you that using 
 $ curl -k -H 'Accept: application/rdf+xml' https://myforge.example.com/projects/myproj/ 
you'd get

 <?xml version="1.0" encoding="UTF-8"?>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:doap="http://usefulinc.com/ns/doap#"
   xmlns:dcterms="http://purl.org/dc/terms/">
 
   <doap:Project rdf:about="">
     <doap:name>myproj</doap:name>
     <doap:shortdesc>My Project</doap:shortdesc>
     <doap:description>Project for testing fusionforge.</doap:description>
     <dcterms:subject>whatever tag</dcterms:subject>
   </doap:Project>
 
 </rdf:RDF>

Hopefully, this will make it easier to interlink forge projects with
other Linked Data / Semantic Web applications yet unimagined, all the
most if several plugins start adding meta-data to that description, like
the OSLC plugin starts to (using the recently improved hook
'project_rdf_metadata').


Now, this mechanism isn't limited to RDF+XML, and could well be reused
for other types of alternate content types / content-negociation
scenarii for other FusionForge features.

Any comments ?

Best regards,

[0] http://patterns.dataincubator.org/book/autodiscovery.html

P.S.: next step on this path will probably be the ADMS.SW support

Olivier Berger <olberger at fusionforge.org> writes:

> Author: olberger
> Date: 2012-07-10 16:05:32 +0200 (Tue, 10 Jul 2012)
> New Revision: 15978
>
> Modified:
>    trunk/src/docs/README.Plugins
>    trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
>    trunk/src/www/include/Layout.class.php
> Log:
> Add alt_representations hook to support Linked Data Autodiscovery links in HTML link/meta
>
> Conflicts:
> 	src/docs/README.Plugins
>
> Modified: trunk/src/docs/README.Plugins
> ===================================================================
> --- trunk/src/docs/README.Plugins	2012-07-10 11:29:39 UTC (rev 15977)
> +++ trunk/src/docs/README.Plugins	2012-07-10 14:05:32 UTC (rev 15978)
> @@ -522,6 +522,10 @@
>    Locations  : common/include/RBAC.php
>    Description: Called when a role is removed to an user.
>  
> +  Hook Name  : alt_representations
> +  Parameters : $params['script_name'] contains the SCRIPT_NAME (filtered to work only on /projects or /users for the moment)
> +  Description: returns alternate representations for a particular page in $params['results'] which is populated by the hook users 
> +
>  TODO (nerville) : document display_hierarchy
>  TODO (lolando ?) : document role_normalize, role_translate_strings, role_has_permission, role_get_setting, list_roles_by_permission 
>  TODO : document project_link_with_tooltip
>
> Modified: trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php
> ===================================================================
> --- trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-07-10 11:29:39 UTC (rev 15977)
> +++ trunk/src/plugins/doaprdf/include/doaprdfPlugin.class.php	2012-07-10 14:05:32 UTC (rev 15978)
> @@ -36,6 +36,7 @@
>  		$this->text = "DoaPRDF!"; // To show in the tabs, use...
>  		$this->_addHook("script_accepted_types");
>  		$this->_addHook("content_negociated_project_home");
> +		$this->_addHook("alt_representations");
>  
>  	}
>  
> @@ -156,6 +157,18 @@
>  			$params['content'] = $doc;
>  		}
>  	}
> +	
> +	/**
> +	 * Declares a link to itself in the link+meta HTML headers
> +	 * @param unknown_type $params
> +	 */
> +	function alt_representations (&$params) {
> +		$script_name = $params['script_name'];
> +		if ($script_name == '/projects') {
> +			$params['return'][] = '<link rel="meta" type="application/rdf+xml" title="DOAP RDF Data" href=""/>';
> +		}
> +	}
> +	
>  }
>  
>  // Local Variables:
>
> Modified: trunk/src/www/include/Layout.class.php
> ===================================================================
> --- trunk/src/www/include/Layout.class.php	2012-07-10 11:29:39 UTC (rev 15977)
> +++ trunk/src/www/include/Layout.class.php	2012-07-10 14:05:32 UTC (rev 15978)
> @@ -268,6 +268,7 @@
>  		$this->headerCSS();
>  		$this->headerJS();
>  		$this->headerForgepluckerMeta();
> +		$this->headerLinkedDataAutodiscovery();
>  		?>
>  	</head>
>  		<?php
> @@ -369,6 +370,28 @@
>  		}
>  	}
>  
> +	/**
> + 	 * headerLinkedDataAutodiscovery() - creates the link+meta links to alternate
> + 	 * 		representations for Linked Data autodiscovery
> + 	 */
> +	function headerLinkedDataAutodiscovery() {
> +		// Only activated for /projects or /users for the moment
> +		$script_name = getStringFromServer('SCRIPT_NAME');
> +
> +		if ($script_name == '/projects' || $script_name == '/users') {
> +
> +			// invoke the 'alt_representations' hook
> +			$params = array('script_name' => $script_name,
> +							'return' => array());
> +
> +			plugin_hook_by_reference('alt_representations', $params);
> +
> +			foreach($params['return'] as $link) {
> +				echo "                        $link"."\n";
> +			}
> +		}
> +	}
> +
>  	function headerForgepluckerMeta() {
>  		/*-
>  		 * Forge-Identification Meta Header, Version 1.0
>
>
> _______________________________________________
> Fusionforge-commits mailing list
> Fusionforge-commits at lists.fusionforge.org
> http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits
>

-- 
Olivier BERGER 
http://www-public.it-sudparis.eu/~berger_o/ - OpenPGP-Id: 2048R/5819D7E8
Ingenieur Recherche - Dept INF
Institut Mines-Telecom, Telecom SudParis, Evry (France)



More information about the Fusionforge-general mailing list