[Mapbender-commits] r9286 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Sep 10 07:31:17 PDT 2015


Author: armin11
Date: 2015-09-10 07:31:16 -0700 (Thu, 10 Sep 2015)
New Revision: 9286

Modified:
   trunk/mapbender/http/classes/class_wfs_1_1_factory.php
Log:
Enhance wfs decribefeaturetype parser for simpeType extensions like used by tinyows (mapservers wfs-t)

Modified: trunk/mapbender/http/classes/class_wfs_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2015-09-09 13:40:48 UTC (rev 9285)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2015-09-10 14:31:16 UTC (rev 9286)
@@ -95,13 +95,13 @@
 		$xpath =  new DOMXpath($doc);
 		$xpath->registerNamespace("xs","http://www.w3.org/2001/XMLSchema");
 
-		// populate a Namespaces Hastable where we can use thec namesopace as a lookup for the prefix
+		// populate a Namespaces Hastable where we can use the namesopace as a lookup for the prefix
 		// and also keep a 
 		$namespaces = array();
 		$namespaceList = $xpath->query("//namespace::*");
 		$targetNamespace = $doc->documentElement->getAttribute("targetNamespace");
 		$targetNamespaceNode = null;
-
+		//add all namespaces to featuretype
 		foreach($namespaceList as $namespaceNode){
 			$namespaces[$namespaceNode->nodeValue] = $namespaceNode->localName;
 			if($namespaceNode->nodeValue == $targetNamespace){
@@ -114,48 +114,62 @@
 		// for the sake of simplicity we only care about top level elements. Seems to have worked so far
 		$query = sprintf("/xs:schema/xs:element[@name='%s']",$ftLocalname);
 		$elementList = $xpath->query($query);
-
 		foreach ($elementList as $elementNode){
 			$elementName = $elementNode->getAttribute("name");
 			$elementType = $elementNode->getAttribute("type");
+            		//if Type is empty, we assume an anonymousType, else we go looking for the anmed Type
+            		if($elementType == ""){
+                		//Just querying for complexTypes containing a Sequence - good enough for Simple Features
+                		$query = "xs:complexType//xs:element";
+                		$subElementList = $xpath->query($query,$elementNode);
+            		} else {
+                		// The elementType is now bound to a prefix e.g. topp:housType
+                		// if the prefix is in the targetNamespace, changces are good it's defined in this very document
+                		// if the prefix is not in the targetNamespace, it's likely not defined here, and we bail
 
-            // if Type is empty, we assume an anonymousType, else we go looking for the anmed Type
-            if($elementType == ""){
-                // Just querying for complexTypes containing a Sequence - good enough for Simple Features
-                $query = "xs:complexType//xs:element";
-                $subElementList = $xpath->query($query,$elementNode);
+                		list($elementTypeLocalname,$elementTypePrefix) = array_reverse(explode(":",$elementType));
+                		$elementTypeNamespace = $doc->lookupNamespaceURI($elementTypePrefix);
+                		if($elementTypeNamespace !== $targetNamespaceNode->nodeValue){
+                    			$e = new mb_warning("Tried to parse FeatureTypeName $featureTypeName : $elementType is not in the targetNamespace");	
+                    			break;
+                		}
 
-            }else{
-
-                // The elementType is now bound to a prefix e.g. topp:housType
-                // if the prefix is in the targetNamespace, changces are good it's defined in this very document
-                // if the prefiox is not in the targetNamespace, it's likely not defined here, and we bail
-
-                list($elementTypeLocalname,$elementTypePrefix) = array_reverse(explode(":",$elementType));
-                $elementTypeNamespace = $doc->lookupNamespaceURI($elementTypePrefix);
-                if($elementTypeNamespace !== $targetNamespaceNode->nodeValue){
-                    $e = new mb_warning("Tried to parse FeatureTypeName $featureTypeName : $elementType is not in the targetNamespace");	
-                    break;
-                }
-
-                // Just querying for complexTypes containing a Sequence - good enough for Simple Features
-                $query = sprintf("//xs:complexType[@name='%s']//xs:element",$elementTypeLocalname);
-                $subElementList = $xpath->query($query);
-
-            }
-			foreach($subElementList as $subElement){
-                // Since this is a rewrite of the old way, it reproduces it quirks
-                // in this case the namespace of the type was cut off for some reason
+                		// Just querying for complexTypes containing a Sequence - good enough for Simple Features
+                		$query = sprintf("//xs:complexType[@name='%s']//xs:element",$elementTypeLocalname);
+                		$subElementList = $xpath->query($query);
+            		}
+	    		foreach ($subElementList as $subElement) {
+            			// Since this is a rewrite of the old way, it reproduces it quirks
+                		// in this case the namespace of the type was cut off for some reason
 				$name = $subElement->getAttribute('name');
-                $typeParts = explode(":",$subElement->getAttribute('type'));
-                if(count($typeParts) == 1){
-                    $type = $typeParts[0];
-                }else{
-                    $type = $typeParts[1];
-                }
-				$newFeatureType->addElement($name,$type);
-			}
-
+                		$typeParts = explode(":",$subElement->getAttribute('type'));
+				//$e = new mb_exception("element: ".$name." - type: ".$typeParts[0]);
+				if (empty($typeParts[0])) {
+					$e = new mb_warning("No type attribute found in xs:element - test for integrated simpleType!");
+					//it maybe a simple type
+					/*<xs:element name="kennung" nillable="true" minOccurs="0" maxOccurs="1">
+						<xs:simpleType>
+							<xs:restriction base="string">
+								<xs:maxLength value="40"/>
+							</xs:restriction>
+						</xs:simpleType>
+					</xs:element>*/
+					$query = "xs:simpleType/xs:restriction";
+					$restriction = $xpath->query($query,$subElement);
+					$type = $restriction->item(0)->getAttribute('base');
+					//TODO parse further information from xsd like maxLength: <xs:maxLength value="40"/> - add further column in wfs_element!
+				} else {
+					switch (count($typeParts)) {
+						case 1 :
+							$type = $typeParts[0];
+						break;
+						case 2 :
+							$type = $typeParts[1];
+						break;
+					}
+				}
+	    			$newFeatureType->addElement($name,$type);
+	    		}
 		}
 		return $newFeatureType;
 	}



More information about the Mapbender_commits mailing list