Skip to content
Permalink
Browse files

WFS: fix #3319 (optional/mandatory attributes by introducing gml_opti…

…onal_items, gml_mandatory_items and gml_default_items) and #3563 (PropertyName should check gml_include_items/gml_exclude_items)
  • Loading branch information...
rouault committed Nov 1, 2013
1 parent 9e04abb commit b511b24b31b4ebe2310d4223242ed2fc7bed23c6
Showing with 270 additions and 107 deletions.
  1. +54 −5 mapgml.c
  2. +2 −0 mapows.h
  3. +213 −101 mapwfs.c
  4. +1 −1 msautotest
@@ -1771,38 +1771,57 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
char **excitems=NULL;
int numexcitems=0;

char **optionalitems=NULL;
int numoptionalitems=0;

char **mandatoryitems=NULL;
int nummandatoryitems=0;

char **defaultitems=NULL;
int numdefaultitems=0;

const char *value=NULL;
char tag[64];

gmlItemListObj *itemList=NULL;
gmlItemObj *item=NULL;

/* get a list of items that should be included in output */
/* get a list of items that might be included in output */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "include_items")) != NULL)
incitems = msStringSplit(value, ',', &numincitems);

/* get a list of items that should be excluded in output */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "exclude_items")) != NULL)
excitems = msStringSplit(value, ',', &numexcitems);

/* get a list of items that need don't get encoded */
/* get a list of items that should not be XML encoded */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "xml_items")) != NULL)
xmlitems = msStringSplit(value, ',', &numxmlitems);

/* get a list of items that should be indicated as optional in DescribeFeatureType */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "optional_items")) != NULL)
optionalitems = msStringSplit(value, ',', &numoptionalitems);

/* get a list of items that should be indicated as mandatory in DescribeFeatureType */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "mandatory_items")) != NULL)
mandatoryitems = msStringSplit(value, ',', &nummandatoryitems);

/* get a list of items that should be presented by default in GetFeature */
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "default_items")) != NULL)
defaultitems = msStringSplit(value, ',', &numdefaultitems);

/* allocate memory and iinitialize the item collection */
itemList = (gmlItemListObj *) malloc(sizeof(gmlItemListObj));
if(itemList == NULL) {
msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()");
return NULL;
}

itemList->items = NULL;
itemList->numitems = 0;

itemList->numitems = layer->numitems;
itemList->items = (gmlItemObj *) malloc(sizeof(gmlItemObj)*itemList->numitems);
if(!itemList->items) {
msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()");
free(itemList);
return NULL;
}

@@ -1817,6 +1836,8 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
item->visible = MS_FALSE;
item->width = 0;
item->precision = 0;
item->outputByDefault = (numdefaultitems == 0);
item->minOccurs = 0;

/* check visibility, included items first... */
if(numincitems == 1 && strcasecmp("all", incitems[0]) == 0) {
@@ -1840,6 +1861,31 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
item->encode = MS_FALSE;
}

/* check optional */
if(numoptionalitems == 1 && strcasecmp("all", optionalitems[0]) == 0) {
item->minOccurs = 0;
} else {
if(nummandatoryitems == 1 && strcasecmp("all", mandatoryitems[0]) == 0) {
item->minOccurs = 1;
}
for(j=0; j<numoptionalitems; j++) {
if(strcasecmp(layer->items[i], optionalitems[j]) == 0)
item->minOccurs = 0;
}
}

/* check mandatory */
for(j=0; j<nummandatoryitems; j++) {
if(strcasecmp(layer->items[i], mandatoryitems[j]) == 0)
item->minOccurs = 1;
}

/* check default */
for(j=0; j<numdefaultitems; j++) {
if(strcasecmp(layer->items[i], defaultitems[j]) == 0)
item->outputByDefault = 1;
}

snprintf(tag, sizeof(tag), "%s_alias", layer->items[i]);
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL)
item->alias = msStrdup(value);
@@ -1864,6 +1910,9 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
msFreeCharArray(incitems, numincitems);
msFreeCharArray(excitems, numexcitems);
msFreeCharArray(xmlitems, numxmlitems);
msFreeCharArray(optionalitems, numoptionalitems);
msFreeCharArray(mandatoryitems, nummandatoryitems);
msFreeCharArray(defaultitems, numdefaultitems);

return itemList;
}
@@ -328,6 +328,8 @@ typedef struct {
int visible; /* should this item be output, default is MS_FALSE */
int width; /* field width, zero if unknown */
int precision; /* field precision (decimal places), zero if unknown or N/A */
int outputByDefault; /* whether this should be output in a GetFeature without PropertyName. MS_TRUE by default, unless gml_default_items is specified and the item name is not in it */
int minOccurs; /* 0 by default. Can be set to 1 by specifying item name in gml_mandatory_items */
} gmlItemObj;

typedef struct {
Oops, something went wrong.

0 comments on commit b511b24

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