-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathDataConfigurationUtils.java
More file actions
2285 lines (2004 loc) · 95.4 KB
/
DataConfigurationUtils.java
File metadata and controls
2285 lines (2004 loc) · 95.4 KB
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
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.util;
import gov.nasa.worldwind.avlist.*;
import gov.nasa.worldwind.cache.FileStore;
import gov.nasa.worldwind.exception.WWRuntimeException;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.layers.AbstractLayer;
import gov.nasa.worldwind.ogc.OGCConstants;
import gov.nasa.worldwind.ogc.wcs.wcs100.*;
import gov.nasa.worldwind.ogc.wms.*;
import gov.nasa.worldwind.terrain.AbstractElevationModel;
import gov.nasa.worldwind.wms.CapabilitiesRequest;
import org.w3c.dom.*;
import javax.xml.stream.events.XMLEvent;
import javax.xml.xpath.XPath;
import java.net.*;
import java.util.concurrent.*;
/**
* A collection of static methods useful for opening, reading, and otherwise working with WorldWind data configuration
* documents.
*
* @author dcollins
* @version $Id: DataConfigurationUtils.java 2120 2014-07-03 03:05:03Z tgaskins $
*/
public class DataConfigurationUtils
{
protected static final String DATE_TIME_PATTERN = "dd MM yyyy HH:mm:ss z";
protected static final String DEFAULT_TEXTURE_FORMAT = "image/dds";
/**
* Returns true if the specified {@link org.w3c.dom.Element} is a data configuration document. This recognizes the
* following data configuration documents: <ul> <li>Layer Configuration Documents</li> <li>Elevation Model
* Configuration Documents</li> <li>Installed DataDescriptor Documents</li> <li>WorldWind .NET LayerSet
* Documents</li> </ul>
*
* @param domElement the document in question.
*
* @return true if the document is a data configuration document; false otherwise.
*
* @throws IllegalArgumentException if the document is null.
*/
public static boolean isDataConfig(Element domElement)
{
if (domElement == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (AbstractLayer.isLayerConfigDocument(domElement))
{
return true;
}
if (AbstractElevationModel.isElevationModelConfigDocument(domElement))
{
return true;
}
if (isInstalledDataDescriptorConfigDocument(domElement))
{
return true;
}
//noinspection RedundantIfStatement
if (isWWDotNetLayerSetConfigDocument(domElement))
{
return true;
}
return false;
}
/**
* Returns the specified data configuration document transformed to a standard Layer or ElevationModel configuration
* document. This returns the original document if the document is already in a standard form, or if the document is
* not one of the recognized types. Installed DataDescriptor documents are transformed to standard Layer or
* ElevationModel configuration documents, depending on the document contents. WorldWind .NET LayerSet documents
* are transformed to standard Layer configuration documents. This returns null if the document's root element is
* null.
*
* @param doc the document to transform.
*
* @return the specified document transformed to a standard data configuration document, the original document if
* it's already in a standard form or is unrecognized, or null if the document's root element is null.
*
* @throws IllegalArgumentException if the document is null.
*/
public static Document convertToStandardDataConfigDocument(Document doc)
{
if (doc == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
Element el = doc.getDocumentElement();
if (el == null)
{
return null;
}
if (isInstalledDataDescriptorConfigDocument(el))
{
return transformInstalledDataDescriptorConfigDocument(el);
}
if (isWWDotNetLayerSetConfigDocument(el))
{
return transformWWDotNetLayerSetConfigDocument(el);
}
return doc;
}
/**
* Returns the specified data configuration document's display name as a string, or null if the document is not one
* of the recognized types. This determines the display name for each type of data configuration document as
* follows: <table> <tr><th>Document Type</th><th>Path to Display Name</th></tr> <tr><td>Layer
* Configuration</td><td>./DisplayName</td></tr> <tr><td>Elevation Model Configuration</td><td>./DisplayName</td></tr>
* <tr><td>Installed DataDescriptor</td><td>./property[@name="dataSet"]/property[@name="gov.nasa.worldwind.avkey.DatasetNameKey"]</td></tr>
* <tr><td>WorldWind .NET LayerSet</td><td>./QuadTileSet/Name</td></tr> <tr><td>Other</td><td>null</td></tr>
* </table>
*
* @param domElement the data configuration document who's display name is returned.
*
* @return a String representing the data configuration document's display name, or null if the document is not
* recognized.
*
* @throws IllegalArgumentException if the document is null.
*/
public static String getDataConfigDisplayName(Element domElement)
{
if (domElement == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (AbstractLayer.isLayerConfigDocument(domElement) || AbstractElevationModel.isElevationModelConfigDocument(
domElement))
{
return WWXML.getText(domElement, "DisplayName");
}
if (isInstalledDataDescriptorConfigDocument(domElement))
{
return WWXML.getText(domElement,
"property[@name=\"dataSet\"]/property[@name=\"gov.nasa.worldwind.avkey.DatasetNameKey\"]");
}
if (isWWDotNetLayerSetConfigDocument(domElement))
{
return WWXML.getText(domElement, "QuadTileSet/Name");
}
return null;
}
/**
* Returns the specified data configuration document's type as a string, or null if the document is not one of the
* recognized types. This maps data configuration documents to a type string as follows: <table> <tr><th>Document
* Type</th><th>Type String</th></tr> <tr><td>Layer Configuration</td><td>"Layer"</td></tr> <tr><td>Elevation Model
* Configuration</td><td>"Elevation Model"</td></tr> <tr><td>Installed DataDescriptor</td><td>"Layer" or
* "ElevationModel"</td></tr> <tr><td>WorldWind .NET LayerSet</td><td>"Layer"</td></tr>
* <tr><td>Other</td><td>null</td></tr> </table>
*
* @param domElement the data configuration document to determine a type for.
*
* @return a String representing the data configuration document's type, or null if the document is not recognized.
*
* @throws IllegalArgumentException if the document is null.
*/
public static String getDataConfigType(Element domElement)
{
if (domElement == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (AbstractLayer.isLayerConfigDocument(domElement))
{
return "Layer";
}
if (AbstractElevationModel.isElevationModelConfigDocument(domElement))
{
return "ElevationModel";
}
if (isInstalledDataDescriptorConfigDocument(domElement))
{
String s = WWXML.getText(domElement,
"property[@name=\"dataSet\"]/property[@name=\"gov.nasa.worldwind.avkey.DataType\"]",
null);
if (s != null && s.equals("gov.nasa.worldwind.avkey.TiledElevations"))
{
return "ElevationModel";
}
else
{
return "Layer";
}
}
if (isWWDotNetLayerSetConfigDocument(domElement))
{
return "Layer";
}
return null;
}
/**
* Returns a file store path name for the specified parameters list. This returns null if the parameter list does
* not contain enough information to construct a path name.
*
* @param params the parameter list to extract a configuration filename from.
* @param suffix the file suffix to append on the path name, or null to append no suffix.
*
* @return a file store path name with the specified suffix, or null if a path name cannot be constructed.
*
* @throws IllegalArgumentException if the parameter list is null.
*/
public static String getDataConfigFilename(AVList params, String suffix)
{
if (params == null)
{
String message = Logging.getMessage("nullValue.ParametersIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
String path = params.getStringValue(AVKey.DATA_CACHE_NAME);
if (path == null || path.length() == 0)
{
return null;
}
String filename = params.getStringValue(AVKey.DATASET_NAME);
if (filename == null || filename.length() == 0)
{
filename = params.getStringValue(AVKey.DISPLAY_NAME);
}
if (filename == null || filename.length() == 0)
{
filename = "DataConfiguration";
}
filename = WWIO.replaceIllegalFileNameCharacters(filename);
return path + java.io.File.separator + filename + (suffix != null ? suffix : "");
}
/**
* Convenience method for computing a data configuration file's cache name in a FileStore, given the file's cache
* path. This writes the computed cache name to the specified parameter list under the key {@link
* gov.nasa.worldwind.avlist.AVKey#DATA_CACHE_NAME}. If the parameter already exists, it's left unchanged.
* <p/>
* A data configuration file's cache name is its parent directory in the cache. The cache name therefore points to
* the directory containing both the configuration file and any cached data associated with it. Determining the
* cache name at run time - instead of hard wiring it in the data configuration file - enables cache data to be
* moved to an arbitrary location within the cache.
*
* @param dataConfigCachePath the data configuration file's cache path.
* @param params the output key-value pairs which receive the DATA_CACHE_NAME parameter. A null
* reference is permitted.
*
* @return a reference to params, or a new AVList if params is null.
*
* @throws IllegalArgumentException if the data config file's cache path is null or has length zero.
*/
public static AVList getDataConfigCacheName(String dataConfigCachePath, AVList params)
{
if (dataConfigCachePath == null || dataConfigCachePath.length() == 0)
{
String message = Logging.getMessage("nullValue.FilePathIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (params == null)
{
params = new AVListImpl();
}
String s = params.getStringValue(AVKey.DATA_CACHE_NAME);
if (s == null || s.length() == 0)
{
// Get the data configuration file's parent cache name.
s = WWIO.getParentFilePath(dataConfigCachePath);
if (s != null && s.length() > 0)
{
// Replace any windows-style path separators with the unix-style path separator, which is the convention
// for cache paths.
s = s.replaceAll("\\\\", "/");
params.setValue(AVKey.DATA_CACHE_NAME, s);
}
}
return params;
}
/**
* Returns true if a configuration file name exists in the store which has not expired. This returns false if a
* configuration file does not exist, or it has expired. This invokes {@link #findExistingDataConfigFile(gov.nasa.worldwind.cache.FileStore,
* String)} to determine the URL of any existing file names. If an existing file has expired, and removeIfExpired is
* true, this removes the existing file.
*
* @param fileStore the file store in which to look.
* @param fileName the file name to look for. If a file with this name does not exist in the store, this
* looks at the file's siblings for a match.
* @param removeIfExpired true to remove the existing file, if it exists and is expired; false otherwise.
* @param expiryTime the time in milliseconds, before which a file is considered to be expired.
*
* @return whether a configuration file already exists which has not expired.
*
* @throws IllegalArgumentException if either the file store or file name are null.
*/
public static boolean hasDataConfigFile(FileStore fileStore, String fileName, boolean removeIfExpired,
long expiryTime)
{
if (fileStore == null)
{
String message = Logging.getMessage("nullValue.FileStoreIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (fileName == null)
{
String message = Logging.getMessage("nullValue.FilePathIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
// Look for an existing configuration file in the store. Return true if a configuration file does not exist,
// or it has expired; otherwise return false.
java.net.URL url = findExistingDataConfigFile(fileStore, fileName);
if (url != null && !WWIO.isFileOutOfDate(url, expiryTime))
{
return true;
}
// A configuration file exists but it is expired. Remove the file and return false, indicating that there is
// no configuration document.
if (url != null && removeIfExpired)
{
fileStore.removeFile(url);
String message = Logging.getMessage("generic.DataFileExpired", url);
Logging.logger().fine(message);
}
return false;
}
/**
* Returns the URL of an existing data configuration file under the specified file store, or null if no
* configuration file exists. This first looks for a configuration file with the specified name. If that does not
* exist, this checks the siblings of the specified file for a configuration file match.
*
* @param fileStore the file store in which to look.
* @param fileName the file name to look for. If a file with this name does not exist in the store, this looks at
* the file's siblings for a match.
*
* @return the URL of an existing configuration file in the store, or null if none exists.
*
* @throws IllegalArgumentException if either the file store or file name are null.
*/
public static java.net.URL findExistingDataConfigFile(FileStore fileStore, String fileName)
{
if (fileStore == null)
{
String message = Logging.getMessage("nullValue.FileStoreIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (fileName == null)
{
String message = Logging.getMessage("nullValue.FilePathIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
// Attempt to find the specified file name in the store. If it exists, then we've found a match and we're done.
java.net.URL url = fileStore.findFile(fileName, false);
if (url != null)
{
return url;
}
// If the specified name did not exist, then try to find any data configuration file under the file's parent
// path. Find only the file names which are siblings of the specified file name.
String path = WWIO.getParentFilePath(fileName);
if (path == null || path.length() == 0)
{
return null;
}
String[] names = fileStore.listFileNames(path, new DataConfigurationFilter());
if (names == null || names.length == 0)
{
return null;
}
// Ignore all but the first file match.
return fileStore.findFile(names[0], false);
}
/**
* Convenience method to create a {@link java.util.concurrent.ScheduledExecutorService} which can be used by World
* Wind components to schedule periodic resource checks. The returned ExecutorService is backed by a single daemon
* thread with minimum priority.
*
* @param threadName the String name for the ExecutorService's thread, may be <code>null</code>.
*
* @return a new ScheduledExecutorService appropriate for scheduling periodic resource checks.
*/
public static ScheduledExecutorService createResourceRetrievalService(final String threadName)
{
ThreadFactory threadFactory = new ThreadFactory()
{
public Thread newThread(Runnable r)
{
Thread thread = new Thread(r);
thread.setDaemon(true);
thread.setPriority(Thread.MIN_PRIORITY);
if (threadName != null)
{
thread.setName(threadName);
}
return thread;
}
};
return Executors.newSingleThreadScheduledExecutor(threadFactory);
}
//**************************************************************//
//******************** WMS Common Configuration **************//
//**************************************************************//
/**
* Appends WMS layer parameters as elements to a specified context. This appends elements for the following
* parameters: <table> <th><td>Parameter</td><td>Element Path</td><td>Type</td></th> <tr><td>{@link
* AVKey#WMS_VERSION}</td><td>Service/@version</td><td>String</td></tr> <tr><td>{@link
* AVKey#LAYER_NAMES}</td><td>Service/LayerNames</td><td>String</td></tr> <tr><td>{@link
* AVKey#STYLE_NAMES}</td><td>Service/StyleNames</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_MAP_URL}</td><td>Service/GetMapURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_CAPABILITIES_URL}</td><td>Service/GetCapabilitiesURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#SERVICE}</td><td>AVKey#GET_MAP_URL</td><td>String</td></tr> <tr><td>{@link
* AVKey#DATASET_NAME}</td><td>AVKey.LAYER_NAMES</td><td>String</td></tr> </table>
*
* @param params the key-value pairs which define the WMS layer configuration parameters.
* @param context the XML document root on which to append WMS layer configuration elements.
*
* @return a reference to context.
*
* @throws IllegalArgumentException if either the parameters or the context are null.
*/
public static Element createWMSLayerConfigElements(AVList params, Element context)
{
if (params == null)
{
String message = Logging.getMessage("nullValue.ParametersIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (context == null)
{
String message = Logging.getMessage("nullValue.ContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
XPath xpath = WWXML.makeXPath();
// Service properties. The service element may already exist, in which case we want to append the "URL" element
// to the existing service element.
Element el = WWXML.getElement(context, "Service", xpath);
if (el == null)
{
el = WWXML.appendElementPath(context, "Service");
}
// Try to get the SERVICE_NAME property, but default to "OGC:WMS".
String s = AVListImpl.getStringValue(params, AVKey.SERVICE_NAME, OGCConstants.WMS_SERVICE_NAME);
if (s != null && s.length() > 0)
{
WWXML.setTextAttribute(el, "serviceName", s);
}
s = params.getStringValue(AVKey.WMS_VERSION);
if (s != null && s.length() > 0)
{
WWXML.setTextAttribute(el, "version", s);
}
WWXML.checkAndAppendTextElement(params, AVKey.LAYER_NAMES, el, "LayerNames");
WWXML.checkAndAppendTextElement(params, AVKey.STYLE_NAMES, el, "StyleNames");
WWXML.checkAndAppendTextElement(params, AVKey.GET_MAP_URL, el, "GetMapURL");
WWXML.checkAndAppendTextElement(params, AVKey.GET_CAPABILITIES_URL, el, "GetCapabilitiesURL");
// Since this is a WMS tiled image layer, we want to express the service URL as a GetMap URL. If we have a
// GET_MAP_URL property, then remove any existing SERVICE property from the DOM document.
s = params.getStringValue(AVKey.GET_MAP_URL);
if (s != null && s.length() > 0)
{
Element urlElement = WWXML.getElement(el, "URL", xpath);
if (urlElement != null)
{
el.removeChild(urlElement);
}
}
return context;
}
/**
* Appends WCS layer parameters as elements to a specified context. This appends elements for the following
* parameters: <table> <th><td>Parameter</td><td>Element Path</td><td>Type</td></th> <tr><td>{@link
* AVKey#WCS_VERSION}</td><td>Service/@version</td><td>String</td></tr> <tr><td>{@link
* AVKey#COVERAGE_IDENTIFIERS}</td><td>Service/coverageIdentifiers</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_COVERAGE_URL}</td><td>Service/GetCoverageURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_CAPABILITIES_URL}</td><td>Service/GetCapabilitiesURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#SERVICE}</td><td>AVKey#GET_COVERAGE_URL</td><td>String</td></tr> <tr><td>{@link
* AVKey#DATASET_NAME}</td><td>AVKey.COVERAGE_IDENTIFIERS</td><td>String</td></tr> </table>
*
* @param params the key-value pairs which define the WMS layer configuration parameters.
* @param context the XML document root on which to append WMS layer configuration elements.
*
* @return a reference to context.
*
* @throws IllegalArgumentException if either the parameters or the context are null.
*/
public static Element createWCSLayerConfigElements(AVList params, Element context)
{
if (params == null)
{
String message = Logging.getMessage("nullValue.ParametersIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (context == null)
{
String message = Logging.getMessage("nullValue.ContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
XPath xpath = WWXML.makeXPath();
// Service properties. The service element may already exist, in which case we want to append the "URL" element
// to the existing service element.
Element el = WWXML.getElement(context, "Service", xpath);
if (el == null)
{
el = WWXML.appendElementPath(context, "Service");
}
// Try to get the SERVICE_NAME property, but default to "OGC:WCS".
String s = AVListImpl.getStringValue(params, AVKey.SERVICE_NAME, OGCConstants.WCS_SERVICE_NAME);
if (s != null && s.length() > 0)
{
WWXML.setTextAttribute(el, "serviceName", s);
}
s = params.getStringValue(AVKey.WCS_VERSION);
if (s != null && s.length() > 0)
{
WWXML.setTextAttribute(el, "version", s);
}
WWXML.checkAndAppendTextElement(params, AVKey.COVERAGE_IDENTIFIERS, el, "CoverageIdentifiers");
WWXML.checkAndAppendTextElement(params, AVKey.GET_COVERAGE_URL, el, "GetCoverageURL");
WWXML.checkAndAppendTextElement(params, AVKey.GET_CAPABILITIES_URL, el, "GetCapabilitiesURL");
// Since this is a WCS tiled coverage, we want to express the service URL as a GetCoverage URL. If we have a
// GET_COVERAGE_URL property, then remove any existing SERVICE property from the DOM document.
s = params.getStringValue(AVKey.GET_COVERAGE_URL);
if (s != null && s.length() > 0)
{
Element urlElement = WWXML.getElement(el, "URL", xpath);
if (urlElement != null)
{
el.removeChild(urlElement);
}
}
return context;
}
/**
* Parses WMS layer parameters from the XML configuration document starting at domElement. This writes output as
* key-value pairs to params. If a parameter from the XML document already exists in params, that parameter is
* ignored. Supported key and parameter names are: <table> <th><td>Parameter</td><td>Element
* Path</td><td>Type</td></th> <tr><td>{@link AVKey#WMS_VERSION}</td><td>Service/@version</td><td>String</td></tr>
* <tr><td>{@link AVKey#LAYER_NAMES}</td><td>Service/LayerNames</td><td>String</td></tr> <tr><td>{@link
* AVKey#STYLE_NAMES}</td><td>Service/StyleNames</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_MAP_URL}</td><td>Service/GetMapURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#GET_CAPABILITIES_URL}</td><td>Service/GetCapabilitiesURL</td><td>String</td></tr> <tr><td>{@link
* AVKey#SERVICE}</td><td>AVKey#GET_MAP_URL</td><td>String</td></tr> <tr><td>{@link
* AVKey#DATASET_NAME}</td><td>AVKey.LAYER_NAMES</td><td>String</td></tr> </table>
*
* @param domElement the XML document root to parse for WMS layer parameters.
* @param params the output key-value pairs which receive the WMS layer parameters. A null reference is
* permitted.
*
* @return a reference to params, or a new AVList if params is null.
*
* @throws IllegalArgumentException if the document is null.
*/
public static AVList getWMSLayerConfigParams(Element domElement, AVList params)
{
if (domElement == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (params == null)
{
params = new AVListImpl();
}
XPath xpath = WWXML.makeXPath();
// Need to determine these for URLBuilder construction.
WWXML.checkAndSetStringParam(domElement, params, AVKey.WMS_VERSION, "Service/@version", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.LAYER_NAMES, "Service/LayerNames", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.STYLE_NAMES, "Service/StyleNames", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.GET_MAP_URL, "Service/GetMapURL", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.GET_CAPABILITIES_URL, "Service/GetCapabilitiesURL",
xpath);
params.setValue(AVKey.SERVICE, params.getValue(AVKey.GET_MAP_URL));
String serviceURL = params.getStringValue(AVKey.SERVICE);
if (serviceURL != null)
{
params.setValue(AVKey.SERVICE, WWXML.fixGetMapString(serviceURL));
}
// The dataset name is the layer-names string for WMS elevation models
String layerNames = params.getStringValue(AVKey.LAYER_NAMES);
if (layerNames != null)
{
params.setValue(AVKey.DATASET_NAME, layerNames);
}
return params;
}
public static AVList getWCSConfigParams(Element domElement, AVList params)
{
if (domElement == null)
{
String message = Logging.getMessage("nullValue.DocumentIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (params == null)
{
params = new AVListImpl();
}
XPath xpath = WWXML.makeXPath();
// Need to determine these for URLBuilder construction.
WWXML.checkAndSetStringParam(domElement, params, AVKey.WCS_VERSION, "Service/@version", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.COVERAGE_IDENTIFIERS, "Service/CoverageIdentifiers",
xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.GET_COVERAGE_URL, "Service/GetCoverageURL", xpath);
WWXML.checkAndSetStringParam(domElement, params, AVKey.GET_CAPABILITIES_URL, "Service/GetCapabilitiesURL",
xpath);
params.setValue(AVKey.SERVICE, params.getValue(AVKey.GET_COVERAGE_URL));
String serviceURL = params.getStringValue(AVKey.SERVICE);
if (serviceURL != null)
{
params.setValue(AVKey.SERVICE, WWXML.fixGetMapString(serviceURL));
}
// The dataset name is the layer-names string for WMS elevation models
String coverages = params.getStringValue(AVKey.COVERAGE_IDENTIFIERS);
if (coverages != null)
{
params.setValue(AVKey.DATASET_NAME, coverages);
}
return params;
}
public static AVList getWMSLayerConfigParams(WMSCapabilities caps, String[] formatOrderPreference, AVList params)
{
if (caps == null)
{
String message = Logging.getMessage("nullValue.WMSCapabilities");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (params == null)
{
String message = Logging.getMessage("nullValue.ParametersIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
String layerNames = params.getStringValue(AVKey.LAYER_NAMES);
String styleNames = params.getStringValue(AVKey.STYLE_NAMES);
if (layerNames == null || layerNames.length() == 0)
{
String message = Logging.getMessage("nullValue.WMSLayerNames");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
String[] names = layerNames.split(",");
if (names == null || names.length == 0)
{
String message = Logging.getMessage("nullValue.WMSLayerNames");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
String coordinateSystem = params.getStringValue(AVKey.COORDINATE_SYSTEM);
if (WWUtil.isEmpty(coordinateSystem))
{
for (String name : names)
{
WMSLayerCapabilities layerCaps = caps.getLayerByName(name);
if (layerCaps == null)
{
String msg = Logging.getMessage("WMS.LayerNameMissing", name);
Logging.logger().warning(msg);
throw new WWRuntimeException(msg);
}
if (layerCaps.hasCoordinateSystem("EPSG:4326"))
{
coordinateSystem = "EPSG:4326";
break; // this assumes that the CS is available for all the layers in layerNames
}
else if (layerCaps.hasCoordinateSystem("CRS:84"))
{
coordinateSystem = "CRS:84";
break; // this assumes that the CS is available for all the layers in layerNames
}
}
if (!WWUtil.isEmpty(coordinateSystem))
params.setValue(AVKey.COORDINATE_SYSTEM, coordinateSystem);
}
// Define the DISPLAY_NAME and DATASET_NAME from the WMS layer names and styles.
params.setValue(AVKey.DISPLAY_NAME, makeTitle(caps, layerNames, styleNames));
params.setValue(AVKey.DATASET_NAME, layerNames);
// Get the EXPIRY_TIME from the WMS layer last update time.
Long lastUpdate = caps.getLayerLatestLastUpdateTime(names);
if (lastUpdate != null)
{
params.setValue(AVKey.EXPIRY_TIME, lastUpdate);
}
// Get the GET_MAP_URL from the WMS getMapRequest URL.
String mapRequestURIString = caps.getRequestURL("GetMap", "http", "get");
if (params.getValue(AVKey.GET_MAP_URL) == null)
{
params.setValue(AVKey.GET_MAP_URL, mapRequestURIString);
}
mapRequestURIString = params.getStringValue(AVKey.GET_MAP_URL);
// Throw an exception if there's no GET_MAP_URL property, or no getMapRequest URL in the WMS Capabilities.
if (mapRequestURIString == null || mapRequestURIString.length() == 0)
{
Logging.logger().severe("WMS.RequestMapURLMissing");
throw new WWRuntimeException(Logging.getMessage("WMS.RequestMapURLMissing"));
}
// Get the GET_CAPABILITIES_URL from the WMS getCapabilitiesRequest URL.
String capsRequestURIString = caps.getRequestURL("GetCapabilities", "http", "get");
if (params.getValue(AVKey.GET_CAPABILITIES_URL) == null)
{
params.setValue(AVKey.GET_CAPABILITIES_URL, capsRequestURIString);
}
// Define the SERVICE from the GET_MAP_URL property.
params.setValue(AVKey.SERVICE, params.getValue(AVKey.GET_MAP_URL));
String serviceURL = params.getStringValue(AVKey.SERVICE);
if (serviceURL != null)
{
params.setValue(AVKey.SERVICE, WWXML.fixGetMapString(serviceURL));
}
// Define the SERVICE_NAME as the standard OGC WMS service string.
if (params.getValue(AVKey.SERVICE_NAME) == null)
{
params.setValue(AVKey.SERVICE_NAME, OGCConstants.WMS_SERVICE_NAME);
}
// Define the WMS VERSION as the version fetched from the Capabilities document.
String versionString = caps.getVersion();
if (params.getValue(AVKey.WMS_VERSION) == null)
{
params.setValue(AVKey.WMS_VERSION, versionString);
}
// Form the cache path DATA_CACHE_NAME from a set of unique WMS parameters.
if (params.getValue(AVKey.DATA_CACHE_NAME) == null)
{
try
{
URI mapRequestURI = new URI(mapRequestURIString);
String cacheName = WWIO.formPath(mapRequestURI.getAuthority(), mapRequestURI.getPath(), layerNames,
styleNames);
params.setValue(AVKey.DATA_CACHE_NAME, cacheName);
}
catch (URISyntaxException e)
{
String message = Logging.getMessage("WMS.RequestMapURLBad", mapRequestURIString);
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
throw new WWRuntimeException(message);
}
}
// Determine image format to request.
if (params.getStringValue(AVKey.IMAGE_FORMAT) == null)
{
String imageFormat = chooseImageFormat(caps.getImageFormats().toArray(), formatOrderPreference);
params.setValue(AVKey.IMAGE_FORMAT, imageFormat);
}
// Throw an exception if we cannot determine an image format to request.
if (params.getStringValue(AVKey.IMAGE_FORMAT) == null)
{
Logging.logger().severe("WMS.NoImageFormats");
throw new WWRuntimeException(Logging.getMessage("WMS.NoImageFormats"));
}
// Determine bounding sector.
Sector sector = (Sector) params.getValue(AVKey.SECTOR);
if (sector == null)
{
for (String name : names)
{
Sector layerSector = caps.getLayerByName(name).getGeographicBoundingBox();
if (layerSector == null)
{
Logging.logger().log(java.util.logging.Level.SEVERE, "WMS.NoGeographicBoundingBoxForLayer", name);
continue;
}
sector = Sector.union(sector, layerSector);
}
if (sector == null)
{
Logging.logger().severe("WMS.NoGeographicBoundingBox");
throw new WWRuntimeException(Logging.getMessage("WMS.NoGeographicBoundingBox"));
}
params.setValue(AVKey.SECTOR, sector);
}
// TODO: adjust for subsetable, fixedimage, etc.
return params;
}
public static AVList getWCSConfigParameters(WCS100Capabilities caps, WCS100DescribeCoverage coverage, AVList params)
{
if (caps == null)
{
String message = Logging.getMessage("nullValue.WMSCapabilities");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (coverage == null)
{
String message = Logging.getMessage("nullValue.WCSDescribeCoverage");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (coverage.getCoverageOfferings().size() == 0)
{
String message = Logging.getMessage("AbsentResourceList.WCSDescribeCoverage");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (params == null)
{
String message = Logging.getMessage("nullValue.ParametersIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
WCS100CoverageOffering offering = coverage.getCoverageOfferings().get(0);
params.setValue(AVKey.SERVICE_NAME, OGCConstants.WCS_SERVICE_NAME);
params.setValue(AVKey.WCS_VERSION, caps.getVersion() != null ? caps.getVersion() : "1.0.0");
params.setValue(AVKey.DISPLAY_NAME, offering.getLabel());
params.setValue(AVKey.COVERAGE_IDENTIFIERS, offering.getName());
params.setValue(AVKey.GET_COVERAGE_URL, caps.getCapability().getGetOperationAddress("GetCoverage"));
params.setValue(AVKey.GET_CAPABILITIES_URL, caps.getCapability().getGetOperationAddress("GetCapabilities"));
params.setValue(AVKey.SERVICE, params.getValue(AVKey.GET_COVERAGE_URL));
String serviceURL = params.getStringValue(AVKey.SERVICE);
if (serviceURL != null)
{
params.setValue(AVKey.SERVICE, WWXML.fixGetMapString(serviceURL));
}
String coverages = params.getStringValue(AVKey.COVERAGE_IDENTIFIERS);
if (coverages != null)
{
params.setValue(AVKey.DATASET_NAME, coverages);
}
// Form the cache path DATA_CACHE_NAME from a set of unique WMS parameters.
if (params.getValue(AVKey.DATA_CACHE_NAME) == null)
{
try
{
URI mapRequestURI = new URI(params.getStringValue(AVKey.GET_COVERAGE_URL));
String cacheName = WWIO.formPath(mapRequestURI.getAuthority(), mapRequestURI.getPath(),
params.getStringValue(AVKey.COVERAGE_IDENTIFIERS));
params.setValue(AVKey.DATA_CACHE_NAME, cacheName);
}
catch (URISyntaxException e)
{
String message = Logging.getMessage("WCS.RequestMapURLBad",
params.getStringValue(AVKey.GET_COVERAGE_URL));
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
throw new WWRuntimeException(message);
}
}
for (String format : offering.getSupportedFormats().getStrings())
{
if (format.toLowerCase().contains("image/tiff"))
{
params.setValue(AVKey.IMAGE_FORMAT, format);
break;
}
else if (format.toLowerCase().contains("tiff")) // lots of variants in use, so find one
{
params.setValue(AVKey.IMAGE_FORMAT, format);
break;
}
}
// Determine bounding sector.
WCS100LonLatEnvelope envelope = offering.getLonLatEnvelope();
if (envelope != null)
{
double[] sw = envelope.getPositions().get(0).getPos2();
double[] ne = envelope.getPositions().get(1).getPos2();
if (sw != null && ne != null)
{
params.setValue(AVKey.SECTOR, Sector.fromDegreesAndClamp(sw[1], ne[1], sw[0], ne[0]));
}
}
String epsg4326 = "EPSG:4326";
String crs = null;
if (offering.getSupportedCRSs() != null)
{
if (offering.getSupportedCRSs().getRequestResponseCRSs().contains(epsg4326))
{
crs = epsg4326;
} else if (offering.getSupportedCRSs().getRequestCRSs().contains(epsg4326)
&& offering.getSupportedCRSs().getResponseCRSs().contains(epsg4326))
{
crs = epsg4326;
}