@@ -1771,38 +1771,57 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
1771
1771
char * * excitems = NULL ;
1772
1772
int numexcitems = 0 ;
1773
1773
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
+
1774
1783
const char * value = NULL ;
1775
1784
char tag [64 ];
1776
1785
1777
1786
gmlItemListObj * itemList = NULL ;
1778
1787
gmlItemObj * item = NULL ;
1779
1788
1780
- /* get a list of items that should be included in output */
1789
+ /* get a list of items that might be included in output */
1781
1790
if ((value = msOWSLookupMetadata (& (layer -> metadata ), metadata_namespaces , "include_items" )) != NULL )
1782
1791
incitems = msStringSplit (value , ',' , & numincitems );
1783
1792
1784
1793
/* get a list of items that should be excluded in output */
1785
1794
if ((value = msOWSLookupMetadata (& (layer -> metadata ), metadata_namespaces , "exclude_items" )) != NULL )
1786
1795
excitems = msStringSplit (value , ',' , & numexcitems );
1787
1796
1788
- /* get a list of items that need don't get encoded */
1797
+ /* get a list of items that should not be XML encoded */
1789
1798
if ((value = msOWSLookupMetadata (& (layer -> metadata ), metadata_namespaces , "xml_items" )) != NULL )
1790
1799
xmlitems = msStringSplit (value , ',' , & numxmlitems );
1791
1800
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
+
1792
1813
/* allocate memory and iinitialize the item collection */
1793
1814
itemList = (gmlItemListObj * ) malloc (sizeof (gmlItemListObj ));
1794
1815
if (itemList == NULL ) {
1795
1816
msSetError (MS_MEMERR , "Error allocating a collection GML item structures." , "msGMLGetItems()" );
1796
1817
return NULL ;
1797
1818
}
1798
1819
1799
- itemList -> items = NULL ;
1800
- itemList -> numitems = 0 ;
1801
-
1802
1820
itemList -> numitems = layer -> numitems ;
1803
1821
itemList -> items = (gmlItemObj * ) malloc (sizeof (gmlItemObj )* itemList -> numitems );
1804
1822
if (!itemList -> items ) {
1805
1823
msSetError (MS_MEMERR , "Error allocating a collection GML item structures." , "msGMLGetItems()" );
1824
+ free (itemList );
1806
1825
return NULL ;
1807
1826
}
1808
1827
@@ -1817,6 +1836,8 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
1817
1836
item -> visible = MS_FALSE ;
1818
1837
item -> width = 0 ;
1819
1838
item -> precision = 0 ;
1839
+ item -> outputByDefault = (numdefaultitems == 0 );
1840
+ item -> minOccurs = 0 ;
1820
1841
1821
1842
/* check visibility, included items first... */
1822
1843
if (numincitems == 1 && strcasecmp ("all" , incitems [0 ]) == 0 ) {
@@ -1840,6 +1861,31 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
1840
1861
item -> encode = MS_FALSE ;
1841
1862
}
1842
1863
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
+
1843
1889
snprintf (tag , sizeof (tag ), "%s_alias" , layer -> items [i ]);
1844
1890
if ((value = msOWSLookupMetadata (& (layer -> metadata ), metadata_namespaces , tag )) != NULL )
1845
1891
item -> alias = msStrdup (value );
@@ -1864,6 +1910,9 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces)
1864
1910
msFreeCharArray (incitems , numincitems );
1865
1911
msFreeCharArray (excitems , numexcitems );
1866
1912
msFreeCharArray (xmlitems , numxmlitems );
1913
+ msFreeCharArray (optionalitems , numoptionalitems );
1914
+ msFreeCharArray (mandatoryitems , nummandatoryitems );
1915
+ msFreeCharArray (defaultitems , numdefaultitems );
1867
1916
1868
1917
return itemList ;
1869
1918
}
0 commit comments