[Mapbender-commits] r7638 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Feb 23 05:13:28 EST 2011
Author: kmq
Date: 2011-02-23 02:13:28 -0800 (Wed, 23 Feb 2011)
New Revision: 7638
Modified:
trunk/mapbender/http/classes/class_wfs_1_0_factory.php
trunk/mapbender/http/classes/class_wfs_1_1_factory.php
Log:
fix for ticket #778
Modified: trunk/mapbender/http/classes/class_wfs_1_0_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0_factory.php 2011-02-22 23:59:00 UTC (rev 7637)
+++ trunk/mapbender/http/classes/class_wfs_1_0_factory.php 2011-02-23 10:13:28 UTC (rev 7638)
@@ -44,37 +44,57 @@
protected function createFeatureTypeFromXml ($xml, $myWfs) {
$newFeatureType = new WfsFeatureType($myWfs);
- $admin = new administration();
- $values = $admin->parseXml($xml);
+ $doc = new DOMDocument();
+ $doc->loadXML($xml);
+ $xpath = new DOMXpath($doc);
+ $xpath->registerNamespace("xs","http://www.w3.org/2001/XMLSchema");
- foreach ($values as $element) {
- if ($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open") {
- $section = "namespace";
+ // populate a Namespaces Hastable where we can use thec namesopace as a lookup for the prefix
+ // and also keep a
+ $namespaces = array();
+ $namespaceList = $xpath->query("//namespace::*");
+ $targetNamespace = $doc->documentElement->getAttribute("targetNamespace");
+ $targetNamespaceNode = null;
+
+ foreach($namespaceList as $namespaceNode){
+ $namespaces[$namespaceNode->nodeValue] = $namespaceNode->localName;
+ if($namespaceNode->nodeValue == $targetNamespace){
+ $targetNamespaceNode = $namespaceNode;
}
-
- if ($section == "namespace" && is_array($element[attributes])) {
-
- while (list($k, $val) = each ($element[attributes])) {
- if (substr($k, 0, 5) == "xmlns") {
- $key = $this->sepNameSpace($k);
- $newFeatureType->addNamespace($key, $val);
- }
- }
+ $newFeatureType->addNamespace($namespaceNode->localName, $namespaceNode->nodeValue);
+ }
+
+
+ list($ftLocalname,$ftTypePrefix) = array_reverse(explode(":",$featureTypeName));
+ // 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");
+
+ // 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;
}
- if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "open"){
- $section = "complexcontent";
+
+ // 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);
+ $e = new mb_exception("NNN sub $query $subElementList->length");
+ foreach($subElementList as $subElement){
+ $newFeatureType->addElement($subElement->getAttribute('name'), $subElement->getAttribute('type'));
}
- if($section == "complexcontent" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
- $newFeatureType->addElement(
- $element[attributes]["name"],
- $this->sepNameSpace($element[attributes]["type"])
- );
- }
- if($this->sepNameSpace($element[tag]) == "complexContent" && $element[type] == "close"){
- $section = "";
- }
- }
- return $newFeatureType;
+
+ }
+ return $newFeatureType;
}
/**
@@ -203,4 +223,4 @@
return parent::createFromDb($id, $myWfs);
}
}
-?>
\ No newline at end of file
+?>
Modified: trunk/mapbender/http/classes/class_wfs_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1_factory.php 2011-02-22 23:59:00 UTC (rev 7637)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php 2011-02-23 10:13:28 UTC (rev 7638)
@@ -76,38 +76,64 @@
return $this->createFeatureTypeFromXml ($xml, $aWfs, $featureTypeName);
}
+ /**
+ * Given an XSD document (usually from a DescribefeatureType Operation)
+ * @returns a WfsFeatureType
+ *
+
+ */
protected function createFeatureTypeFromXml ($xml, $myWfs, $featureTypeName) {
$newFeatureType = new WfsFeatureType($myWfs);
- $admin = new administration();
- $values = $admin->parseXml($xml);
+ $doc = new DOMDocument();
+ $doc->loadXML($xml);
+ $xpath = new DOMXpath($doc);
+ $xpath->registerNamespace("xs","http://www.w3.org/2001/XMLSchema");
- foreach ($values as $element) {
- if ($this->sepNameSpace($element[tag]) == "schema" && $element[type] == "open") {
- $section = "namespace";
+ // populate a Namespaces Hastable where we can use thec namesopace as a lookup for the prefix
+ // and also keep a
+ $namespaces = array();
+ $namespaceList = $xpath->query("//namespace::*");
+ $targetNamespace = $doc->documentElement->getAttribute("targetNamespace");
+ $targetNamespaceNode = null;
+
+ foreach($namespaceList as $namespaceNode){
+ $namespaces[$namespaceNode->nodeValue] = $namespaceNode->localName;
+ if($namespaceNode->nodeValue == $targetNamespace){
+ $targetNamespaceNode = $namespaceNode;
}
+ $newFeatureType->addNamespace($namespaceNode->localName, $namespaceNode->nodeValue);
+ }
+
- if ($section == "namespace" && is_array($element[attributes])) {
+ list($ftLocalname,$ftTypePrefix) = array_reverse(explode(":",$featureTypeName));
+ // 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);
- while (list($k, $val) = each ($element[attributes])) {
- if (substr($k, 0, 5) == "xmlns") {
- $key = $this->sepNameSpace($k);
- $newFeatureType->addNamespace($key, $val);
- }
- }
+ foreach ($elementList as $elementNode){
+ $elementName = $elementNode->getAttribute("name");
+ $elementType = $elementNode->getAttribute("type");
+
+ // 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;
}
- if($this->sepNameSpace($element[tag]) == "complexType" && $element[type] == "open" && $element[attributes]["name"] === $featureTypeName . "Type"){
- $section = "complexType";
+
+ // 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);
+ $e = new mb_exception("NNN sub $query $subElementList->length");
+ foreach($subElementList as $subElement){
+ $newFeatureType->addElement($subElement->getAttribute('name'), $subElement->getAttribute('type'));
}
- if($section == "complexType" && $this->sepNameSpace($element[tag]) == "element" && $element[attributes][name]){
- $newFeatureType->addElement(
- $element[attributes]["name"],
- $this->sepNameSpace($element[attributes]["type"])
- );
- }
- if($this->sepNameSpace($element[tag]) == "complexType" && $element[type] == "close"){
- $section = "";
- }
+
}
return $newFeatureType;
}
@@ -248,4 +274,4 @@
return parent::createFromDb($id, $myWfs);
}
}
-?>
\ No newline at end of file
+?>
More information about the Mapbender_commits
mailing list