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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Feb 4 05:22:50 EST 2009


Author: christoph
Date: 2009-02-04 05:22:50 -0500 (Wed, 04 Feb 2009)
New Revision: 3516

Modified:
   trunk/mapbender/http/classes/class_ows_factory.php
   trunk/mapbender/http/classes/class_wfs_1_0_factory.php
   trunk/mapbender/http/classes/class_wfs_1_1_factory.php
   trunk/mapbender/http/classes/class_wfs_factory.php
Log:
DescribeFeatureType is now done via POST, because of namespaced featuretype names

Modified: trunk/mapbender/http/classes/class_ows_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_ows_factory.php	2009-02-04 10:20:40 UTC (rev 3515)
+++ trunk/mapbender/http/classes/class_ows_factory.php	2009-02-04 10:22:50 UTC (rev 3516)
@@ -76,14 +76,31 @@
 		}
 		return $s;
 	}
+	
+	/**
+	 * Get namespace from a tag name.
+	 * 
+	 * Example: input is "topp:the_geom" will return "topp".
+	 * 
+	 * @return String
+	 * @param $s String
+	 */
+	final protected function getNameSpace($s) {
+		$c = strpos($s, ":"); 
+		if ($c > 0) {
+			return substr($s, 0, $c);
+		}
+		return $s;
+	}
 
 	/**
-	 * Retrieves a document from a URL, presumably a capabilities document.
+	 * Retrieves a document from a URL, presumably a 
+	 * capabilities document, via GET.
 	 * 
 	 * @return String
 	 * @param $url String
 	 */
-	final protected function getFromUrl ($url) {
+	final protected function get ($url) {
 		$x = new connector($url);
 		$xml = $x->file;
 		if(!$xml){
@@ -94,6 +111,27 @@
 	}
 
 	/**
+	 * Retrieves a document from a URL, presumably a 
+	 * describe feature type document, via POST
+	 * 
+	 * @return String
+	 * @param $url String
+	 */
+	final protected function post ($url, $postData) {
+		$x = new connector();
+		$x->set("httpType", "post");
+		$x->set("httpPostData", $postData);
+		$x->set("httpContentType", "XML");
+		
+		$xml = $x->load($url);
+		if(!$xml){
+			throw new Exception("Unable to open document: " . $url);
+			return null;
+		}
+		return $xml;		
+	}
+
+	/**
 	 * Creates an OWS from an XML, presumably a capabilities document, 
 	 * which is retrieved from a URL.
 	 * 
@@ -102,7 +140,7 @@
 	 */
 	final public function createFromUrl ($url) {
 		try {
-			$xml = $this->getFromUrl($url);
+			$xml = $this->get($url);
 	
 			$myOws = $this->createFromXml($xml);
 			if ($myOws != null) {

Modified: trunk/mapbender/http/classes/class_wfs_1_0_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0_factory.php	2009-02-04 10:20:40 UTC (rev 3515)
+++ trunk/mapbender/http/classes/class_wfs_1_0_factory.php	2009-02-04 10:22:50 UTC (rev 3516)
@@ -31,7 +31,7 @@
  */
 class Wfs_1_0_Factory extends WfsFactory {
 
-	private function createFeatureTypeFromXml ($xml, $myWfs) {
+	protected function createFeatureTypeFromXml ($xml, $myWfs) {
 		$newFeatureType = new Wfs_1_0_FeatureType($myWfs);
 
 		$admin = new administration();
@@ -67,11 +67,6 @@
 		return $newFeatureType;	
 	}
 
-	private function createFeatureTypeFromUrl ($url, $aWfs) {
-		$xml = $this->getFromUrl($url);
-		return $this->createFeatureTypeFromXml ($xml, $aWfs);
-	}
-
 	/**
 	 * Creates WFS 1.0 objects from a capabilities documents.
 	 * 
@@ -118,7 +113,7 @@
 				if($tag == "GETCAPABILITIES" && $element[type] == "open"){
 					$section = "getcapabilities";
 				}
-				if($section == "getcapabilities" && $tag == "POST"){
+				if($section == "getcapabilities" && $tag == "GET"){
 					$myWfs->getCapabilities = $element[attributes][onlineResource];
 				}
 				
@@ -155,6 +150,7 @@
 				}
 				if($tag == "FEATURETYPE" && $element[type] == "open"){
 					$section = "featuretype";
+					$featureTypeNsArray = $element[attributes];
 				}
 				if($section == "featuretype" && $tag == "NAME"){
 					$featuretype_name = $element[value];
@@ -168,10 +164,7 @@
 				if($section == "featuretype" && $tag == "SRS"){
 					$featuretype_srs = $element[value];
 
-					$describeFeatureTypeUrl = $myWfs->describeFeatureType . "&SERVICE=WFS&VERSION=" . 
-							$myWfs->version . "&REQUEST=DescribeFeatureType&TYPENAME=" . $this->sepNameSpace($featuretype_name);
-
-					$currentFeatureType = $this->createFeatureTypeFromUrl($describeFeatureTypeUrl, $myWfs);
+					$currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name, $featureTypeNsArray);
 					if ($currentFeatureType !== null) {
 						$currentFeatureType->name = $this->sepNameSpace($featuretype_name);
 						$currentFeatureType->title = $featuretype_title;

Modified: trunk/mapbender/http/classes/class_wfs_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2009-02-04 10:20:40 UTC (rev 3515)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2009-02-04 10:22:50 UTC (rev 3516)
@@ -31,7 +31,7 @@
  */
 class Wfs_1_1_Factory extends WfsFactory {
 
-	private function createFeatureTypeFromXml ($xml, $myWfs) {
+	protected function createFeatureTypeFromXml ($xml, $myWfs) {
 		$newFeatureType = new Wfs_1_1_FeatureType($myWfs);
 
 		$admin = new administration();
@@ -67,11 +67,6 @@
 		return $newFeatureType;	
 	}
 
-	private function createFeatureTypeFromUrl ($url, $aWfs) {
-		$xml = $this->getFromUrl($url);
-		return $this->createFeatureTypeFromXml ($xml, $aWfs);
-	}
-
 	/**
 	 * Creates WFS 1.0 objects from a capabilities documents.
 	 * 
@@ -131,7 +126,7 @@
 					}
 				}
 				# getCapabilities
-				if($section == "getcapabilities" && $tag == "POST"){
+				if($section == "getcapabilities" && $tag == "GET"){
 					$myWfs->getCapabilities = html_entity_decode($element[attributes]["xlink:href"]);
 				}
 			
@@ -156,6 +151,7 @@
 
 				if($tag == "FEATURETYPE" && $element[type] == "open"){
 					$section = "featuretype";
+					$featureTypeNsArray = $element[attributes];
 				}
 				if($section == "featuretype" && $tag == "NAME"){
 					$featuretype_name = $element[value];
@@ -169,10 +165,7 @@
 				if($section == "featuretype" && $tag == "DEFAULTSRS"){
 					$featuretype_srs = $element[value];
 
-					$describeFeatureTypeUrl = $myWfs->describeFeatureType . "&SERVICE=WFS&VERSION=" . 
-							$myWfs->version . "&REQUEST=DescribeFeatureType&TYPENAME=" . $this->sepNameSpace($featuretype_name);
-
-					$currentFeatureType = $this->createFeatureTypeFromUrl($describeFeatureTypeUrl, $myWfs);
+					$currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name, $featureTypeNsArray);
 					if ($currentFeatureType !== null) {
 						$currentFeatureType->name = $this->sepNameSpace($featuretype_name);
 						$currentFeatureType->title = $featuretype_title;

Modified: trunk/mapbender/http/classes/class_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_factory.php	2009-02-04 10:20:40 UTC (rev 3515)
+++ trunk/mapbender/http/classes/class_wfs_factory.php	2009-02-04 10:22:50 UTC (rev 3516)
@@ -47,7 +47,23 @@
 		}
 		throw new Exception("WFS version could not be determined from XML.");
 	}
-	
+
+	protected function createFeatureTypeFromUrl ($aWfs, $featureTypeName, $featureTypeNsArray) {
+		$postData = "<?xml version=\"1.0\"?>\n".
+				"<DescribeFeatureType version=\"" . $aWfs->getVersion() . "\" " . 
+				"service=\"WFS\" xmlns=\"http://www.opengis.net/wfs\" ";
+				
+		if ($featuretype_name != $this->sepNameSpace($featureTypeName)) {
+			$key = "xmlns:" . $this->getNameSpace($featureTypeName);
+			$postData .= $key . "=\"" . $featureTypeNsArray[$key] . "\" ";
+		}
+		$postData .= "><TypeName>" . $featureTypeName . "</TypeName>" . 
+				"</DescribeFeatureType>";
+
+		$xml = $this->post($aWfs->describeFeatureType, $postData);
+		return $this->createFeatureTypeFromXml ($xml, $aWfs);
+	}
+		
 	/**
 	 * Retrieves the data of a WFS from the database and initiates the object.
 	 * 



More information about the Mapbender_commits mailing list