Skip to content
Permalink
Browse files

Add support for <keywords> in WMS/WMTS Capabilities (#183)

  • Loading branch information...
jbo-ads authored and tbonfort committed Mar 6, 2018
1 parent dca7999 commit 330f0eb9ac64752efcf36d84c8c1ebd5cc62390a
Showing with 67 additions and 9 deletions.
  1. +15 −2 lib/configuration_xml.c
  2. +21 −0 lib/service_wms.c
  3. +24 −5 lib/service_wmts.c
  4. +7 −2 mapcache.xml.sample
@@ -42,8 +42,21 @@
void parseMetadata(mapcache_context *ctx, ezxml_t node, apr_table_t *metadata)
{
ezxml_t cur_node;
for(cur_node = node->child; cur_node; cur_node = cur_node->sibling) {
apr_table_add(metadata,cur_node->name, cur_node->txt);
for(cur_node = node->child; cur_node; cur_node = cur_node->ordered) {
if (!cur_node->child) {
// Parse simple text
apr_table_add(metadata, cur_node->name, cur_node->txt);
} else {
// Parse tags:
// `>` suffix in name indicates that value is a table and not a string
char * name = apr_pstrcat(ctx->pool,cur_node->name,">",NULL);
apr_table_t * contents = apr_table_make(ctx->pool,3);
ezxml_t sub_node;
for(sub_node = cur_node->child; sub_node; sub_node = sub_node->ordered) {
apr_table_add(contents, sub_node->name, sub_node->txt);
}
apr_table_addn(metadata, name, (const char *)contents);
}
}
}

@@ -32,6 +32,13 @@
#include <math.h>
#include "mapcache_services.h"

static int metadata_xml_add_child(void * rec, const char * key, const char * value)
{
ezxml_t node = (ezxml_t)rec;
ezxml_set_txt(ezxml_add_child(node,key,0),value);
return 1;
}

static int sort_strings(const void* pa, const void* pb)
{
char** ppszA = (char**)pa;
@@ -253,6 +260,7 @@ void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabi
apr_ssize_t keylen;
const char *title;
const char *abstract;
const char *keywords;
int i;
apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);

@@ -277,6 +285,19 @@ void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabi
ezxml_set_txt(ezxml_add_child(layerxml,"Abstract",0),abstract);
}

// optional layer keywords
// `>` suffix in name indicates that a table is expected instead of a string
// (see `parseMetadata()` in `configuration_xml.c`)
keywords = apr_table_get(tileset->metadata,"keywords>");
if (keywords) {
apr_table_t * contents = (apr_table_t *)keywords;
keywords = apr_table_get(contents,"keyword");
if (keywords) {
ezxml_t nodeKeywords = ezxml_add_child(layerxml,"KeywordList",0);
apr_table_do(metadata_xml_add_child, nodeKeywords, contents, "keyword", NULL);
}
}

if(tileset->wgs84bbox.minx != tileset->wgs84bbox.maxx) {
ezxml_t wgsxml = ezxml_add_child(layerxml,"LatLonBoundingBox",0);
ezxml_set_attr(wgsxml,"minx",apr_psprintf(ctx->pool,"%f",tileset->wgs84bbox.minx));
@@ -62,7 +62,11 @@ static ezxml_t _wmts_capabilities(mapcache_context *ctx, mapcache_cfg *cfg)

int _wmts_service_identification_keywords(void *in, const char *key, const char *value) {
ezxml_t node = (ezxml_t )in;
ezxml_set_txt(ezxml_add_child(node,"ows:Keyword",0),value);
if (!strcasecmp(key,"keyword")) {
ezxml_set_txt(ezxml_add_child(node,"ows:Keyword",0),value);
} else {
ezxml_set_txt(ezxml_add_child(node,key,0),value);
}

return 1;
}
@@ -84,10 +88,6 @@ static ezxml_t _wmts_service_identification(mapcache_context *ctx, mapcache_cfg
value = apr_table_get(cfg->metadata,"keyword");
if(value) {
ezxml_t nodeKeywords = ezxml_new("ows:Keywords");
/*
* @todo: cfg->metadata holds only one item named keyword,
* adjust configuration_xml.c
*/
apr_table_do(_wmts_service_identification_keywords, nodeKeywords, cfg->metadata, "keyword", NULL);
ezxml_insert(nodeKeywords, node, 0);
}
@@ -329,24 +329,43 @@ void _create_capabilities_wmts(mapcache_context *ctx, mapcache_request_get_capab
ezxml_t layer;
const char *title;
const char *abstract;
const char *keywords;
ezxml_t style;
char *dimensionstemplate="";
ezxml_t resourceurl;

apr_hash_this(layer_index,&key,&keylen,(void**)&tileset);

layer = ezxml_add_child(contents,"Layer",0);

/* optional layer title */
title = apr_table_get(tileset->metadata,"title");
if(title) {
ezxml_set_txt(ezxml_add_child(layer,"ows:Title",0),title);
} else {
ezxml_set_txt(ezxml_add_child(layer,"ows:Title",0),tileset->name);

/* optional layer abstract */
}
abstract = apr_table_get(tileset->metadata,"abstract");
if(abstract) {
ezxml_set_txt(ezxml_add_child(layer,"ows:Abstract",0),abstract);
}

// optional layer keywords
// `>` suffix in name indicates that a table is expected instead of a string
// (see `parseMetadata()` in `configuration_xml.c`)
keywords = apr_table_get(tileset->metadata,"keywords>");
if (keywords) {
apr_table_t * contents = (apr_table_t *)keywords;
keywords = apr_table_get(contents,"keyword");
if (keywords) {
ezxml_t nodeKeywords = ezxml_new("ows:Keywords");
apr_table_do(_wmts_service_identification_keywords, nodeKeywords, contents, "keyword", NULL);
ezxml_insert(nodeKeywords, layer, 0);
}
}

if(tileset->wgs84bbox.minx != tileset->wgs84bbox.maxx) {
ezxml_t bbox = ezxml_add_child(layer,"ows:WGS84BoundingBox",0);
ezxml_set_txt(ezxml_add_child(bbox,"ows:LowerCorner",0),
@@ -772,12 +772,17 @@

<!-- metadata
optional metadata tags used for responding to GetCapabilities request.
you can put anything in here, although only the title and abstract tags
are currently used to populate the GetCapabilities document.
you can put anything in here, although only the title, abstract and
keywords tags are currently used to populate the GetCapabilities
document.
-->
<metadata>
<title>vmap0 map</title>
<abstract>blabla</abstract>
<keywords>
<keyword>foo</keyword>
<keyword>bar</keyword>
</keywords>
</metadata>

<!-- watermark

0 comments on commit 330f0eb

Please sign in to comment.
You can’t perform that action at this time.