Skip to content

Commit b511b24

Browse files
committed
WFS: fix #3319 (optional/mandatory attributes by introducing gml_optional_items, gml_mandatory_items and gml_default_items) and #3563 (PropertyName should check gml_include_items/gml_exclude_items)
1 parent 9e04abb commit b511b24

File tree

4 files changed

+270
-107
lines changed

4 files changed

+270
-107
lines changed

mapgml.c

+54-5
Original file line numberDiff line numberDiff line change
@@ -1771,38 +1771,57 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
17711771
char **excitems=NULL;
17721772
int numexcitems=0;
17731773

1774+
char **optionalitems=NULL;
1775+
int numoptionalitems=0;
1776+
1777+
char **mandatoryitems=NULL;
1778+
int nummandatoryitems=0;
1779+
1780+
char **defaultitems=NULL;
1781+
int numdefaultitems=0;
1782+
17741783
const char *value=NULL;
17751784
char tag[64];
17761785

17771786
gmlItemListObj *itemList=NULL;
17781787
gmlItemObj *item=NULL;
17791788

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

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

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

1801+
/* get a list of items that should be indicated as optional in DescribeFeatureType */
1802+
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "optional_items")) != NULL)
1803+
optionalitems = msStringSplit(value, ',', &numoptionalitems);
1804+
1805+
/* get a list of items that should be indicated as mandatory in DescribeFeatureType */
1806+
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "mandatory_items")) != NULL)
1807+
mandatoryitems = msStringSplit(value, ',', &nummandatoryitems);
1808+
1809+
/* get a list of items that should be presented by default in GetFeature */
1810+
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "default_items")) != NULL)
1811+
defaultitems = msStringSplit(value, ',', &numdefaultitems);
1812+
17921813
/* allocate memory and iinitialize the item collection */
17931814
itemList = (gmlItemListObj *) malloc(sizeof(gmlItemListObj));
17941815
if(itemList == NULL) {
17951816
msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()");
17961817
return NULL;
17971818
}
17981819

1799-
itemList->items = NULL;
1800-
itemList->numitems = 0;
1801-
18021820
itemList->numitems = layer->numitems;
18031821
itemList->items = (gmlItemObj *) malloc(sizeof(gmlItemObj)*itemList->numitems);
18041822
if(!itemList->items) {
18051823
msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()");
1824+
free(itemList);
18061825
return NULL;
18071826
}
18081827

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

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

1864+
/* check optional */
1865+
if(numoptionalitems == 1 && strcasecmp("all", optionalitems[0]) == 0) {
1866+
item->minOccurs = 0;
1867+
} else {
1868+
if(nummandatoryitems == 1 && strcasecmp("all", mandatoryitems[0]) == 0) {
1869+
item->minOccurs = 1;
1870+
}
1871+
for(j=0; j<numoptionalitems; j++) {
1872+
if(strcasecmp(layer->items[i], optionalitems[j]) == 0)
1873+
item->minOccurs = 0;
1874+
}
1875+
}
1876+
1877+
/* check mandatory */
1878+
for(j=0; j<nummandatoryitems; j++) {
1879+
if(strcasecmp(layer->items[i], mandatoryitems[j]) == 0)
1880+
item->minOccurs = 1;
1881+
}
1882+
1883+
/* check default */
1884+
for(j=0; j<numdefaultitems; j++) {
1885+
if(strcasecmp(layer->items[i], defaultitems[j]) == 0)
1886+
item->outputByDefault = 1;
1887+
}
1888+
18431889
snprintf(tag, sizeof(tag), "%s_alias", layer->items[i]);
18441890
if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL)
18451891
item->alias = msStrdup(value);
@@ -1864,6 +1910,9 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
18641910
msFreeCharArray(incitems, numincitems);
18651911
msFreeCharArray(excitems, numexcitems);
18661912
msFreeCharArray(xmlitems, numxmlitems);
1913+
msFreeCharArray(optionalitems, numoptionalitems);
1914+
msFreeCharArray(mandatoryitems, nummandatoryitems);
1915+
msFreeCharArray(defaultitems, numdefaultitems);
18671916

18681917
return itemList;
18691918
}

mapows.h

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ typedef struct {
328328
int visible; /* should this item be output, default is MS_FALSE */
329329
int width; /* field width, zero if unknown */
330330
int precision; /* field precision (decimal places), zero if unknown or N/A */
331+
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 */
332+
int minOccurs; /* 0 by default. Can be set to 1 by specifying item name in gml_mandatory_items */
331333
} gmlItemObj;
332334

333335
typedef struct {

0 commit comments

Comments
 (0)