[Mapbender-commits] r9260 - in trunk/mapbender: http/classes http/php resources/db/pgsql/UTF-8/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 17 02:14:57 PDT 2015


Author: armin11
Date: 2015-07-17 02:14:57 -0700 (Fri, 17 Jul 2015)
New Revision: 9260

Modified:
   trunk/mapbender/http/classes/class_iso19139.php
   trunk/mapbender/http/php/mod_dataISOMetadata.php
   trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
   trunk/mapbender/http/php/mod_layerISOMetadata.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
Log:
Enhancement for dynamic iso19139 metadata creation - possibility to give rdf/xml variant for those files

Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php	2015-07-17 07:16:55 UTC (rev 9259)
+++ trunk/mapbender/http/classes/class_iso19139.php	2015-07-17 09:14:57 UTC (rev 9260)
@@ -436,6 +436,22 @@
 		$this->metadata = $xml;
 	}
 
+	public function transformToRdf() {
+		$xslDoc = new DOMDocument();
+   		$xslDoc->load(dirname(__FILE__) . "/../geoportal/xslt/iso-19139-to-dcat-ap.xsl");
+   		$xmlDoc = new DOMDocument();
+   		$xmlDoc->loadXML($this->metadata);
+   		$proc = new XSLTProcessor();
+		libxml_use_internal_errors(true);
+   		$result = $proc->importStylesheet($xslDoc);
+		if (!$result) {
+    			foreach (libxml_get_errors() as $error) {
+        			$e = new mb_exception("Libxml error: {$error->message}\n");
+    			}
+		}
+   		return $proc->transformToXML($xmlDoc);	
+	}
+
 	public function transformToHtml($layout,$languageCode){
 		libxml_use_internal_errors(true);
 		//TODO don't parse it again, but change the internal parser function!

Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php	2015-07-17 07:16:55 UTC (rev 9259)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php	2015-07-17 09:14:57 UTC (rev 9260)
@@ -30,7 +30,10 @@
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
 require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
 require_once(dirname(__FILE__) . "/../php/mod_validateInspire.php");
+require_once(dirname(__FILE__) . "/../classes/class_iso19139.php");
 
+
+
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
 
@@ -59,17 +62,33 @@
 	$testMatch = NULL;
 }
 //
-if ($_REQUEST['OUTPUTFORMAT'] == "iso19139") {
+if ($_REQUEST['OUTPUTFORMAT'] == "iso19139" || $_REQUEST['OUTPUTFORMAT'] == "rdf" || $_REQUEST['OUTPUTFORMAT'] == 'html') {
 	//Initialize XML document
 	$iso19139Doc = new DOMDocument('1.0');
 	$iso19139Doc->encoding = 'UTF-8';
 	$iso19139Doc->preserveWhiteSpace = false;
 	$iso19139Doc->formatOutput = true;
+	$outputFormat = $_REQUEST['OUTPUTFORMAT'];
 } else {
 	//echo 'outputFormat: <b>'.$_REQUEST['OUTPUTFORMAT'].'</b> is not set or valid.<br/>'; 
-	echo 'Parameter outputFormat is not set or valid (iso19139).<br/>'; 
+	echo 'Parameter outputFormat is not set or valid (iso19139 | rdf | html).<br/>'; 
 	die();
 }
+
+if (!($_REQUEST['CN'] == "false")) {
+	//overwrite outputFormat for special headers:
+	switch ($_SERVER["HTTP_ACCEPT"]) {
+		case "application/rdf+xml":
+			$outputFormat="rdf";
+		break;
+		case "text/html":
+			$outputFormat="html";
+		break;
+		default:
+			$outputFormat="iso19139";
+		break;
+	}
+}
 //if validation is requested
 //
 if (isset($_REQUEST['VALIDATE']) and $_REQUEST['VALIDATE'] != "true") {
@@ -105,16 +124,15 @@
 			$xml = fillISO19139($iso19139Doc, $recordId);
 			validateInspire($xml); //calls fillISO19139 to!
 		} else {
-			pushISO19139($iso19139Doc, $recordId); //throw it out!
+			pushISO19139($iso19139Doc, $recordId, $outputFormat); //throw it out!
 		}
 
 		break;
 		case 'external':
 			if ($mb_metadata['export2csw'] == "t") { //the metadata must have been harvested before!
 				if ($mb_metadata['harvestresult'] == 1) {
-					if ($_REQUEST['VALIDATE'] != "true") {
-						header("Content-type: text/xml");
-						echo $mb_metadata['data'];
+					if ($_REQUEST['VALIDATE'] != "true") { 
+						proxyFile($mb_metadata['data'],$outputFormat);
 						die();
 					} else {
 						validateInspire($row['data']);
@@ -132,8 +150,7 @@
 				$metadataUrlObject = new connector($mb_metadata['link']);
 				$metadataXml = $metadataUrlObject->file;
 				if ($_REQUEST['VALIDATE'] != "true") {
-					header("Content-type: text/xml");
-					echo $metadataXml;
+					proxyFile($metadataXml,$outputFormat);
 					die();
 				} else {
 					validateInspire($metadataXml);
@@ -146,8 +163,7 @@
 		case 'upload':
 			if ($mb_metadata['harvestresult'] == 1) {
 				if ($_REQUEST['VALIDATE'] != "true") {
-					header("Content-type: text/xml");
-					echo $mb_metadata['data'];
+					proxyFile($mb_metadata['data'],$outputFormat);
 					die();
 				} else {
 					validateInspire($row['data']);
@@ -164,8 +180,7 @@
 			//do the same as for the external case but all from caps should be harvested
 			if ($mb_metadata['harvestresult'] == 1) {
 				if ($_REQUEST['VALIDATE'] != "true") {
-					header("Content-type: text/xml");
-					echo $mb_metadata['data'];
+					proxyFile($mb_metadata['data'],$outputFormat);
 					die();
 				} else {
 					validateInspire($mb_metadata['data']);
@@ -181,14 +196,43 @@
 		default:
 		break;	
 	}
+
 //function to give away the xml data
-function pushISO19139($iso19139Doc, $recordId) {
-	//echo $recordId;
-	header("Content-type: text/xml; charset=UTF-8");
+function pushISO19139($iso19139Doc, $recordId, $outputFormat) {
 	$xml = fillISO19139($iso19139Doc, $recordId);
-	echo $xml;
+	proxyFile($xml, $outputFormat);
 	die();
 }
+
+function xml2rdf($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToRdf();
+}
+
+function xml2html($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToHtml();
+}
+
+function proxyFile($iso19139str,$outputFormat) {
+	switch ($outputFormat) {
+		case "rdf":
+			header("Content-type: application/rdf+xml; charset=UTF-8");
+			echo xml2rdf($iso19139str);
+		break;
+		case "html":
+			header("Content-type: text/html; charset=UTF-8");
+			echo xml2html($iso19139str);
+		break;
+		default:
+			header("Content-type: text/xml; charset=UTF-8");
+			echo $iso19139str;
+		break;
+	}
+	
+}
 //some needfull functions to pull metadata out of the database!
 function fillISO19139($iso19139, $recordId) {
 	global $admin;

Modified: trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php	2015-07-17 07:16:55 UTC (rev 9259)
+++ trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php	2015-07-17 09:14:57 UTC (rev 9260)
@@ -24,6 +24,8 @@
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
 require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
+require_once(dirname(__FILE__) . "/../classes/class_iso19139.php");
+
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
 
@@ -53,18 +55,35 @@
 	$recordId = $testMatch;
 	$testMatch = NULL;
 }
-//
-if ($_REQUEST['OUTPUTFORMAT'] == "iso19139") {
+
+if ($_REQUEST['OUTPUTFORMAT'] == "iso19139" || $_REQUEST['OUTPUTFORMAT'] == "rdf" || $_REQUEST['OUTPUTFORMAT'] == 'html') {
 	//Initialize XML document
 	$iso19139Doc = new DOMDocument('1.0');
 	$iso19139Doc->encoding = 'UTF-8';
 	$iso19139Doc->preserveWhiteSpace = false;
 	$iso19139Doc->formatOutput = true;
+	$outputFormat = $_REQUEST['OUTPUTFORMAT'];
 } else {
 	//echo 'outputFormat: <b>'.$_REQUEST['OUTPUTFORMAT'].'</b> is not set or valid.<br/>'; 
-	echo 'Parameter <b>outputFormat</b> is not set or valid (iso19139).<br/>'; 
+	echo 'Parameter outputFormat is not set or valid (iso19139 | rdf | html).<br/>'; 
 	die();
 }
+
+if (!($_REQUEST['CN'] == "false")) {
+	//overwrite outputFormat for special headers:
+	switch ($_SERVER["HTTP_ACCEPT"]) {
+		case "application/rdf+xml":
+			$outputFormat="rdf";
+		break;
+		case "text/html":
+			$outputFormat="html";
+		break;
+		default:
+			$outputFormat="iso19139";
+		break;
+	}
+}
+
 //if validation is requested
 //
 if (isset($_REQUEST['VALIDATE']) and $_REQUEST['VALIDATE'] != "true") {
@@ -1318,15 +1337,45 @@
 	$MD_Metadata->appendChild($gmd_dataQualityInfo);
 	return $iso19139->saveXML();
 }
-	//function to give away the xml data
-	function pushISO19139($iso19139Doc, $recordId) {
-		//echo $recordId;
-		header("Content-type: application/xhtml+xml; charset=UTF-8");
-		$xml = fillISO19139($iso19139Doc, $recordId);
-		echo $xml;
-		die();
+
+//function to give away the xml data
+function pushISO19139($iso19139Doc, $recordId, $outputFormat) {
+	$xml = fillISO19139($iso19139Doc, $recordId);
+	proxyFile($xml, $outputFormat);
+	die();
+}
+
+function xml2rdf($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToRdf();
+}
+
+function xml2html($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToHtml();
+}
+
+function proxyFile($iso19139str,$outputFormat) {
+	switch ($outputFormat) {
+		case "rdf":
+			header("Content-type: application/rdf+xml; charset=UTF-8");
+			echo xml2rdf($iso19139str);
+		break;
+		case "html":
+			header("Content-type: text/html; charset=UTF-8");
+			echo xml2html($iso19139str);
+		break;
+		default:
+			header("Content-type: application/xhtml+xml; charset=UTF-8");
+			echo $iso19139str;
+		break;
 	}
+	
+}
 
+
 	//function to validate against the inspire validation service
 	function validateInspireMetadata($iso19139Doc, $recordId){
 		$validatorUrl = 'http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire';
@@ -1421,7 +1470,7 @@
 if ($_REQUEST['VALIDATE'] == "true"){
 	validateInspireMetadata($iso19139Doc, $recordId);
 } else {
-	pushISO19139($iso19139Doc, $recordId); //throw it out to world!
+	pushISO19139($iso19139Doc, $recordId, $outputFormat); //throw it out to world!
 }
 ?>
 

Modified: trunk/mapbender/http/php/mod_layerISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadata.php	2015-07-17 07:16:55 UTC (rev 9259)
+++ trunk/mapbender/http/php/mod_layerISOMetadata.php	2015-07-17 09:14:57 UTC (rev 9260)
@@ -24,6 +24,7 @@
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
 require_once(dirname(__FILE__) . "/../php/mod_validateInspire.php");
+require_once(dirname(__FILE__) . "/../classes/class_iso19139.php");
 
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
@@ -51,18 +52,35 @@
 	$recordId = $testMatch;
 	$testMatch = NULL;
 }
-//
-if ($_REQUEST['OUTPUTFORMAT'] == "iso19139") {
+
+if ($_REQUEST['OUTPUTFORMAT'] == "iso19139" || $_REQUEST['OUTPUTFORMAT'] == "rdf" || $_REQUEST['OUTPUTFORMAT'] == 'html') {
 	//Initialize XML document
 	$iso19139Doc = new DOMDocument('1.0');
 	$iso19139Doc->encoding = 'UTF-8';
 	$iso19139Doc->preserveWhiteSpace = false;
 	$iso19139Doc->formatOutput = true;
+	$outputFormat = $_REQUEST['OUTPUTFORMAT'];
 } else {
 	//echo 'outputFormat: <b>'.$_REQUEST['OUTPUTFORMAT'].'</b> is not set or valid.<br/>'; 
-	echo 'Parameter <b>outputFormat</b> is not set or valid (iso19139).<br/>'; 
+	echo 'Parameter outputFormat is not set or valid (iso19139 | rdf | html).<br/>'; 
 	die();
 }
+
+if (!($_REQUEST['CN'] == "false")) {
+	//overwrite outputFormat for special headers:
+	switch ($_SERVER["HTTP_ACCEPT"]) {
+		case "application/rdf+xml":
+			$outputFormat="rdf";
+		break;
+		case "text/html":
+			$outputFormat="html";
+		break;
+		default:
+			$outputFormat="iso19139";
+		break;
+	}
+}
+
 //if validation is requested
 //
 if (isset($_REQUEST['VALIDATE']) and $_REQUEST['VALIDATE'] != "true") {
@@ -932,14 +950,43 @@
 	$MD_Metadata->appendChild($gmd_dataQualityInfo);
 	return $iso19139->saveXML();
 }
-	//function to give away the xml data
-	function pushISO19139($iso19139Doc, $recordId) {
-		//echo $recordId;
-		header("Content-type: application/xhtml+xml; charset=UTF-8");
-		$xml = fillISO19139($iso19139Doc, $recordId);
-		echo $xml;
-		die();
+
+//function to give away the xml data
+function pushISO19139($iso19139Doc, $recordId, $outputFormat) {
+	$xml = fillISO19139($iso19139Doc, $recordId);
+	proxyFile($xml, $outputFormat);
+	die();
+}
+
+function xml2rdf($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToRdf();
+}
+
+function xml2html($iso19139xml) {
+	$iso19139 = new Iso19139();
+	$iso19139->createMapbenderMetadataFromXML($iso19139xml);
+	return $iso19139->transformToHtml();
+}
+
+function proxyFile($iso19139str,$outputFormat) {
+	switch ($outputFormat) {
+		case "rdf":
+			header("Content-type: application/rdf+xml; charset=UTF-8");
+			echo xml2rdf($iso19139str);
+		break;
+		case "html":
+			header("Content-type: text/html; charset=UTF-8");
+			echo xml2html($iso19139str);
+		break;
+		default:
+			header("Content-type: text/xml; charset=UTF-8");
+			echo $iso19139str;
+		break;
 	}
+	
+}
 
 function getEpsgByLayerId ($layer_id) { // from merge_layer.php
 	$epsg_list = "";
@@ -990,7 +1037,7 @@
 	$xml = fillISO19139($iso19139Doc, $recordId);
 	validateInspire($xml);
 } else {
-	pushISO19139($iso19139Doc, $recordId); //throw it out to world!
+	pushISO19139($iso19139Doc, $recordId, $outputFormat); //throw it out to world!
 }
 ?>
 

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql	2015-07-17 07:16:55 UTC (rev 9259)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql	2015-07-17 09:14:57 UTC (rev 9260)
@@ -596,4 +596,4 @@
 ALTER TABLE mb_metadata ADD COLUMN transfer_size real;
 
 ALTER TABLE mb_metadata ALTER column uuid type varchar(300);
-
+ALTER TABLE mb_metadata ALTER column link type varchar(400);



More information about the Mapbender_commits mailing list