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