Revision 4709
Added by daigle over 15 years ago
SkinPropertyService.java | ||
---|---|---|
72 | 72 |
* |
73 | 73 |
* @param servletContext the context we will use to get relative paths |
74 | 74 |
*/ |
75 |
private SkinPropertyService(ServletContext servletContext) throws ServiceException {
|
|
75 |
private SkinPropertyService() throws ServiceException { |
|
76 | 76 |
try { |
77 |
initialize(servletContext);
|
|
77 |
initialize(); |
|
78 | 78 |
} catch (GeneralPropertyException gpe) { |
79 | 79 |
throw new ServiceException( |
80 | 80 |
"Properties problem while initializing PropertyService: " |
... | ... | |
91 | 91 |
* @param servletContext the context we will use to get relative paths |
92 | 92 |
* @return the single instance of SkinPropertyService |
93 | 93 |
*/ |
94 |
public static SkinPropertyService getInstance(ServletContext servletContext) throws ServiceException {
|
|
94 |
public static SkinPropertyService getInstance() throws ServiceException { |
|
95 | 95 |
if (skinService == null) { |
96 |
skinService = new SkinPropertyService(servletContext);
|
|
96 |
skinService = new SkinPropertyService(); |
|
97 | 97 |
} |
98 | 98 |
return skinService; |
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
public boolean refreshable() { |
102 |
return false;
|
|
102 |
return true;
|
|
103 | 103 |
} |
104 | 104 |
|
105 |
protected void doRefresh() { |
|
106 |
return; |
|
105 |
protected void doRefresh() throws ServiceException { |
|
106 |
try { |
|
107 |
initialize(); |
|
108 |
} catch (IOException ioe) { |
|
109 |
throw new ServiceException("Could not refresh SkinPropertyService due to" |
|
110 |
+ " I/O error: " + ioe.getMessage()); |
|
111 |
} catch (GeneralPropertyException gpe) { |
|
112 |
throw new ServiceException("Could not refresh SkinPropertyService due to" |
|
113 |
+ " property error: " + gpe.getMessage()); |
|
114 |
} |
|
107 | 115 |
} |
108 | 116 |
|
109 | 117 |
/** |
... | ... | |
112 | 120 |
* @param servletContext |
113 | 121 |
* the context we will use to get relative paths |
114 | 122 |
*/ |
115 |
private void initialize(ServletContext servletContext) throws IOException,
|
|
116 |
GeneralPropertyException { |
|
123 |
private void initialize() throws IOException, |
|
124 |
GeneralPropertyException, ServiceException {
|
|
117 | 125 |
|
118 | 126 |
logMetacat.debug("Initializing SkinService"); |
119 | 127 |
|
120 |
SKIN_DIR = "/style/skins"; |
|
121 |
BACKUP_DIR = PropertyService.getBackupDir(); |
|
128 |
BACKUP_DIR = PropertyService.getProperty("application.backupDir") + FileUtil.getFS() + ".metacat"; |
|
122 | 129 |
|
123 | 130 |
skinNames = SkinUtil.getSkinNames(); |
124 | 131 |
|
... | ... | |
128 | 135 |
|
129 | 136 |
try { |
130 | 137 |
for (String skinName : skinNames) { |
131 |
String propertyFilePath = servletContext.getRealPath(SKIN_DIR)
|
|
138 |
String propertyFilePath = ServiceService.getRealSkinDir()
|
|
132 | 139 |
+ FileUtil.getFS() + skinName + FileUtil.getFS() + skinName |
133 | 140 |
+ ".properties"; |
134 | 141 |
SortedProperties skinProperties = new SortedProperties(propertyFilePath); |
135 | 142 |
skinProperties.load(); |
136 | 143 |
skinPropertiesMap.put(skinName, skinProperties); |
137 | 144 |
|
138 |
String metaDataFilePath = servletContext.getRealPath(SKIN_DIR)
|
|
145 |
String metaDataFilePath = ServiceService.getRealSkinDir()
|
|
139 | 146 |
+ FileUtil.getFS() + skinName + FileUtil.getFS() + skinName |
140 | 147 |
+ ".properties.metadata.xml"; |
141 | 148 |
if (FileUtil.getFileStatus(metaDataFilePath) == FileUtil.DOES_NOT_EXIST) { |
142 | 149 |
throw new GeneralPropertyException("Could not find skin property metadata file: " + metaDataFilePath); |
143 | 150 |
} else { |
144 |
PropertiesMetaData skinMetaData = |
|
145 |
new PropertiesMetaData(metaDataFilePath); |
|
151 |
PropertiesMetaData skinMetaData = new PropertiesMetaData(metaDataFilePath); |
|
146 | 152 |
skinMetaDataMap.put(skinName, skinMetaData); |
147 | 153 |
} |
148 | 154 |
|
... | ... | |
345 | 351 |
/** |
346 | 352 |
* Writes out backup configurable properties to a file. |
347 | 353 |
*/ |
348 |
public static void persistBackupProperties(String skinName, ServletContext servletContext) |
|
349 |
throws GeneralPropertyException { |
|
350 |
|
|
351 |
String metaDataFilePath = servletContext.getRealPath(SKIN_DIR) + FileUtil.getFS() |
|
352 |
+ skinName + FileUtil.getFS() + skinName + ".properties.metadata.xml"; |
|
353 |
|
|
354 |
String backupPropertyFilePath = |
|
355 |
BACKUP_DIR + FileUtil.getFS() + skinName + ".properties.backup"; |
|
354 |
public static void persistBackupProperties(String skinName) throws GeneralPropertyException { |
|
355 |
try { |
|
356 |
String metaDataFilePath = ServiceService.getRealSkinDir() + FileUtil.getFS() |
|
357 |
+ skinName + FileUtil.getFS() + skinName + ".properties.metadata.xml"; |
|
356 | 358 |
|
357 |
// Use the metadata to extract configurable properties from the |
|
358 |
// overall properties list, and store those properties. |
|
359 |
try { |
|
359 |
String backupPropertyFilePath = BACKUP_DIR + FileUtil.getFS() + skinName |
|
360 |
+ ".properties.backup"; |
|
361 |
|
|
362 |
// Use the metadata to extract configurable properties from the |
|
363 |
// overall properties list, and store those properties. |
|
360 | 364 |
SortedProperties backupProperties = |
361 | 365 |
new SortedProperties(backupPropertyFilePath); |
362 | 366 |
|
... | ... | |
377 | 381 |
} catch (IOException ioe) { |
378 | 382 |
throw new GeneralPropertyException("Could not backup configurable properties: " |
379 | 383 |
+ ioe.getMessage()); |
384 |
} catch (ServiceException se) { |
|
385 |
throw new GeneralPropertyException("Could not get skins property file: " |
|
386 |
+ se.getMessage()); |
|
380 | 387 |
} |
381 | 388 |
} |
382 |
|
|
383 |
/** |
|
384 |
* Gets the backup properties directory |
|
385 |
* |
|
386 |
* TODO MCD figure out how to expand this. At least for Windows |
|
387 |
* |
|
388 |
* @return a string which holds the name of the backup directory. returns |
|
389 |
* null if directory could not be created. |
|
390 |
*/ |
|
391 |
public static String getBackupDir() { |
|
392 |
return SystemUtil.discoverExternalDir() + FileUtil.getFS() + ".metacat"; |
|
393 |
} |
|
394 | 389 |
|
395 | 390 |
/** |
396 | 391 |
* Reports whether properties are fully configured. |
Also available in: Unified diff
Implement refresh methods inherited from base class