[Mapbender-commits] r6702 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Aug 5 11:45:58 EDT 2010
Author: christoph
Date: 2010-08-05 15:45:58 +0000 (Thu, 05 Aug 2010)
New Revision: 6702
Added:
trunk/mapbender/http/classes/class_universal_wms_factory.php
trunk/mapbender/http/classes/class_wms_1_1_1_factory.php
trunk/mapbender/http/classes/class_wms_factory.php
Log:
new WMS classes, similar to WFS. Will become more interesting once WMS 1.3 is being added
Added: trunk/mapbender/http/classes/class_universal_wms_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_wms_factory.php (rev 0)
+++ trunk/mapbender/http/classes/class_universal_wms_factory.php 2010-08-05 15:45:58 UTC (rev 6702)
@@ -0,0 +1,147 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_administration.php";
+require_once dirname(__FILE__) . "/class_ows_factory.php";
+require_once dirname(__FILE__) . "/class_wms_factory.php";
+require_once dirname(__FILE__) . "/class_wms_1_1_1_factory.php";
+
+/**
+ *
+ * @return
+ * @param $xml String
+ */
+class UniversalWmsFactory extends WmsFactory {
+
+ /**
+ * Parses the capabilities document for the WMS
+ * version number and returns it.
+ *
+ * @return String
+ * @param $xml String
+ */
+ private function getVersionFromXml ($xml) {
+ // of course to be refactored. Up to now, the same factory
+ // handles just 1.1.1 and below
+ return "1.1.1 or older";
+/*
+ $admin = new administration();
+ $values = $admin->parseXml($xml);
+
+ foreach ($values as $element) {
+ if($this->sepNameSpace(strtoupper($element[tag])) == "WFS_CAPABILITIES" && $element[type] == "open"){
+ return $element[attributes][version];
+ }
+ }
+ throw new Exception("WFS version could not be determined from XML.");
+*/
+ }
+
+ /**
+ * Creates a WMS object by parsing its capabilities document.
+ *
+ * The WMS version is determined by parsing
+ * the capabilities document up-front.
+ *
+ * @return Wms
+ * @param $xml String
+ */
+ public function createFromXml ($xml) {
+ try {
+ $version = $this->getVersionFromXml($xml);
+
+ switch ($version) {
+ case "1.1.1 or older":
+ $factory = new Wms_1_1_1_Factory();
+ break;
+ default:
+ throw new Exception("Unknown WMS version " . $version);
+ break;
+ }
+ return $factory->createFromXml($xml);
+ }
+ catch (Exception $e) {
+ new mb_exception($e);
+ return null;
+ }
+ }
+
+ private function getVersionByWmsId ($id) {
+ $sql = "SELECT wms_version FROM wms WHERE wms_id = $1";
+ $v = array($id);
+ $t = array("i");
+ $res = db_prep_query($sql, $v, $t);
+ $row = db_fetch_array($res);
+ if ($row) {
+ return $row["wms_version"];
+ }
+ return null;
+ }
+
+ private function getFactory ($version) {
+ switch ($version) {
+ case "1.0.0":
+ return new Wms_1_1_1_Factory();
+ break;
+ case "1.1.0":
+ return Wms_1_1_1_Factory();
+ break;
+ case "1.1.1":
+ return new Wms_1_1_1_Factory();
+ break;
+ default:
+ throw new Exception("Unknown WMS version " . $version);
+ break;
+ }
+ return null;
+ }
+
+ public function createFromDb ($id, $appId = null) {
+ try {
+ $version = $this->getVersionByWmsId();
+ if (!is_null($version)) {
+
+ $factory = $this->getFactory($version);
+ if (!is_null($factory)) {
+ if (!is_null($appId)) {
+ return $factory->createFromDb($id, $appId);
+ }
+ return $factory->createFromDb($id);
+ }
+ return null;
+ }
+ }
+ catch (Exception $e) {
+ new mb_exception($e);
+ return null;
+ }
+ }
+
+ public function createLayerFromDb ($id, $appId = null) {
+ try {
+ $wmsId = intval(wms::getWmsIdByLayerId($id));
+ $version = $this->getVersionByWmsId($wmsId);
+ if (!is_null($version)) {
+
+ $factory = $this->getFactory($version);
+ if (!is_null($factory)) {
+ if (!is_null($appId)) {
+ return $factory->createLayerFromDb($id, $wmsId, $appId);
+ }
+ return $factory->createLayerFromDb($id, $wmsId);
+ }
+ return null;
+ }
+ }
+ catch (Exception $e) {
+ new mb_exception($e);
+ return null;
+ }
+ }
+}
+?>
\ No newline at end of file
Added: trunk/mapbender/http/classes/class_wms_1_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wms_1_1_1_factory.php (rev 0)
+++ trunk/mapbender/http/classes/class_wms_1_1_1_factory.php 2010-08-05 15:45:58 UTC (rev 6702)
@@ -0,0 +1,91 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/../classes/class_wms_factory.php";
+require_once dirname(__FILE__) . "/../classes/class_wms.php";
+require_once dirname(__FILE__) . "/../classes/class_connector.php";
+require_once dirname(__FILE__) . "/../classes/class_administration.php";
+
+/**
+ * Creates WMS < 1.2 objects from a capabilities documents.
+ *
+ * @return Wms
+ */
+class Wms_1_1_1_Factory extends WmsFactory {
+
+ /**
+ * Creates WMS < 1.2 objects from a capabilities documents.
+ *
+ * @return Wms
+ * @param $xml String
+ */
+ public function createFromXml ($xml) {
+ }
+
+ public function createFromDb ($id) {
+ $appId = func_num_args() >= 2 ?
+ func_get_arg(1) : null;
+
+ $myWms = new wms();
+ if (!is_null($appId)) {
+ return parent::createFromDb($id, $myWms, $appId);
+ }
+ return parent::createFromDb($id, $myWms);
+ }
+
+ public function createLayerFromDb ($id) {
+ $wmsId = func_num_args() >= 2 ?
+ func_get_arg(1) : null;
+
+ $appId = func_num_args() >= 3 ?
+ func_get_arg(2) : null;
+
+ //
+ // get WMS of this layer
+ //
+ if (!is_null($appId)) {
+ $myWms = $this->createFromDb($wmsId, $appId);
+ }
+ else {
+ $myWms = $this->createFromDb($wmsId);
+ }
+
+ if (is_null($myWms)) {
+ return null;
+ }
+
+ //
+ // delete all layers apart from the one mentioned (but keep parents)
+ //
+ // 1. find all layers to keep
+ $keep = array();
+ $currentLayer = $myWms->getLayerById($id);
+
+ do {
+ $keep[]= $currentLayer->layer_pos;
+ $pos = $currentLayer->layer_parent;
+ $currentLayer = $myWms->getLayerByPos($pos);
+ } while (!is_null($currentLayer));
+
+ //
+ // 2. delete layers not for keeping
+ //
+ $i = 0;
+ while ($i < count($myWms->objLayer)) {
+ $l = $myWms->objLayer[$i];
+ if (in_array($l->layer_pos, $keep)) {
+ $i++;
+ continue;
+ }
+ // delete layer
+ array_splice($myWms->objLayer, $i, 1);
+ }
+ return $myWms;
+ }
+}
+?>
\ No newline at end of file
Added: trunk/mapbender/http/classes/class_wms_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wms_factory.php (rev 0)
+++ trunk/mapbender/http/classes/class_wms_factory.php 2010-08-05 15:45:58 UTC (rev 6702)
@@ -0,0 +1,37 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_administration.php";
+require_once dirname(__FILE__) . "/class_ows_factory.php";
+
+abstract class WmsFactory extends OwsFactory {
+ /**
+ * Retrieves the data of a WMS from the database and initiates the object.
+ *
+ * @return
+ * @param $id Integer
+ * @param $aWms Wms is being created by the subclass
+ * @param $appId id of the application where this WMS is configured
+ */
+ public function createFromDb ($id) {
+ $myWms = func_num_args() >= 2 ?
+ func_get_arg(1) : null;
+
+ $appId = func_num_args() >= 3 ?
+ func_get_arg(2) : null;
+
+ if (!is_null($appId)) {
+ $myWms->createObjFromDB($id, $appId);
+ }
+ else {
+ $myWms->createObjFromDBNoGui($id);
+ }
+ return $myWms;
+ }
+}
+?>
More information about the Mapbender_commits
mailing list