5
5
package org .geoserver .csw .store .internal ;
6
6
7
7
import java .io .File ;
8
- import java .io .FileInputStream ;
9
8
import java .io .IOException ;
10
9
import java .util .HashMap ;
11
10
import java .util .Map ;
12
- import java .util .Properties ;
11
+ import java .util .logging .Level ;
12
+ import java .util .logging .Logger ;
13
13
14
14
import org .geoserver .config .GeoServer ;
15
15
import org .geoserver .platform .GeoServerResourceLoader ;
16
+ import org .geoserver .security .PropertyFileWatcher ;
17
+ import org .geotools .util .logging .Logging ;
16
18
17
19
/**
18
20
* Internal Catalog Store that automatically loads mappings from mapping files in GeoServer Data Directory.
21
23
*
22
24
*/
23
25
public class GeoServerInternalCatalogStore extends InternalCatalogStore {
26
+
27
+ protected static final Logger LOGGER = Logging .getLogger (GeoServerInternalCatalogStore .class );
28
+
29
+ protected Map <String , PropertyFileWatcher > watchers = new HashMap <String , PropertyFileWatcher >();
30
+
31
+ /**
32
+ * Get Mapping, update from file if changed
33
+ *
34
+ * @param typeName
35
+ * @return the mapping
36
+ */
37
+ public CatalogStoreMapping getMapping (String typeName ) {
38
+
39
+ PropertyFileWatcher watcher = watchers .get (typeName );
40
+
41
+ if (watcher !=null && watcher .isModified () ) {
42
+ try {
43
+ addMapping (typeName , CatalogStoreMapping .parse (new HashMap <String , String >((Map ) watcher .getProperties ())));
44
+ } catch (IOException e ) {
45
+ LOGGER .log (Level .WARNING , e .toString ());
46
+ }
47
+ }
48
+
49
+ return super .getMapping ( typeName );
50
+ }
24
51
25
52
/**
26
53
* Create GeoServerInternalCatalogStore
@@ -32,12 +59,17 @@ public GeoServerInternalCatalogStore(GeoServer geoserver) throws IOException {
32
59
super ( geoserver .getCatalog ());
33
60
GeoServerResourceLoader loader = geoserver .getCatalog ().getResourceLoader ();
34
61
File dir = loader .findOrCreateDirectory ("csw" );
35
- for (File f : dir .listFiles ()) {
36
- Properties properties = new Properties ();
37
- FileInputStream in = new FileInputStream (f );
38
- properties .load (in );
39
- in .close ();
40
- addMapping (f .getName (), CatalogStoreMapping .parse (new HashMap <String , String >((Map ) properties )));
62
+ for (String typeName : descriptorByType .keySet ()) {
63
+ File f = new File (dir , typeName + ".properties" );
64
+
65
+ PropertyFileWatcher watcher = new PropertyFileWatcher (f );
66
+ watchers .put (typeName , watcher );
67
+
68
+ if (f .exists ()) {
69
+ addMapping (typeName , CatalogStoreMapping .parse (new HashMap <String , String >((Map ) watcher .getProperties ())));
70
+ } else {
71
+ addMapping (typeName , new CatalogStoreMapping ());
72
+ }
41
73
}
42
74
}
43
75
0 commit comments