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 package fr.paris.lutece.util;
35
36 import java.util.ArrayList;
37 import java.util.Enumeration;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Properties;
42
43 import fr.paris.lutece.portal.service.util.AppPathService;
44
45
46
47
48 public final class AppInitPropertiesService
49 {
50 private static final String FILE_PROPERTIES_CONFIG = "config.properties";
51 private static final String FILE_PROPERTIES_DATABASE = "db.properties";
52 private static final String FILE_PROPERTIES_LUTECE = "lutece.properties";
53 private static final String FILE_PROPERTIES_SEARCH = "search.properties";
54 private static final String FILE_PROPERTIES_DAEMONS = "daemons.properties";
55 private static final String FILE_PROPERTIES_CACHES = "caches.properties";
56 private static final String FILE_PROPERTIES_EDITORS = "editors.properties";
57 private static final String PATH_PLUGINS = "plugins/";
58 private static final String PATH_OVERRIDE_CORE = "override/";
59 private static final String PATH_OVERRIDE_PLUGINS = "override/plugins";
60 private static PropertiesService _propertiesService;
61
62
63
64
65 private AppInitPropertiesService( )
66 {
67 }
68
69
70
71
72
73
74
75 public static void init( String strConfPath )
76 {
77 String confPath = strConfPath;
78 _propertiesService = new PropertiesService( AppPathService.getWebAppPath( ) );
79
80 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_CONFIG );
81 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_DATABASE );
82 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_LUTECE );
83 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_SEARCH );
84 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_DAEMONS );
85 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_CACHES );
86 _propertiesService.addPropertiesFile( confPath, FILE_PROPERTIES_EDITORS );
87 _propertiesService.addPropertiesDirectory( confPath + PATH_PLUGINS );
88 _propertiesService.addPropertiesDirectory( confPath + PATH_OVERRIDE_CORE );
89 _propertiesService.addPropertiesDirectory( confPath + PATH_OVERRIDE_PLUGINS );
90 }
91
92
93
94
95
96
97
98
99 public static String getProperty( String strProperty )
100 {
101 return _propertiesService.getProperty( strProperty );
102 }
103
104
105
106 public static void reloadAll( )
107 {
108 _propertiesService.reloadAll( );
109 }
110
111
112
113
114
115
116
117 public static void reload( String strFilename )
118 {
119 _propertiesService.reload( strFilename );
120 }
121
122
123
124
125
126
127
128 public static Properties getProperties( )
129 {
130
131 return new Properties( _propertiesService.getProperties( ) );
132 }
133
134
135
136
137 public static Map<String, String> getPropertiesAsMap( )
138 {
139 Map<String, String> res = new HashMap<>( );
140 Properties properties = _propertiesService.getProperties( );
141
142
143 Enumeration<?> names = properties.propertyNames( );
144
145 while ( names.hasMoreElements( ) )
146 {
147 String name = (String) names.nextElement( );
148 res.put( name, properties.getProperty( name ) );
149 }
150
151 return res;
152 }
153
154
155
156
157
158
159
160
161 public static List<String> getKeys( String strPrefix )
162 {
163 List<String> listKeys = new ArrayList<>( );
164 Enumeration eList = _propertiesService.getProperties( ).keys( );
165
166 while ( eList.hasMoreElements( ) )
167 {
168 String strKey = (String) eList.nextElement( );
169
170 if ( strKey.startsWith( strPrefix ) )
171 {
172 listKeys.add( strKey );
173 }
174 }
175
176 return listKeys;
177 }
178 }