[Mapbender-commits] r3517 - in trunk/mapbender/http: classes
javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Feb 5 04:46:20 EST 2009
Author: christoph
Date: 2009-02-05 04:46:20 -0500 (Thu, 05 Feb 2009)
New Revision: 3517
Modified:
trunk/mapbender/http/classes/class_connector.php
trunk/mapbender/http/classes/class_ows.php
trunk/mapbender/http/classes/class_wfs.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
trunk/mapbender/http/classes/class_wfs_featuretype.php
trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
trunk/mapbender/http/php/mod_loadwfs.php
Log:
wfs featuretype is no longer abstract
getfeature us done via POST
Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_connector.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -55,6 +55,10 @@
* Loads content from the given URL.
*/
public function load($url) {
+ if (!$url) {
+ $e = new mb_exception("connector: no URL given");
+ return false;
+ }
switch ($this->connectionType) {
case "curl":
if (in_array($host, $NOT_PROXY_HOSTS_array)){
Modified: trunk/mapbender/http/classes/class_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_ows.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_ows.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -45,7 +45,24 @@
var $electronicMailAddress;
var $country;
+
/**
+ * 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;
+ }
+
+ /**
* Returns the conjunction character of an URL
*
* @param String $url
Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_wfs.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -46,21 +46,62 @@
array_push($this->featureTypeArray, $aFeatureType);
}
+ protected function findFeatureTypeByName ($name) {
+ foreach ($this->featureTypeArray as $ft) {
+ if ($ft->name == $name) {
+ return $ft;
+ }
+ }
+ return null;
+ }
+
public function getFeature ($featureTypeName, $filter) {
+/* POST */
- $url = $this->getFeature .
- $this->getConjunctionCharacter($this->getFeature) .
- "service=WFS&request=getFeature&version=" .
- $this->getVersion() . "&typename=" . $featureTypeName .
- "&filter=" . urlencode($filter);
+ $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+ "<wfs:GetFeature version=\"" . $this->getVersion() . "\" " .
+ "xmlns:wfs=\"http://www.opengis.net/wfs\">" .
+ "<wfs:Query ";
+
+ // add namespace
+ if (strpos($featureTypeName, ":") !== false) {
+ $ft = $this->findFeatureTypeByName($featureTypeName);
+ $ns = $this->getNamespace($featureTypeName);
+ $url = $ft->getNamespace($ns);
+ $postData .= "xmlns:" . $ns . "=\"" . $url . "\" ";
+
+ }
+ $postData .= "typeName=\"" . $featureTypeName . "\"/>" .
+ "</wfs:GetFeature>";
- $connection = new connector($url);
- $data = $connection->file;
+ $connection = new connector();
+ $connection->set("httpType", "post");
+ $connection->set("httpContentType", "xml");
+ $connection->set("httpPostData", $postData);
+
+ $data = $connection->load($this->getFeature);
+
if (!$data) {
- $e = new mb_exception("WFS request returned no result: " . $url);
+ $e = new mb_exception("WFS request returned no result: " . $url . "\n" . $postData);
return null;
}
return $data;
+
+
+/* GET */
+// $url = $this->getFeature .
+// $this->getConjunctionCharacter($this->getFeature) .
+// "service=WFS&request=getFeature&version=" .
+// $this->getVersion() . "&typename=" . $featureTypeName .
+// "&filter=" . urlencode($filter);
+//
+// $connection = new connector($url);
+// $data = $connection->file;
+// if (!$data) {
+// $e = new mb_exception("WFS request returned no result: " . $url);
+// return null;
+// }
+// return $data;
}
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:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_wfs_1_0_factory.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -32,7 +32,7 @@
class Wfs_1_0_Factory extends WfsFactory {
protected function createFeatureTypeFromXml ($xml, $myWfs) {
- $newFeatureType = new Wfs_1_0_FeatureType($myWfs);
+ $newFeatureType = new WfsFeatureType($myWfs);
$admin = new administration();
$values = $admin->parseXml($xml);
@@ -166,7 +166,7 @@
$currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name, $featureTypeNsArray);
if ($currentFeatureType !== null) {
- $currentFeatureType->name = $this->sepNameSpace($featuretype_name);
+ $currentFeatureType->name = $featuretype_name;
$currentFeatureType->title = $featuretype_title;
$currentFeatureType->summary = $featuretype_abstract;
$currentFeatureType->srs = $featuretype_srs;
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:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -32,7 +32,7 @@
class Wfs_1_1_Factory extends WfsFactory {
protected function createFeatureTypeFromXml ($xml, $myWfs) {
- $newFeatureType = new Wfs_1_1_FeatureType($myWfs);
+ $newFeatureType = new WfsFeatureType($myWfs);
$admin = new administration();
$values = $admin->parseXml($xml);
@@ -167,7 +167,7 @@
$currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name, $featureTypeNsArray);
if ($currentFeatureType !== null) {
- $currentFeatureType->name = $this->sepNameSpace($featuretype_name);
+ $currentFeatureType->name = $featuretype_name;
$currentFeatureType->title = $featuretype_title;
$currentFeatureType->summary = $featuretype_abstract;
$currentFeatureType->srs = $featuretype_srs;
Modified: trunk/mapbender/http/classes/class_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_factory.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_wfs_factory.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -20,6 +20,7 @@
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
require_once(dirname(__FILE__)."/../classes/class_administration.php");
require_once(dirname(__FILE__)."/../classes/class_ows_factory.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_featuretype.php");
/**
*
@@ -88,7 +89,6 @@
while(db_fetch_row($res)){
$aWfs->id = db_result($res, $cnt, "wfs_id");
- new mb_exception("WFS:".$aWfs->id);
$aWfs->name = db_result($res, $cnt, "wfs_name");
$aWfs->title = db_result($res, $cnt, "wfs_title");
$aWfs->summary = db_result($res, $cnt, "wfs_abstract");
@@ -112,42 +112,46 @@
while(db_fetch_row($res_fe)){
- $c = count($aWfs->featureTypeArray);
- $aWfs->featureTypeArray[$c]->id = db_result($res_fe, $cnt_fe, "featuretype_id");
- new mb_exception("FT:".$aWfs->featureTypeArray[$c]->id);
- $aWfs->featureTypeArray[$c]->name = db_result($res_fe, $cnt_fe, "featuretype_name");
- $aWfs->featureTypeArray[$c]->title = db_result($res_fe, $cnt_fe, "featuretype_title");
- $aWfs->featureTypeArray[$c]->summary = db_result($res_fe, $cnt_fe, "featuretype_abstract");
- $aWfs->featureTypeArray[$c]->srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
+ $ft = new WfsFeatureType($aWfs);
+ $ft->id = db_result($res_fe, $cnt_fe, "featuretype_id");
+ $ft->name = db_result($res_fe, $cnt_fe, "featuretype_name");
+ $ft->title = db_result($res_fe, $cnt_fe, "featuretype_title");
+ $ft->summary = db_result($res_fe, $cnt_fe, "featuretype_abstract");
+ $ft->srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
// Elements
$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
- $v = array($aWfs->featureTypeArray[$c]->id);
+ $v = array($ft->id);
$t = array("i");
$res_el = db_prep_query($sql_el, $v, $t);
$cnt_el = 0;
while(db_fetch_row($res_el)){
- $z = count($aWfs->featureTypeArray[$c]->elementArray);
- $aWfs->featureTypeArray[$c]->elementArray[$z] = new stdClass();
- $aWfs->featureTypeArray[$c]->elementArray[$z]->id = db_result($res_el, $cnt_el, "element_id");
- $aWfs->featureTypeArray[$c]->elementArray[$z]->name = db_result($res_el, $cnt_el, "element_name");
- $aWfs->featureTypeArray[$c]->elementArray[$z]->type = db_result($res_el, $cnt_el, "element_type");
+
+ $ft->addElement(
+ db_result($res_el, $cnt_el, "element_name"),
+ db_result($res_el, $cnt_el, "element_type"),
+ db_result($res_el, $cnt_el, "element_id")
+ );
$cnt_el++;
}
//Namespaces
$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
- $v = array($aWfs->featureTypeArray[$c]->id);
+ $v = array($ft->id);
$t = array("i");
$res_ns = db_prep_query($sql_ns, $v, $t);
$cnt_ns = 0;
while(db_fetch_row($res_ns)){
- $z = count($aWfs->featureTypeArray[$c]->namespaceArray);
- $aWfs->featureTypeArray[$c]->namespaceArray[$z] = new stdClass();
- $aWfs->featureTypeArray[$c]->namespaceArray[$z]->name = db_result($res_ns, $cnt_ns, "namespace");
- $aWfs->featureTypeArray[$c]->namespaceArray[$z]->value = db_result($res_ns, $cnt_ns, "namespace_location");
+
+ $ft->addNamespace(
+ db_result($res_ns, $cnt_ns, "namespace"),
+ db_result($res_ns, $cnt_ns, "namespace_location")
+ );
$cnt_ns++;
}
+
+ $aWfs->addFeatureType($ft);
+
$cnt_fe++;
}
$cnt++;
Modified: trunk/mapbender/http/classes/class_wfs_featuretype.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_featuretype.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/classes/class_wfs_featuretype.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -22,7 +22,7 @@
require_once(dirname(__FILE__)."/class_administration.php");
require_once(dirname(__FILE__)."/class_wfs.php");
-abstract class WfsFeatureType {
+class WfsFeatureType {
var $id;
var $name;
var $title;
@@ -32,7 +32,11 @@
var $namespaceArray = array();
var $elementArray = array();
- private function hasNamespace ($key, $value) {
+ public function __construct ($aWfs) {
+ $this->wfs = $aWfs;
+ }
+
+ public function hasNamespace ($key, $value) {
for ($i = 0; $i < count($this->namespaceArray); $i++) {
if ($this->namespaceArray[$i]->name == $key &&
$this->namespaceArray[$i]->value == $value)
@@ -43,6 +47,15 @@
return false;
}
+ public function getNamespace ($key) {
+ for ($i = 0; $i < count($this->namespaceArray); $i++) {
+ if ($this->namespaceArray[$i]->name == $key) {
+ return $this->namespaceArray[$i]->value;
+ }
+ }
+ return null;
+ }
+
public function addNamespace ($key, $value) {
if ($this->hasNamespace($key, $value)) {
return $this;
@@ -59,7 +72,14 @@
public function addElement ($name, $type) {
$newElement = new stdClass();
- $newElement->id = null;
+
+ if (func_num_args() == 3) {
+ $newElement->id = func_get_arg(2);
+ }
+ else {
+ $newElement->id = null;
+ }
+
$newElement->name = $name;
$newElement->type = $type;
@@ -94,22 +114,4 @@
return $this->toHtml();
}
}
-
-/**
- * This class will be implemented only if needed
- */
-class Wfs_1_0_FeatureType extends WfsFeatureType {
- public function __construct ($aWfs) {
- $this->wfs = $aWfs;
- }
-}
-
-/**
- * This class will be implemented only if needed
- */
-class Wfs_1_1_FeatureType extends WfsFeatureType {
- public function __construct ($aWfs) {
- $this->wfs = $aWfs;
- }
-}
?>
\ No newline at end of file
Modified: trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/javascripts/mod_wfs_gazetteer_client.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -979,10 +979,6 @@
//andConditions += "</ogc:PropertyIsNull></ogc:Not>";
}
- var u = global_wfsConfObj[global_selectedWfsConfId].wfs_getfeature + parent.mb_getConjunctionCharacter(global_wfsConfObj[global_selectedWfsConfId].wfs_getfeature);
- u += "REQUEST=getFeature&Typename="+global_wfsConfObj[global_selectedWfsConfId].featuretype_name+"&Version=1.0.0&service=WFS";
- u += "&filter=";
-
if (filterParameterCount > 1 || spatialRequestGeom != null) {
andConditions = "<And>" + andConditions + "</And>";
}
@@ -995,7 +991,6 @@
"wfs_conf_id" : global_selectedWfsConfId,
"typename" : global_wfsConfObj[global_selectedWfsConfId].featuretype_name,
"frame" : this.name,
- "url" : u,
"filter" : filter,
"backlink" : ""
};
Modified: trunk/mapbender/http/php/mod_loadwfs.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwfs.php 2009-02-04 10:22:50 UTC (rev 3516)
+++ trunk/mapbender/http/php/mod_loadwfs.php 2009-02-05 09:46:20 UTC (rev 3517)
@@ -32,7 +32,7 @@
$myWfsFactory = new UniversalWfsFactory();
$myWfs = $myWfsFactory->createFromUrl($url);
-if ($myWfs == null) {
+if (is_null($myWfs)) {
echo "WFS could not be uploaded.";
}
$myWfs->insertOrUpdate();
More information about the Mapbender_commits
mailing list