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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jun 6 08:19:06 PDT 2012


Author: armin11
Date: 2012-06-06 08:19:06 -0700 (Wed, 06 Jun 2012)
New Revision: 8370

Added:
   trunk/mapbender/http/classes/class_iso19139.php
Modified:
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/php/mod_dataISOMetadata.php
   trunk/mapbender/http/php/wms.php
   trunk/mapbender/http/plugins/mb_metadata_server.php
   trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
Log:
New class to parse ISO19139 files - can be used from different classes. Further work have to be done. Bugfixes for INSPIRE.

Added: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_iso19139.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -0,0 +1,161 @@
+<?php
+# $Id: class_iso19139.php 3094 2008-10-01 13:52:35Z christoph $
+# http://www.mapbender.org/index.php/class_iso19139.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+
+class Iso19139 {
+	//values for handling apriori ows metadataurls
+	var $fileIdentifier;
+	var $createDate;
+	var $changeDate;
+	var $title;
+	var $abstract;
+	var $metadata;
+	var $datasetId;
+	var $datasetIdCodeSpace;
+	var $keywords = array();
+	var $hierachyLevel;
+	var $tmpExtentBegin;
+	var $tmpExtentEnd;
+	var $refSystem;
+	var $randomId;
+	var $href;
+	var $format;
+	var $type;
+	var $origin;
+
+
+	public function removeGetRecordTag ($xml) {
+		$regex = "#<csw:GetRecordByIdResponse .*?>#";
+		$xml = preg_replace($regex,"",$xml);
+		$regex = "#</csw:GetRecordByIdResponse>#";
+		$xml = preg_replace($regex,"",$xml);
+		return $xml;
+	}
+	
+	public function createMapbenderMetadataFromXML($xml){
+		$this->metadata = $xml;
+		$this->metadata = $this->removeGetRecordTag($this->metadata);
+		libxml_use_internal_errors(true);
+		try {
+			$iso19139Xml = simplexml_load_string($this->metadata);
+			if ($iso19139Xml === false) {
+				foreach(libxml_get_errors() as $error) {
+        				$e = new mb_exception($error->message);
+    				}
+				throw new Exception('Cannot parse Metadata XML!');
+			}
+		}
+		catch (Exception $e) {
+    			$e = new mb_exception($e->getMessage());
+		}
+		//if parsing was successful
+		if ($iso19139Xml != false) {
+			$this->fileIdentifier = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
+			$this->createDate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+			$this->changeDate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+			//TODO: check if this is set, maybe DateTime must be searched instead?
+			$this->title = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString');
+			//dataset identifier - howto model into md_metadata?
+			//check where datasetid is defined - maybe as RS_Identifier or as MD_Identifier see http://inspire.jrc.ec.europa.eu/documents/Metadata/INSPIRE_MD_IR_and_ISO_v1_2_20100616.pdf page 18
+			//First check if MD_Identifier is set, then check if RS_Identifier is used!
+			//Initialize datasetid
+			$this->datasetId = 'undefined';
+			$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString');
+			if (isset($code[0]) && $code[0] != '') {
+				$this->datasetId = $code[0];
+				$this->datasetIdCodeSpace = "";	
+			} else { //try to read code from RS_Identifier 		
+				$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
+				$codeSpace = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:codeSpace/gco:CharacterString');
+				if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
+					$this->datasetId = $code[0];
+					$this->datasetIdCodeSpace = $codeSpace[0];
+				} else {
+					//neither MD_Identifier nor RS_Identifier are defined in a right way
+					$e = new mb_notice("class_iso19139.php: No datasetId found in metadata record!");
+				}
+			}
+			//abstract
+			$this->abstract = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString');
+			$this->keywords = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString');
+			$this->hierachyLevel = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
+			$this->tmpExtentBegin = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
+			$this->tmpExtentEnd = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition');			
+			//spatial_res_type
+			//spatial_res_value
+			//ref_system
+			//format
+			//inspire_charset
+			//inspire_top_consistence
+			//responsible_party
+			//fees
+			//"constraints"	
+			//fill database with elements:
+			return $this;
+		} else {
+			return false;
+		}
+	}
+	
+	public function createFromUrl($url){
+		$metadataConnector = new connector($url);
+		$xml = $metadataConnector->file;
+		$mbMetadata = $this->createMapbenderMetadataFromXML($xml);
+		return $mbMetadata;
+	}
+	
+	public function createFromDB($fileIdentifier){
+		return $this;
+	}
+	
+	public function insertToDB(){
+		$sql = "INSERT INTO mb_metadata (link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid) ";
+		$sql .= "VALUES($1, 'capabilities', $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)";
+		$v = array($this->href,
+			$this->format,
+			$this->metadata,
+			$this->type,
+			$this->fileIdentifier[0],
+			$this->title[0],
+			$this->createDate[0],
+			$this->changeDate[0],
+			$this->abstract[0],
+			$this->keywords[0],
+			$this->hierachyLevel[0],
+			$this->tmpExtentBegin[0],
+			$this->tmpExtentEnd[0],
+			't',
+			$this->datasetId,
+			$this->datasetIdCodeSpace,
+			$this->randomId
+		);
+		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();
+			return false;
+		} else {
+			return true;
+		}
+		
+	}
+	
+}
+?>

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/http/classes/class_wms.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -12,6 +12,7 @@
 require_once dirname(__FILE__) . "/class_administration.php";
 require_once dirname(__FILE__) . "/class_georss_factory.php";
 require_once dirname(__FILE__) . "/class_mb_exception.php";
+require_once dirname(__FILE__) . "/class_iso19139.php";
 require_once dirname(__FILE__) . "/../classes/class_universal_wms_factory.php";
 
 class wms {
@@ -2370,198 +2371,107 @@
 		//parse the content if iso19139 is given
 		//TODO: generate temporal uuid for inserting and getting the serial afterwards
 		for($j=0; $j<count($this->objLayer[$i]->layer_metadataurl);$j++){
-
 			//check for returned format?
 			if (($this->objLayer[$i]->layer_metadataurl[$j]->type == 'ISO19115:2003' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml') || ($this->objLayer[$i]->layer_metadataurl[$j]->type == 'TC211' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml')) {
 				//load metadata from link
-				$metadataConnector = new connector($this->objLayer[$i]->layer_metadataurl[$j]->href);
-				$metaData = $metadataConnector->file;
-				//delete getRecordByIdResponse from xml if there cause we handle only iso19139 files !
-				$regex = "#<csw:GetRecordByIdResponse .*?>#";
-				$output = preg_replace($regex,"",$metaData);
-				$regex = "#</csw:GetRecordByIdResponse>#";
-				$output = preg_replace($regex,"",$output);
-				//$e = new mb_exception($output);
-				$metaData = $output;
-				//parse metadata
-				libxml_use_internal_errors(true);
-				try {
-					$iso19139Xml = simplexml_load_string($metaData);
-					//$iso19139Xml =  new SimpleXMLElement($metaData);
-					if ($iso19139Xml === false) {
-						foreach(libxml_get_errors() as $error) {
-        						$e = new mb_exception($error->message);
-    						}
-						throw new Exception('Cannot parse Metadata XML!');
-					}
-				}
-				catch (Exception $e) {
-    					$e = new mb_exception($e->getMessage());
-				}
-				if ($iso19139Xml != false) {
-					//get elements for database from xml by using xpath
-					//uuid
-					$uuid = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
-					//createdate
-					$createdate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
-					//changedate
-					$changedate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
-					//TODO: check if this is set, maybe DateTime must be searched instead?
-					//title
-					$title = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString');
-					//dataset identifier - howto model into md_metadata?
-					//check where datasetid is defined - maybe as RS_Identifier or as MD_Identifier see http://inspire.jrc.ec.europa.eu/documents/Metadata/INSPIRE_MD_IR_and_ISO_v1_2_20100616.pdf page 18
-					//First check if MD_Identifier is set, then check if RS_Identifier is used!
-					//Initialize datasetid
-					$datasetid = 'undefined';
-					$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString');
-					if (isset($code[0]) && $code[0] != '') {
-						$e = new mb_notice("class_wms.php: code given thru MD_Identifier: ".$code[0]);
-						//check if code is defined by codespace and code
-						$codeSplit = explode("#",$code);
-						if (isset($codeSplit[0]) && $codeSplit[0] != '' && isset($codeSplit[1]) && $codeSplit[1] != '') {
-							$e = new mb_notice("class_wms.php: code was constructed via codespace#code !");	
-							$datasetid = $codeSplit[0]."#".$codeSplit[1];
-						
-							
-						} else {
-							$e = new mb_notice("class_wms.php: code was not constructed via codespace#code !");	
-							$datasetid = $code;
+				$mbMetadata = new Iso19139();
+				$randomid = new Uuid();
+				$mbMetadata = $mbMetadata->createFromUrl($this->objLayer[$i]->layer_metadataurl[$j]->href);
+				if ($mbMetadata != false) {
+					//create randomId for metadata
+					$mbMetadata->randomId = $randomid;
+					$mbMetadata->href = $this->objLayer[$i]->layer_metadataurl[$j]->href;
+					$mbMetadata->format = $this->objLayer[$i]->layer_metadataurl[$j]->format;
+					$mbMetadata->type = $this->objLayer[$i]->layer_metadataurl[$j]->type;
+					$mbMetadata->origin = "capabilities";
+					if ($mbMetadata->insertToDB()){
+						//get inserted metadata_id
+						$sql = <<<SQL
+SELECT metadata_id FROM mb_metadata WHERE randomid = $1
+SQL;
+						//maybe there are more than one results - which should be used??? case of creating new linkage with old metadata TODO TODO
+						$v = array($randomid);
+						$t = array('s');
+						try {
+							$res = db_prep_query($sql,$v,$t);
 						}
-					} else { //try to read code from RS_Identifier 		
-						$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
-						$codeSpace = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:codeSpace/gco:CharacterString');
-					#$e = new mb_exception("class_wms.php: code: ".$code[0]);
-					#$e = new mb_exception("class_wms.php: codeSpace: ".$codeSpace[0]);
-						if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
-							$datasetid = $codeSpace[0]."#".$code[0];
-							$e = new mb_notice("class_wms.php: datasetid: ".$datasetid);
+						catch (Exception $e){
+							$e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+						}
+						if (!$res) {
+							//do nothing
 						} else {
-							//neither MD_Identifier nor RS_Identifier are defined in a right way
-							$e = new mb_notice("class_wms.php: the service data coupling has problems, cause the metadata doesnt have defined a datasetid");
+							//insert relation
+							$row = db_fetch_assoc($res);
+							$metadata_id = $row['metadata_id'];
+							//insert relation to layer
+							$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
+							$v = array($this->objLayer[$i]->db_id, $metadata_id);
+							$t = array('i','i');
+							$res = db_prep_query($sql,$v,$t);
+							if(!$res){
+								db_rollback();	
+							} else {
+								$sql = "UPDATE mb_metadata SET harvestresult = 1 where metadata_id = $1";
+								$v = array($metadata_id);
+								$t = array('i');
+								$res = db_prep_query($sql,$v,$t);
+							}		
 						}
 					}
-					//abstract
-					$abstract = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString');
-					//searchtext -- use keywords!
-					$keywords = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString');
-					//type 
-					$type = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
-					//tmp_reference_1
-					$tmp_reference_1 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
-					//tmp_reference_2
-					$tmp_reference_2 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition');			//spatial_res_type
-					//spatial_res_value
-					//ref_system
-					//format
-					//inspire_charset
-					//inspire_top_consistence
-					//responsible_party
-					//fees
-					//"constraints"	
-					//fill database with elements:
-					$sql = "INSERT INTO mb_metadata (link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid) ";
-					$sql .= "VALUES($1, 'capabilities', $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)";
+				} else {
+					//parsing made problems - fill only the urls into database and give a reasonable error message
+					$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype, randomid) ";
+					$sql .= "VALUES($1, 'capabilities', $2, $3, $4)";
 					$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,
 						$this->objLayer[$i]->layer_metadataurl[$j]->format,
-						$metaData,
 						$this->objLayer[$i]->layer_metadataurl[$j]->type,
-						$uuid[0],
-						$title[0],
-						$createdate[0],
-						$changedate[0],
-						$abstract[0],
-						$keywords[0],
-						$type[0],
-						$tmp_reference_1[0],
-						$tmp_reference_2[0],
-						't',
-						$datasetid
+						$randomid	
 					);
-					$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s');
+					$t = array('s','s','s','s');
 					$res = db_prep_query($sql,$v,$t);
 					if(!$res){
 						db_rollback();	
-					}
-					//get last inserted serial_id
-					$mdId = db_insert_id($con, 'mb_metadata','metadata_id');
-					//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
-					$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
-					$v = array($this->objLayer[$i]->db_id, $mdId);
-					$t = array('i','i');
-					$res = db_prep_query($sql,$v,$t);
-					if(!$res){
-						db_rollback();	
 					} else {
-						$sql = "UPDATE mb_metadata SET harvestresult = 1 where metadata_id = $1";
-						$v = array($mdId);
-						$t = array('i');
-						$res = db_prep_query($sql,$v,$t);
-					}		
-				} else {
-				//parsing was not ok - fill only the urls into database and give a reasonable error message
-					$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype) ";
-					$sql .= "VALUES($1, 'capabilities', $2, $3)";
-					$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,
-						$this->objLayer[$i]->layer_metadataurl[$j]->format,
-						$this->objLayer[$i]->layer_metadataurl[$j]->type		
-					);
-					$t = array('s','s','s');
-					$res = db_prep_query($sql,$v,$t);
-					if(!$res){
-						db_rollback();	
+						//get last inserted metadata_id
+						$sql = <<<SQL
+SELECT metadata_id FROM mb_metadata WHERE randomid = $1
+SQL;
+						//maybe there are more than one results - which should be used??? case of creating new linkage with old metadata TODO TODO
+						$v = array($randomid);
+						$t = array('s');
+						try {
+							$res = db_prep_query($sql,$v,$t);
+						}
+						catch (Exception $e){
+							$e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+						}
+						if (!$res) {
+							//do nothing
+						} else {
+							//insert relation
+							$row = db_fetch_assoc($res);
+							$metadata_id = $row['metadata_id'];
+							//insert relation to layer
+							$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
+							$v = array($this->objLayer[$i]->db_id, $metadata_id);
+							$t = array('i','i');
+							$res = db_prep_query($sql,$v,$t);
+							if(!$res){
+								db_rollback();
+								//TODO delete mb_metadata from table, cause the relation cannot be inserted
+							} else {
+								$sql = "UPDATE mb_metadata SET harvestresult = 0, harvestexception = 'Problem occured while parsing ISO19139 metadata!' where metadata_id = $1";
+								$v = array($metadata_id);
+								$t = array('i');
+								$res = db_prep_query($sql,$v,$t);
+							}		
+						}
 					}
-					//get last inserted serial_id
-					$mdId = db_insert_id($con, 'mb_metadata','metadata_id');
-					//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
-					$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
-					$v = array($this->objLayer[$i]->db_id, $mdId);
-					$t = array('i','i');
-					$res = db_prep_query($sql,$v,$t);
-					if(!$res){
-						db_rollback();	
-					} else {
-						//set harvest result to 0 cause this metadata had problems while parsing
-						$sql = "UPDATE mb_metadata SET harvestresult = 0, harvestexception = 'Problem occured while parsing ISO19139 metadata!' where metadata_id = $1";
-						$v = array($mdId);
-						$t = array('i');
-						$res = db_prep_query($sql,$v,$t);
-					}
-				
-				}
-			} else {//no readable format given - only store the links!
-				//don't push single elements into database
-				$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype) ";
-				$sql .= "VALUES($1, 'capabilities', $2, $3)";
-				$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,
-					$this->objLayer[$i]->layer_metadataurl[$j]->format,
-					$this->objLayer[$i]->layer_metadataurl[$j]->type		
-				);
-				$t = array('s','s','s');
-				$res = db_prep_query($sql,$v,$t);
-				if(!$res){
-					db_rollback();	
-				}
-				//get last inserted serial_id
-				$mdId = db_insert_id($con, 'mb_metadata','metadata_id');
-				//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
-				$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values ($1, $2);";
-				$v = array($this->objLayer[$i]->db_id, $mdId);
-				$t = array('i','i');
-				$res = db_prep_query($sql,$v,$t);
-				if(!$res){
-					db_rollback();	
-				} else {
-					//set harvest result to 0 cause this metadata format can not to be parsed
-					$sql = "UPDATE mb_metadata SET harvestresult = 0 where metadata_id = $1";
-					$v = array($mdId);
-					$t = array('i');
-					$res = db_prep_query($sql,$v,$t);
-				}
+				} //either links or metadata stored to database
 			}
 		}
 	}
-	
 
 
 

Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -179,7 +179,7 @@
 //function to give away the xml data
 function pushISO19139($iso19139Doc, $recordId) {
 	//echo $recordId;
-	header("Content-type: application/xhtml+xml; charset=UTF-8");
+	header("Content-type: text/xml; charset=UTF-8");
 	$xml = fillISO19139($iso19139Doc, $recordId);
 	echo $xml;
 	die();
@@ -304,17 +304,19 @@
 	$userMetadata = db_fetch_array($res);
 	//check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
 	$hasPermission=$admin->getLayerPermission($mapbenderMetadata['wms_id'],$mapbenderMetadata['layer_name'],PUBLIC_USER);
+	//schemas for metadata:
+	/*
+	<gmd:MD_Metadata xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/gmd.xsd" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
+	*/
 	//Creating the "MD_Metadata" node
-	$MD_Metadata = $iso19139->createElementNS('http://www.isotc211.org/2005/gmd', 'gmd:MD_Metadata');
+	$MD_Metadata = $iso19139->createElement("gmd:MD_Metadata");
 	$MD_Metadata = $iso19139->appendChild($MD_Metadata);
-	$MD_Metadata->setAttribute("xmlns:srv", "http://www.isotc211.org/2005/srv");
+	$MD_Metadata->setAttribute("xsi:schemaLocation", "http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/gmd.xsd");
+	$MD_Metadata->setAttribute("xmlns:gmd", "http://www.isotc211.org/2005/gmd");
+	$MD_Metadata->setAttribute("xmlns:gco", "http://www.isotc211.org/2005/gco");
+	$MD_Metadata->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
 	$MD_Metadata->setAttribute("xmlns:gml", "http://www.opengis.net/gml");
-	$MD_Metadata->setAttribute("xmlns:gco", "http://www.isotc211.org/2005/gco");
 	$MD_Metadata->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-	$MD_Metadata->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
-	#$MD_Metadata->setAttribute("xsi:schemaLocation", "http://www.isotc211.org/2005/gmd ./xsd/gmd/gmd.xsd://www.isotc211.org/2005/srv ./xsd/srv/srv.xsd");
-$MD_Metadata->setAttribute("xsi:schemaLocation", "http://www.isotc211.org/2005/gmd");
-//$MD_Metadata->setAttribute("xsi:schemaLocation=","http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/gmd.xsd");
 
 	//generate fileidentifier part (metadata record identification) 
 	$identifier = $iso19139->createElement("gmd:fileIdentifier");

Modified: trunk/mapbender/http/php/wms.php
===================================================================
--- trunk/mapbender/http/php/wms.php	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/http/php/wms.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -729,7 +729,7 @@
 	$inspire_common_Language = $inspire_common_ResponseLanguage->appendChild($inspire_common_Language);
 }
 ################################################################
-#Querying layer table
+#Querying layer table for root layer information!
 $layer_sql = "SELECT * FROM layer WHERE layer.fkey_wms_id = $1 AND layer.layer_parent = ''";
 $v = array($wms_row['wms_id']);
 $t = array("i");
@@ -762,12 +762,14 @@
 
 #Creating the "Abstract" node
 if($layer_row['layer_abstract'] <> "" AND $layer_row['layer_abstract'] <> NULL) {
+	$layerAbstract = $layer_row['layer_abstract'];
+} else {
+	$layerAbstract = _mb("Layer abstract not given - please give a description for this layer.");
+}
     $abstract = $doc->createElement("Abstract");
     $abstract = $layer->appendChild($abstract);
-    $abstractText = $doc->createTextNode($layer_row['layer_abstract']);
-    $abstractText = $abstract->appendChild($abstractText);	
-}
-
+    $abstractText = $doc->createTextNode($layerAbstract);
+    $abstractText = $abstract->appendChild($abstractText);
 #Request the specific wms- and layerkeywords
 
 $keyword_sql = "SELECT DISTINCT keyword FROM keyword, layer_keyword, layer " . 
@@ -792,10 +794,12 @@
     }
     
     #Creating the "Keyword" node
-    $keyword_dom = $doc->createElement("Keyword");
-    $keyword_dom = $keywordList->appendChild($keyword_dom); 
-    $keyword_domText = $doc->createTextNode($keyword_sql['keyword']);
-    $keyword_domText = $keyword_dom->appendChild($keyword_domText);
+	if (trim($keyword_sql['keyword']) <> "" AND $keyword_sql['keyword'] <> NULL) {
+    		$keyword_dom = $doc->createElement("Keyword");
+    		$keyword_dom = $keywordList->appendChild($keyword_dom); 
+    		$keyword_domText = $doc->createTextNode($keyword_sql['keyword']);
+    		$keyword_domText = $keyword_dom->appendChild($keyword_domText);
+	}
 }
 
 
@@ -957,9 +961,9 @@
 	}
 	$sub_layer = $parent->appendChild($sub_layer);
     
-    if($sub_layer_row['layer_queryable'] <> "" AND $sub_layer_row['layer_queryable'] <> NULL) {
+    	if($sub_layer_row['layer_queryable'] <> "" AND $sub_layer_row['layer_queryable'] <> NULL) {
 		$sub_layer->setAttribute('queryable', $sub_layer_row['layer_queryable']);
-    }
+    	}
 	#Getting information about the hierarchie of layers
 	$cascadeSQL = "SELECT COUNT(*) FROM layer WHERE fkey_wms_id = $1 AND layer_parent = $2";
 	
@@ -972,37 +976,37 @@
 	{
 		$cascade = 1;
 	}
-	$sub_layer->setAttribute('cascaded', $cascade);
+	$sub_layer->setAttribute('cascaded', $cascade); //TODO: check if this is right!
 	
 	#Write layer to parent layer array
 	$parentLayerArray[$sub_layer_row['layer_pos']] = $sub_layer;
 	
 	#Creating name node
-    if($sub_layer_row['layer_name'] <> "" AND $sub_layer_row['layer_name'] <> NULL)
-    {
+    	if($sub_layer_row['layer_name'] <> "" AND $sub_layer_row['layer_name'] <> NULL) {
 		$name = $doc->createElement("Name");
 		$name = $sub_layer->appendChild($name);
 		$nameText = $doc->createTextNode($sub_layer_row['layer_name']);
 		$nameText = $name->appendChild($nameText);
-    }
+    	}
 	
 	#Creating Title node
-    if($sub_layer_row['layer_title'] <> "" AND $sub_layer_row['layer_title'] <> NULL)
-    {
+    	if($sub_layer_row['layer_title'] <> "" AND $sub_layer_row['layer_title'] <> NULL) {
 		$title = $doc->createElement("Title");
 		$title = $sub_layer->appendChild($title);
 		$titleText = $doc->createTextNode($sub_layer_row['layer_title']);
 		$titleText = $title->appendChild($titleText);
-    }
+    	}
 	
-		#Creating the "Abstract" node
-    if($sub_layer_row['layer_abstract'] <> "" AND $sub_layer_row['layer_abstract'] <> NULL)
-    {
+	#Creating the "Abstract" node
+    	if($sub_layer_row['layer_abstract'] <> "" AND $sub_layer_row['layer_abstract'] <> NULL) {
+		$layerAbstract = $sub_layer_row['layer_abstract'];
+	} else {
+		$layerAbstract = _mb('No abtract for the specific layer was given, please add a description to your layer ressource.');
+	}
     	$abstract = $doc->createElement("Abstract");
     	$abstract = $sub_layer->appendChild($abstract);
-    	$abstractText = $doc->createTextNode($sub_layer_row['layer_abstract']);
+    	$abstractText = $doc->createTextNode($layerAbstract);
     	$abstractText = $abstract->appendChild($abstractText);
-    }
 	
     #Request the specific wms- and layerkeywords
     $keyword_sql = "SELECT DISTINCT keyword FROM layer LEFT JOIN layer_keyword ON layer_keyword.fkey_layer_id = layer.layer_id LEFT JOIN keyword ON  keyword.keyword_id = layer_keyword.fkey_keyword_id WHERE layer.fkey_wms_id = ".$wms_row['wms_id']." AND layer.layer_id = ".$sub_layer_row['layer_id']."";
@@ -1013,7 +1017,7 @@
     $keywordlistExist = 0;
     while ($keyword_sql = db_fetch_array($res_keyword_sql))
     {
-        #Creating the "KeywordList" node
+        #Initially creating the "KeywordList" node
         if ($keywordlistExist == 0)
         {
             $keywordList = $doc->createElement("KeywordList");
@@ -1023,8 +1027,14 @@
         
         #Creating the "Keyword" node
         $keyword_dom = $doc->createElement("Keyword");
-        $keyword_dom = $keywordList->appendChild($keyword_dom); 
-        $keyword_domText = $doc->createTextNode($keyword_sql['keyword']);
+        $keyword_dom = $keywordList->appendChild($keyword_dom);
+	if (trim($keyword_sql['keyword']) <> "" AND $keyword_sql['keyword'] <> NULL) {
+		$keyword = $keyword_sql['keyword'];
+	} else {
+		$keyword = _mb('Empty keyword was given, please add a keyword to your layer ressource.');
+	}
+        $keyword_domText = $doc->createTextNode($keyword);
+
         $keyword_domText = $keyword_dom->appendChild($keyword_domText);
     }
 

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -920,13 +920,15 @@
 				if (isset($code[0]) && $code[0] != '') {
 					$e = new mb_exception("plugins/mb_metadata_server.php: code given thru MD_Identifier: ".$code[0]);
 					//check if code is defined by codespace and code
-					$codeSplit = explode("#",$code);
+					$codeSplit = explode("#",$code[0]);
 					if (isset($codeSplit[0]) && $codeSplit[0] != '' && isset($codeSplit[1]) && $codeSplit[1] != '') {
 						$e = new mb_exception("plugins/mb_metadata_server.php: code was constructed via codespace#code !");	
-						$datasetid = $codeSplit[0]."#".$codeSplit[1];
+						$datasetid = $code[0];
+						$datasetid_codespace = "";
 					} else {
 						$e = new mb_exception("plugins/mb_metadata_server.php: code was not constructed via codespace#code !");	
 						$datasetid = $code[0];
+						$datasetid_codespace = "";
 					}
 				} else { //try to read code from RS_Identifier 		
 					$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
@@ -934,7 +936,8 @@
 				#$e = new mb_exception("plugins/mb_metadata_server.php: code: ".$code[0]);
 				#$e = new mb_exception("plugins/mb_metadata_server.php: codeSpace: ".$codeSpace[0]);
 					if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
-						$datasetid = $codeSpace[0]."#".$code[0];
+						$datasetid = $code[0];
+						$datasetid_codespace = $codeSpace[0];
 						$e = new mb_exception("plugins/mb_metadata_server.php: datasetid: ".$datasetid);
 					} else {
 						//neither MD_Identifier nor RS_Identifier are defined in a right way
@@ -963,11 +966,11 @@
 
 				$sql = <<<SQL
 
-INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1)
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult, datasetid_codespace) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1, $19)
 
 SQL;
-				$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $metaData);
-				$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s');
+				$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $metaData, $datasetid_codespace);
+				$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s','s');
 		
 				try {
 					$res = db_prep_query($sql,$v,$t);

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-06-06 15:19:06 UTC (rev 8370)
@@ -750,6 +750,7 @@
 				}
 			
 			} else {
+
 				abort(_mb("Problem with parsing the XML structure with SimpleXML! Record was not inserted into database! Ask your administrator."));
 				//give back error message - cause parsing has problems
 			}
@@ -935,10 +936,12 @@
 			$codeSplit = explode("#",$code);
 			if (isset($codeSplit[0]) && $codeSplit[0] != '' && isset($codeSplit[1]) && $codeSplit[1] != '') {
 				$e = new mb_exception("plugins/mb_metadata_server.php: code was constructed via codespace#code !");	
-				$datasetid = $codeSplit[0]."#".$codeSplit[1];
+				$datasetid = $code[0];
+				$datasetid_codespace = "";
 			} else {
 				$e = new mb_exception("plugins/mb_metadata_server.php: code was not constructed via codespace#code !");	
-				$datasetid = $code;
+				$datasetid = $code[0];
+				$datasetid_codespace = "";
 			}
 		} else { //try to read code from RS_Identifier 		
 			$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
@@ -946,7 +949,8 @@
 		#$e = new mb_exception("plugins/mb_metadata_server.php: code: ".$code[0]);
 		#$e = new mb_exception("plugins/mb_metadata_server.php: codeSpace: ".$codeSpace[0]);
 			if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
-				$datasetid = $codeSpace[0]."#".$code[0];
+				$datasetid = $code[0];
+				$datasetid_codespace = $codeSpace[0];
 				$e = new mb_exception("plugins/mb_metadata_server.php: datasetid: ".$datasetid);
 			} else {
 				//neither MD_Identifier nor RS_Identifier are defined in a right way
@@ -976,14 +980,14 @@
 		//fill database with elements:
 		$sql = <<<SQL
 
-INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1)
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult, datasetid_codespace) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1, $19)
 
 			
 SQL;
 			
 		$xml = $iso19139Xml->asXML();
-		$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $xml);
-		$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s');
+		$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw, $inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $xml,$datasetid_codespace);
+		$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s','s');
 		
 		try {
 				$res = db_prep_query($sql,$v,$t);

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-06-06 11:56:32 UTC (rev 8369)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-06-06 15:19:06 UTC (rev 8370)
@@ -437,5 +437,6 @@
 
 ALTER TABLE mb_monitor ALTER COLUMN map_url TYPE varchar;
 ALTER TABLE mb_monitor ALTER COLUMN cap_diff TYPE text; 
+--Add handling of codespaces as demanded from the INSPIRE regulation
+ALTER TABLE mb_metadata ADD COLUMN datasetid_codespace TEXT;
 
-



More information about the Mapbender_commits mailing list