forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapcontext.c
1970 lines (1735 loc) · 67.9 KB
/
mapcontext.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
* $Id$
*
* Project: MapServer
* Purpose: OGC Web Map Context implementation
* Author: Julien-Samuel Lacroix, DM Solutions Group (lacroix@dmsolutions.ca)
*
**********************************************************************
* Copyright (c) 2002-2003, Julien-Samuel Lacroix, DM Solutions Group Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
****************************************************************************/
#include "mapserver.h"
#if defined(USE_WMS_LYR) && defined(USE_OGR)
/* There is a dependency to GDAL/OGR for the GML driver and MiniXML parser */
#include "cpl_minixml.h"
#endif
/* msGetMapContextFileText()
**
** Read a file and return is content
**
** Take the filename in argument
** Return value must be freed by caller
*/
char * msGetMapContextFileText(char *filename)
{
char *pszBuffer;
FILE *stream;
int nLength;
/* open file */
if(filename != NULL && strlen(filename) > 0) {
stream = fopen(filename, "rb");
if(!stream) {
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
return NULL;
}
} else {
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
return NULL;
}
fseek( stream, 0, SEEK_END );
nLength = ftell( stream );
fseek( stream, 0, SEEK_SET );
pszBuffer = (char *) malloc(nLength+1);
if( pszBuffer == NULL ) {
msSetError(MS_MEMERR, "(%s)", "msGetMapContextFileText()", filename);
fclose( stream );
return NULL;
}
if(fread( pszBuffer, nLength, 1, stream ) == 0 && !feof(stream)) {
free( pszBuffer );
fclose( stream );
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
return NULL;
}
pszBuffer[nLength] = '\0';
fclose( stream );
return pszBuffer;
}
#if defined(USE_WMS_LYR) && defined(USE_OGR)
/*
**msGetMapContextXMLHashValue()
**
**Get the xml value and put it in the hash table
**
*/
int msGetMapContextXMLHashValue( CPLXMLNode *psRoot, const char *pszXMLPath,
hashTableObj *metadata, char *pszMetadata )
{
char *pszValue;
pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL);
if(pszValue != NULL) {
if( metadata != NULL ) {
msInsertHashTable(metadata, pszMetadata, pszValue );
} else {
return MS_FAILURE;
}
} else {
return MS_FAILURE;
}
return MS_SUCCESS;
}
/*
**msGetMapContextXMLHashValue()
**
**Get the xml value and put it in the hash table
**
*/
int msGetMapContextXMLHashValueDecode( CPLXMLNode *psRoot,
const char *pszXMLPath,
hashTableObj *metadata,
char *pszMetadata )
{
char *pszValue;
pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL);
if(pszValue != NULL) {
if( metadata != NULL ) {
msDecodeHTMLEntities(pszValue);
msInsertHashTable(metadata, pszMetadata, pszValue );
} else {
return MS_FAILURE;
}
} else {
return MS_FAILURE;
}
return MS_SUCCESS;
}
/*
**msGetMapContextXMLStringValue()
**
**Get the xml value and put it in the string field
**
*/
int msGetMapContextXMLStringValue( CPLXMLNode *psRoot, char *pszXMLPath,
char **pszField)
{
char *pszValue;
pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL);
if(pszValue != NULL) {
if( pszField != NULL ) {
*pszField = msStrdup(pszValue);
} else {
return MS_FAILURE;
}
} else {
return MS_FAILURE;
}
return MS_SUCCESS;
}
/*
**msGetMapContextXMLStringValue()
**
**Get the xml value and put it in the string field
**
*/
int msGetMapContextXMLStringValueDecode( CPLXMLNode *psRoot, char *pszXMLPath,
char **pszField)
{
char *pszValue;
pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL);
if(pszValue != NULL) {
if( pszField != NULL ) {
msDecodeHTMLEntities(pszValue);
*pszField = msStrdup(pszValue);
} else {
return MS_FAILURE;
}
} else {
return MS_FAILURE;
}
return MS_SUCCESS;
}
/*
**msGetMapContextXMLFloatValue()
**
**Get the xml value and put it in the string field
**
*/
int msGetMapContextXMLFloatValue( CPLXMLNode *psRoot, char *pszXMLPath,
double *pszField)
{
char *pszValue;
pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL);
if(pszValue != NULL) {
if( pszField != NULL ) {
*pszField = atof(pszValue);
} else {
return MS_FAILURE;
}
} else {
return MS_FAILURE;
}
return MS_SUCCESS;
}
/*
** msLoadMapContextURLELements
**
** Take a Node and get the width, height, format and href from it.
** Then put this info in metadatas.
*/
int msLoadMapContextURLELements( CPLXMLNode *psRoot, hashTableObj *metadata,
const char *pszMetadataRoot)
{
char *pszMetadataName;
if( psRoot == NULL || metadata == NULL || pszMetadataRoot == NULL )
return MS_FAILURE;
pszMetadataName = (char*) malloc( strlen(pszMetadataRoot) + 10 );
sprintf( pszMetadataName, "%s_width", pszMetadataRoot );
msGetMapContextXMLHashValue( psRoot, "width", metadata, pszMetadataName );
sprintf( pszMetadataName, "%s_height", pszMetadataRoot );
msGetMapContextXMLHashValue( psRoot, "height", metadata, pszMetadataName );
sprintf( pszMetadataName, "%s_format", pszMetadataRoot );
msGetMapContextXMLHashValue( psRoot, "format", metadata, pszMetadataName );
sprintf( pszMetadataName, "%s_href", pszMetadataRoot );
msGetMapContextXMLHashValue( psRoot, "OnlineResource.xlink:href", metadata,
pszMetadataName );
free(pszMetadataName);
return MS_SUCCESS;
}
/* msLoadMapContextKeyword
**
** Put the keywords from a XML node and put them in a metadata.
** psRoot should be set to keywordlist
*/
int msLoadMapContextListInMetadata( CPLXMLNode *psRoot, hashTableObj *metadata,
char *pszXMLName, char *pszMetadataName,
char *pszHashDelimiter)
{
char *pszHash, *pszXMLValue, *pszMetadata;
if(psRoot == NULL || psRoot->psChild == NULL ||
metadata == NULL || pszMetadataName == NULL || pszXMLName == NULL)
return MS_FAILURE;
/* Pass from KeywordList to Keyword level */
psRoot = psRoot->psChild;
/* Loop on all elements and append keywords to the hash table */
while (psRoot) {
if (psRoot->psChild && strcasecmp(psRoot->pszValue, pszXMLName) == 0) {
pszXMLValue = psRoot->psChild->pszValue;
pszHash = msLookupHashTable(metadata, pszMetadataName);
if (pszHash != NULL) {
pszMetadata = (char*)malloc(strlen(pszHash)+
strlen(pszXMLValue)+2);
if(pszHashDelimiter == NULL)
sprintf( pszMetadata, "%s%s", pszHash, pszXMLValue );
else
sprintf( pszMetadata, "%s%s%s", pszHash, pszHashDelimiter,
pszXMLValue );
msInsertHashTable(metadata, pszMetadataName, pszMetadata);
free(pszMetadata);
} else
msInsertHashTable(metadata, pszMetadataName, pszXMLValue);
}
psRoot = psRoot->psNext;
}
return MS_SUCCESS;
}
/* msLoadMapContextContactInfo
**
** Put the Contact informations from a XML node and put them in a metadata.
**
*/
int msLoadMapContextContactInfo( CPLXMLNode *psRoot, hashTableObj *metadata )
{
if(psRoot == NULL || metadata == NULL)
return MS_FAILURE;
/* Contact Person primary */
msGetMapContextXMLHashValue(psRoot,
"ContactPersonPrimary.ContactPerson",
metadata, "wms_contactperson");
msGetMapContextXMLHashValue(psRoot,
"ContactPersonPrimary.ContactOrganization",
metadata, "wms_contactorganization");
/* Contact Position */
msGetMapContextXMLHashValue(psRoot,
"ContactPosition",
metadata, "wms_contactposition");
/* Contact Address */
msGetMapContextXMLHashValue(psRoot, "ContactAddress.AddressType",
metadata, "wms_addresstype");
msGetMapContextXMLHashValue(psRoot, "ContactAddress.Address",
metadata, "wms_address");
msGetMapContextXMLHashValue(psRoot, "ContactAddress.City",
metadata, "wms_city");
msGetMapContextXMLHashValue(psRoot, "ContactAddress.StateOrProvince",
metadata, "wms_stateorprovince");
msGetMapContextXMLHashValue(psRoot, "ContactAddress.PostCode",
metadata, "wms_postcode");
msGetMapContextXMLHashValue(psRoot, "ContactAddress.Country",
metadata, "wms_country");
/* Others */
msGetMapContextXMLHashValue(psRoot, "ContactVoiceTelephone",
metadata, "wms_contactvoicetelephone");
msGetMapContextXMLHashValue(psRoot, "ContactFacsimileTelephone",
metadata, "wms_contactfacsimiletelephone");
msGetMapContextXMLHashValue(psRoot, "ContactElectronicMailAddress",
metadata, "wms_contactelectronicmailaddress");
return MS_SUCCESS;
}
/*
** msLoadMapContextLayerFormat
**
**
*/
int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer)
{
char *pszValue, *pszValue1, *pszHash;
if(psFormat->psChild != NULL &&
strcasecmp(psFormat->pszValue, "Format") == 0 ) {
if(psFormat->psChild->psNext == NULL)
pszValue = psFormat->psChild->pszValue;
else
pszValue = psFormat->psChild->psNext->pszValue;
} else
pszValue = NULL;
if(pszValue != NULL && strcasecmp(pszValue, "") != 0) {
/* wms_format */
pszValue1 = (char*)CPLGetXMLValue(psFormat,
"current", NULL);
if(pszValue1 != NULL &&
(strcasecmp(pszValue1, "1") == 0 || strcasecmp(pszValue1, "true")==0))
msInsertHashTable(&(layer->metadata),
"wms_format", pszValue);
/* wms_formatlist */
pszHash = msLookupHashTable(&(layer->metadata),
"wms_formatlist");
if(pszHash != NULL) {
pszValue1 = (char*)malloc(strlen(pszHash)+
strlen(pszValue)+2);
sprintf(pszValue1, "%s,%s", pszHash, pszValue);
msInsertHashTable(&(layer->metadata),
"wms_formatlist", pszValue1);
free(pszValue1);
} else
msInsertHashTable(&(layer->metadata),
"wms_formatlist", pszValue);
}
/* Make sure selected format is supported or select another
* supported format. Note that we can efficiently do this
* only for GIF/PNG/JPEG, can't try to handle all GDAL
* formats.
*/
pszValue = msLookupHashTable(&(layer->metadata), "wms_format");
if (
#if !(defined USE_PNG)
strcasecmp(pszValue, "image/png") == 0 ||
strcasecmp(pszValue, "PNG") == 0 ||
#endif
#if !(defined USE_JPEG)
strcasecmp(pszValue, "image/jpeg") == 0 ||
strcasecmp(pszValue, "JPEG") == 0 ||
#endif
0 ) {
char **papszList=NULL;
int i, numformats=0;
pszValue = msLookupHashTable(&(layer->metadata),
"wms_formatlist");
papszList = msStringSplit(pszValue, ',', &numformats);
for(i=0; i < numformats; i++) {
if (
#if (defined USE_PNG)
strcasecmp(papszList[i], "image/png") == 0 ||
strcasecmp(papszList[i], "PNG") == 0 ||
#endif
#if (defined USE_JPEG)
strcasecmp(papszList[i], "image/jpeg") == 0 ||
strcasecmp(papszList[i], "JPEG") == 0 ||
#endif
#ifdef USE_GD_GIF
strcasecmp(papszList[i], "image/gif") == 0 ||
strcasecmp(papszList[i], "GIF") == 0 ||
#endif
0 ) {
/* Found a match */
msInsertHashTable(&(layer->metadata),
"wms_format", papszList[i]);
break;
}
}
if(papszList)
msFreeCharArray(papszList, numformats);
} /* end if unsupported format */
return MS_SUCCESS;
}
int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer,
int nStyle)
{
char *pszValue, *pszValue1, *pszValue2;
char *pszHash, *pszStyle=NULL, *pszStyleName;
CPLXMLNode *psStyleSLDBody;
pszStyleName =(char*)CPLGetXMLValue(psStyle,"Name",NULL);
if(pszStyleName == NULL) {
pszStyleName = (char*)malloc(20);
sprintf(pszStyleName, "Style{%d}", nStyle);
} else
pszStyleName = msStrdup(pszStyleName);
/* wms_style */
pszValue = (char*)CPLGetXMLValue(psStyle,"current",NULL);
if(pszValue != NULL &&
(strcasecmp(pszValue, "1") == 0 ||
strcasecmp(pszValue, "true") == 0))
msInsertHashTable(&(layer->metadata),
"wms_style", pszStyleName);
/* wms_stylelist */
pszHash = msLookupHashTable(&(layer->metadata),
"wms_stylelist");
if(pszHash != NULL) {
pszValue1 = (char*)malloc(strlen(pszHash)+
strlen(pszStyleName)+2);
sprintf(pszValue1, "%s,%s", pszHash, pszStyleName);
msInsertHashTable(&(layer->metadata),
"wms_stylelist", pszValue1);
free(pszValue1);
} else
msInsertHashTable(&(layer->metadata),
"wms_stylelist", pszStyleName);
/* Title */
pszStyle = (char*)malloc(strlen(pszStyleName)+20);
sprintf(pszStyle,"wms_style_%s_title",pszStyleName);
if( msGetMapContextXMLHashValue(psStyle, "Title", &(layer->metadata),
pszStyle) == MS_FAILURE )
msInsertHashTable(&(layer->metadata), pszStyle, layer->name);
free(pszStyle);
/* SLD */
pszStyle = (char*)malloc(strlen(pszStyleName)+15);
sprintf(pszStyle, "wms_style_%s_sld", pszStyleName);
msGetMapContextXMLHashValueDecode( psStyle, "SLD.OnlineResource.xlink:href",
&(layer->metadata), pszStyle );
free(pszStyle);
/* SLDBODY */
pszStyle = (char*)malloc(strlen(pszStyleName)+20);
sprintf(pszStyle, "wms_style_%s_sld_body", pszStyleName);
psStyleSLDBody = CPLGetXMLNode(psStyle, "SLD.StyledLayerDescriptor");
/*some clients such as OpenLayers add a name space, which I believe is wrong but
added this additional test for compatibility #3115*/
if (psStyleSLDBody == NULL)
psStyleSLDBody = CPLGetXMLNode(psStyle, "SLD.sld:StyledLayerDescriptor");
if(psStyleSLDBody != NULL && &(layer->metadata) != NULL) {
pszValue = CPLSerializeXMLTree(psStyleSLDBody);
if(pszValue != NULL) {
/* Before including SLDBody in the mapfile, we must replace the */
/* double quote for single quote. This is to prevent having this: */
/* "metadata" "<string attriute="ttt">" */
char *c;
for(c=pszValue; *c != '\0'; c++)
if(*c == '"')
*c = '\'';
msInsertHashTable(&(layer->metadata), pszStyle, pszValue );
msFree(pszValue);
}
}
free(pszStyle);
/* LegendURL */
pszStyle = (char*) malloc(strlen(pszStyleName) + 25);
sprintf( pszStyle, "wms_style_%s_legendurl",
pszStyleName);
msLoadMapContextURLELements( CPLGetXMLNode(psStyle, "LegendURL"),
&(layer->metadata), pszStyle );
free(pszStyle);
free(pszStyleName);
/* */
/* Add the stylelist to the layer connection */
/* */
if(msLookupHashTable(&(layer->metadata),
"wms_stylelist") == NULL) {
if(layer->connection)
pszValue = msStrdup(layer->connection);
else
pszValue = msStrdup( "" );
pszValue1 = strstr(pszValue, "STYLELIST=");
if(pszValue1 != NULL) {
pszValue1 += 10;
pszValue2 = strchr(pszValue, '&');
if(pszValue2 != NULL)
pszValue1[pszValue2-pszValue1] = '\0';
msInsertHashTable(&(layer->metadata), "wms_stylelist",
pszValue1);
}
free(pszValue);
}
/* */
/* Add the style to the layer connection */
/* */
if(msLookupHashTable(&(layer->metadata), "wms_style") == NULL) {
if(layer->connection)
pszValue = msStrdup(layer->connection);
else
pszValue = msStrdup( "" );
pszValue1 = strstr(pszValue, "STYLE=");
if(pszValue1 != NULL) {
pszValue1 += 6;
pszValue2 = strchr(pszValue, '&');
if(pszValue2 != NULL)
pszValue1[pszValue2-pszValue1] = '\0';
msInsertHashTable(&(layer->metadata), "wms_style",
pszValue1);
}
free(pszValue);
}
return MS_SUCCESS;
}
int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer)
{
char *pszValue, *pszHash;
char *pszDimension=NULL, *pszDimensionName=NULL;
pszDimensionName =(char*)CPLGetXMLValue(psDimension,"name",NULL);
if(pszDimensionName == NULL) {
return MS_FALSE;
} else
pszDimensionName = msStrdup(pszDimensionName);
pszDimension = (char*)malloc(strlen(pszDimensionName)+50);
/* wms_dimension: This is the current dimension */
pszValue = (char*)CPLGetXMLValue(psDimension, "current", NULL);
if(pszValue != NULL && (strcasecmp(pszValue, "1") == 0 ||
strcasecmp(pszValue, "true") == 0))
msInsertHashTable(&(layer->metadata),
"wms_dimension", pszDimensionName);
/* wms_dimensionlist */
pszHash = msLookupHashTable(&(layer->metadata),
"wms_dimensionlist");
if(pszHash != NULL) {
pszValue = (char*)malloc(strlen(pszHash)+
strlen(pszDimensionName)+2);
sprintf(pszValue, "%s,%s", pszHash, pszDimensionName);
msInsertHashTable(&(layer->metadata),
"wms_dimensionlist", pszValue);
free(pszValue);
} else
msInsertHashTable(&(layer->metadata),
"wms_dimensionlist", pszDimensionName);
/* Units */
sprintf(pszDimension, "wms_dimension_%s_units", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "units", &(layer->metadata),
pszDimension);
/* UnitSymbol */
sprintf(pszDimension, "wms_dimension_%s_unitsymbol", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "unitSymbol", &(layer->metadata),
pszDimension);
/* userValue */
sprintf(pszDimension, "wms_dimension_%s_uservalue", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "userValue", &(layer->metadata),
pszDimension);
if(strcasecmp(pszDimensionName, "time") == 0)
msGetMapContextXMLHashValue(psDimension, "userValue", &(layer->metadata),
"wms_time");
/* default */
sprintf(pszDimension, "wms_dimension_%s_default", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "default", &(layer->metadata),
pszDimension);
/* multipleValues */
sprintf(pszDimension, "wms_dimension_%s_multiplevalues", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "multipleValues",&(layer->metadata),
pszDimension);
/* nearestValue */
sprintf(pszDimension, "wms_dimension_%s_nearestvalue", pszDimensionName);
msGetMapContextXMLHashValue(psDimension, "nearestValue", &(layer->metadata),
pszDimension);
free(pszDimension);
free(pszDimensionName);
return MS_SUCCESS;
}
/*
** msLoadMapContextGeneral
**
** Load the General block of the mapcontext document
*/
int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral,
CPLXMLNode *psMapContext, int nVersion,
char *filename)
{
char *pszProj=NULL;
char *pszValue, *pszValue1, *pszValue2;
/* Projection */
pszValue = (char*)CPLGetXMLValue(psGeneral,
"BoundingBox.SRS", NULL);
if(pszValue != NULL) {
if(strncasecmp(pszValue, "AUTO:", 5) == 0) {
pszProj = msStrdup(pszValue);
} else {
pszProj = (char*) malloc(sizeof(char)*(strlen(pszValue)+10));
sprintf(pszProj, "init=epsg:%s", pszValue+5);
}
msInitProjection(&map->projection);
map->projection.args[map->projection.numargs] = msStrdup(pszProj);
map->projection.numargs++;
msProcessProjection(&map->projection);
if( (map->units = GetMapserverUnitUsingProj(&(map->projection))) == -1) {
free(pszProj);
msSetError( MS_MAPCONTEXTERR,
"Unable to set units for projection '%s'",
"msLoadMapContext()", pszProj );
return MS_FAILURE;
}
free(pszProj);
} else {
msDebug("Mandatory data General.BoundingBox.SRS missing in %s.",
filename);
}
/* Extent */
if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.minx",
&(map->extent.minx)) == MS_FAILURE) {
msDebug("Mandatory data General.BoundingBox.minx missing in %s.",
filename);
}
if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.miny",
&(map->extent.miny)) == MS_FAILURE) {
msDebug("Mandatory data General.BoundingBox.miny missing in %s.",
filename);
}
if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxx",
&(map->extent.maxx)) == MS_FAILURE) {
msDebug("Mandatory data General.BoundingBox.maxx missing in %s.",
filename);
}
if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxy",
&(map->extent.maxy)) == MS_FAILURE) {
msDebug("Mandatory data General.BoundingBox.maxy missing in %s.",
filename);
}
/* Title */
if( msGetMapContextXMLHashValue(psGeneral, "Title",
&(map->web.metadata), "wms_title") == MS_FAILURE) {
if ( nVersion >= OWS_1_0_0 )
msDebug("Mandatory data General.Title missing in %s.", filename);
else {
if( msGetMapContextXMLHashValue(psGeneral, "gml:name",
&(map->web.metadata), "wms_title") == MS_FAILURE ) {
if( nVersion < OWS_0_1_7 )
msDebug("Mandatory data General.Title missing in %s.", filename);
else
msDebug("Mandatory data General.gml:name missing in %s.",
filename);
}
}
}
/* Name */
if( nVersion >= OWS_1_0_0 ) {
pszValue = (char*)CPLGetXMLValue(psMapContext,
"id", NULL);
if (pszValue)
map->name = msStrdup(pszValue);
} else {
if(msGetMapContextXMLStringValue(psGeneral, "Name",
&(map->name)) == MS_FAILURE) {
msGetMapContextXMLStringValue(psGeneral, "gml:name",
&(map->name));
}
}
/* Keyword */
if( nVersion >= OWS_1_0_0 ) {
msLoadMapContextListInMetadata(
CPLGetXMLNode(psGeneral, "KeywordList"),
&(map->web.metadata), "KEYWORD", "wms_keywordlist", "," );
} else
msGetMapContextXMLHashValue(psGeneral, "Keywords",
&(map->web.metadata), "wms_keywordlist");
/* Window */
pszValue1 = (char*)CPLGetXMLValue(psGeneral,"Window.width",NULL);
pszValue2 = (char*)CPLGetXMLValue(psGeneral,"Window.height",NULL);
if(pszValue1 != NULL && pszValue2 != NULL) {
map->width = atoi(pszValue1);
map->height = atoi(pszValue2);
}
/* Abstract */
if( msGetMapContextXMLHashValue( psGeneral,
"Abstract", &(map->web.metadata),
"wms_abstract") == MS_FAILURE ) {
msGetMapContextXMLHashValue( psGeneral, "gml:description",
&(map->web.metadata), "wms_abstract");
}
/* DataURL */
msGetMapContextXMLHashValueDecode(psGeneral,
"DataURL.OnlineResource.xlink:href",
&(map->web.metadata), "wms_dataurl");
/* LogoURL */
/* The logourl have a width, height, format and an URL */
msLoadMapContextURLELements( CPLGetXMLNode(psGeneral, "LogoURL"),
&(map->web.metadata), "wms_logourl" );
/* DescriptionURL */
/* The descriptionurl have a width, height, format and an URL */
msLoadMapContextURLELements( CPLGetXMLNode(psGeneral,
"DescriptionURL"),
&(map->web.metadata), "wms_descriptionurl" );
/* Contact Info */
msLoadMapContextContactInfo(
CPLGetXMLNode(psGeneral, "ContactInformation"),
&(map->web.metadata) );
return MS_SUCCESS;
}
/*
** msLoadMapContextLayer
**
** Load a Layer block from a MapContext document
*/
int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
char *filename, int unique_layer_names)
{
char *pszProj=NULL;
char *pszValue;
char *pszHash, *pszName=NULL;
CPLXMLNode *psFormatList, *psFormat, *psStyleList, *psStyle, *psExtension;
CPLXMLNode *psDimensionList, *psDimension;
int nStyle;
layerObj *layer;
/* Init new layer */
if(msGrowMapLayers(map) == NULL)
return MS_FAILURE;
layer = (GET_LAYER(map, map->numlayers));
initLayer(layer, map);
layer->map = (mapObj *)map;
layer->type = MS_LAYER_RASTER;
/* save the index */
GET_LAYER(map, map->numlayers)->index = map->numlayers;
map->layerorder[map->numlayers] = map->numlayers;
map->numlayers++;
/* Status */
pszValue = (char*)CPLGetXMLValue(psLayer, "hidden", "1");
if((pszValue != NULL) && (atoi(pszValue) == 0 &&
!strcasecmp(pszValue, "true") == 0))
layer->status = MS_ON;
else
layer->status = MS_OFF;
/* Queryable */
pszValue = (char*)CPLGetXMLValue(psLayer, "queryable", "0");
if(pszValue !=NULL && (atoi(pszValue) == 1 ||
strcasecmp(pszValue, "true") == 0))
layer->template = msStrdup("ttt");
/* Name and Title */
pszValue = (char*)CPLGetXMLValue(psLayer, "Name", NULL);
if(pszValue != NULL) {
msInsertHashTable( &(layer->metadata), "wms_name", pszValue );
if (unique_layer_names) {
pszName = (char*)malloc(sizeof(char)*(strlen(pszValue)+15));
sprintf(pszName, "l%d:%s", layer->index, pszValue);
layer->name = msStrdup(pszName);
free(pszName);
} else
layer->name = msStrdup(pszValue);
} else {
pszName = (char*)malloc(sizeof(char)*15);
sprintf(pszName, "l%d:", layer->index);
layer->name = msStrdup(pszName);
free(pszName);
}
if(msGetMapContextXMLHashValue(psLayer, "Title", &(layer->metadata),
"wms_title") == MS_FAILURE) {
if(msGetMapContextXMLHashValue(psLayer, "Server.title",
&(layer->metadata), "wms_title") == MS_FAILURE) {
msDebug("Mandatory data Layer.Title missing in %s.", filename);
}
}
/* Server Title */
msGetMapContextXMLHashValue(psLayer, "Server.title", &(layer->metadata), "wms_server_title");
/* Abstract */
msGetMapContextXMLHashValue(psLayer, "Abstract", &(layer->metadata),
"wms_abstract");
/* DataURL */
if(nVersion <= OWS_0_1_4) {
msGetMapContextXMLHashValueDecode(psLayer,
"DataURL.OnlineResource.xlink:href",
&(layer->metadata), "wms_dataurl");
} else {
/* The DataURL have a width, height, format and an URL */
/* Width and height are not used, but they are included to */
/* be consistent with the spec. */
msLoadMapContextURLELements( CPLGetXMLNode(psLayer, "DataURL"),
&(layer->metadata), "wms_dataurl" );
}
/* The MetadataURL have a width, height, format and an URL */
/* Width and height are not used, but they are included to */
/* be consistent with the spec. */
msLoadMapContextURLELements( CPLGetXMLNode(psLayer, "MetadataURL"),
&(layer->metadata), "wms_metadataurl" );
/* MinScale && MaxScale */
pszValue = (char*)CPLGetXMLValue(psLayer, "sld:MinScaleDenominator", NULL);
if(pszValue != NULL) {
layer->minscaledenom = atof(pszValue);
}
pszValue = (char*)CPLGetXMLValue(psLayer, "sld:MaxScaleDenominator", NULL);
if(pszValue != NULL) {
layer->maxscaledenom = atof(pszValue);
}
/* */
/* Server */
/* */
if(nVersion >= OWS_0_1_4) {
if(msGetMapContextXMLStringValueDecode(psLayer,
"Server.OnlineResource.xlink:href",
&(layer->connection)) == MS_FAILURE) {
msSetError(MS_MAPCONTEXTERR,
"Mandatory data Server.OnlineResource.xlink:href missing in %s.",
"msLoadMapContext()", filename);
return MS_FAILURE;
} else {
msGetMapContextXMLHashValueDecode(psLayer,
"Server.OnlineResource.xlink:href",
&(layer->metadata), "wms_onlineresource");
layer->connectiontype = MS_WMS;
}
} else {
if(msGetMapContextXMLStringValueDecode(psLayer,
"Server.onlineResource",
&(layer->connection)) == MS_FAILURE) {
msSetError(MS_MAPCONTEXTERR,
"Mandatory data Server.onlineResource missing in %s.",
"msLoadMapContext()", filename);
return MS_FAILURE;
} else {
msGetMapContextXMLHashValueDecode(psLayer, "Server.onlineResource",
&(layer->metadata), "wms_onlineresource");
layer->connectiontype = MS_WMS;
}
}
if(nVersion >= OWS_0_1_4) {
if(msGetMapContextXMLHashValue(psLayer, "Server.version",
&(layer->metadata), "wms_server_version") == MS_FAILURE) {
msSetError(MS_MAPCONTEXTERR,
"Mandatory data Server.version missing in %s.",
"msLoadMapContext()", filename);
return MS_FAILURE;
}
} else {
if(msGetMapContextXMLHashValue(psLayer, "Server.wmtver",
&(layer->metadata), "wms_server_version") == MS_FAILURE) {
msSetError(MS_MAPCONTEXTERR,
"Mandatory data Server.wmtver missing in %s.",
"msLoadMapContext()", filename);
return MS_FAILURE;
}
}
/* Projection */
msLoadMapContextListInMetadata( psLayer, &(layer->metadata),
"SRS", "wms_srs", " " );
pszHash = msLookupHashTable(&(layer->metadata), "wms_srs");
if(((pszHash == NULL) || (strcasecmp(pszHash, "") == 0)) &&
map->projection.numargs != 0) {
pszProj = map->projection.args[map->projection.numargs-1];
if(pszProj != NULL) {
if(strncasecmp(pszProj, "AUTO:", 5) == 0) {
msInsertHashTable(&(layer->metadata),"wms_srs", pszProj);
} else {
if(strlen(pszProj) > 10) {
pszProj = (char*) malloc(sizeof(char) * (strlen(pszProj)));
sprintf( pszProj, "EPSG:%s",
map->projection.args[map->projection.numargs-1]+10);
msInsertHashTable(&(layer->metadata),"wms_srs", pszProj);
} else {
msDebug("Unable to set data for layer wms_srs from this"
" value %s.",
pszProj);
}
}
}
}
/* */
/* Format */
/* */
if( nVersion >= OWS_0_1_4 ) {
psFormatList = CPLGetXMLNode(psLayer, "FormatList");
} else {
psFormatList = psLayer;
}
if(psFormatList != NULL) {
for(psFormat = psFormatList->psChild;
psFormat != NULL;
psFormat = psFormat->psNext) {
msLoadMapContextLayerFormat(psFormat, layer);
}
} /* end FormatList parsing */
/* Style */
if( nVersion >= OWS_0_1_4 ) {
psStyleList = CPLGetXMLNode(psLayer, "StyleList");