[Mapbender-commits] r9073 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Sep 12 03:19:29 PDT 2014
Author: armin11
Date: 2014-09-12 03:19:29 -0700 (Fri, 12 Sep 2014)
New Revision: 9073
Modified:
trunk/mapbender/http/classes/class_wmc.php
Log:
Alter updateUrlsInDb for WMC to add DataURL element after Abstract or Title tag as demanded in WMC 1.1.0 spec - via change from SimpleXML to DOM ;-)
Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php 2014-09-11 11:46:56 UTC (rev 9072)
+++ trunk/mapbender/http/classes/class_wmc.php 2014-09-12 10:19:29 UTC (rev 9073)
@@ -604,7 +604,7 @@
while($row = db_fetch_array($res)){
$wmsId = $row["fkey_wms_id"];
$layerId = $row["layer_id"];
- $e = new mb_exception("class_wmc.php - updateUrlsInDb - following layer will be processed: ".$layerId);
+ $e = new mb_notice("class_wmc.php - updateUrlsInDb - following layer will be processed: ".$layerId);
$layerName = $row["layer_name"];
//xpath to pull a special wmc layer object from simple xml object
$queryPath = "/wmc:ViewContext/wmc:LayerList/wmc:Layer[wmc:Extension/mapbender:layer_id='".(integer)$layerId."']";
@@ -649,7 +649,7 @@
}
} else {
//create dataurl and fill it - maybe with dom?
- $e = new mb_exception("class_wmc.php - updateUrlsInDb - create new DataURL Element!");
+ $e = new mb_notice("class_wmc.php - updateUrlsInDb - create new DataURL Element!");
//$layerXML = $layer->asXML();
//$dom_layer = dom_import_string($layerXML);
@@ -679,10 +679,32 @@
</xs:sequence>
*/
- $DataURL = $layer->addChild('DataURL');
- $OnlineResource = $DataURL->addChild('OnlineResource');
- $DataURL->OnlineResource->addAttribute('xlink:type', 'simple','http://www.w3.org/1999/xlink');
- $DataURL->OnlineResource->addAttribute('xlink:href', $downloadOptionsUrl,'http://www.w3.org/1999/xlink');
+ //check if Abstract exists - if it does DataURL came after Abstract, if not DataURL will be after Title Element
+ if (count($layer->Abstract) > 0) {
+ $e = new mb_notice("class_wmc.php - updateUrlsInDb - Abstract found!");
+ //put it after Abstract Element
+ //New element to be inserted
+ $insert = new SimpleXMLElement('<DataURL></DataURL>');
+ //<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="'.$downloadOptionsUrl.'"/>
+ // Get the Abstract element for this layer
+ $target = current($WMCDoc->xpath("/wmc:ViewContext/wmc:LayerList/wmc:Layer[wmc:Extension/mapbender:layer_id='".(integer)$layerId."']/wmc:Abstract"));
+ // Insert the new element after the last nodeA
+ $this->simplexml_insert_after($insert, $target);
+ $layer->DataURL->addChild('OnlineResource');
+ $layer->DataURL->OnlineResource->addAttribute('xlink:type', 'simple','http://www.w3.org/1999/xlink');
+ $layer->DataURL->OnlineResource->addAttribute('xlink:href', $downloadOptionsUrl,'http://www.w3.org/1999/xlink');
+ } else {
+ //put it after Title Element
+ $insert = new SimpleXMLElement("<DataURL></DataURL>");
+ //<OnlineResource xlink:type='simple' xlink:href='".$downloadOptionsUrl."'/>
+ // Get the Abstract element for this layer
+ $target = current($WMCDoc->xpath("/wmc:ViewContext/wmc:LayerList/wmc:Layer[wmc:Extension/mapbender:layer_id='".(integer)$layerId."']/wmc:Title"));
+ // Insert the new element after the last nodeA
+ $this->simplexml_insert_after($insert, $target);
+ $layer->DataURL->addChild('OnlineResource');
+ $layer->DataURL->OnlineResource->addAttribute('xlink:type', 'simple','http://www.w3.org/1999/xlink');
+ $layer->DataURL->OnlineResource->addAttribute('xlink:href', $downloadOptionsUrl,'http://www.w3.org/1999/xlink');
+ }
$e = new mb_notice("class_wmc.php - updateUrlsInDb new DataURL XML : ".$layer->asXML());
}
}
@@ -1236,6 +1258,17 @@
}
}
+ //http://stackoverflow.com/questions/3361036/php-simplexml-insert-node-at-certain-position
+ private function simplexml_insert_after(SimpleXMLElement $insert, SimpleXMLElement $target) {
+ $target_dom = dom_import_simplexml($target);
+ $insert_dom = $target_dom->ownerDocument->importNode(dom_import_simplexml($insert), true);
+ if ($target_dom->nextSibling) {
+ return $target_dom->parentNode->insertBefore($insert_dom, $target_dom->nextSibling);
+ } else {
+ return $target_dom->parentNode->appendChild($insert_dom);
+ }
+ }
+
public function extentToJavaScript() {
return $this->mainMap->extentToJavaScript();
}
More information about the Mapbender_commits
mailing list