Revision 8074
Added by Jing Tao over 11 years ago
src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java | ||
---|---|---|
27 | 27 |
package edu.ucsb.nceas.metacat.admin; |
28 | 28 |
|
29 | 29 |
import java.io.File; |
30 |
import java.io.StringReader; |
|
30 | 31 |
import java.util.Vector; |
31 | 32 |
|
32 | 33 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
49 | 50 |
import edu.ucsb.nceas.utilities.FileUtil; |
50 | 51 |
import edu.ucsb.nceas.utilities.GeneralPropertyException; |
51 | 52 |
import edu.ucsb.nceas.utilities.PropertiesMetaData; |
53 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
52 | 54 |
import edu.ucsb.nceas.utilities.SortedProperties; |
53 | 55 |
import edu.ucsb.nceas.utilities.UtilException; |
54 | 56 |
|
... | ... | |
57 | 59 |
* processing of the configuration values. |
58 | 60 |
*/ |
59 | 61 |
public class PropertiesAdmin extends MetacatAdmin { |
60 |
|
|
62 |
private static String BACKSLASH = "/"; |
|
63 |
private static String DEFAULTMETACATCONTEXT = "knb"; |
|
64 |
private static String METACATPROPERTYAPPENDIX = "/WEB-INF/metacat.properties"; |
|
61 | 65 |
private static PropertiesAdmin propertiesAdmin = null; |
62 | 66 |
private static Logger logMetacat = Logger.getLogger(PropertiesAdmin.class); |
63 | 67 |
|
... | ... | |
288 | 292 |
validationErrors.add(errorString); |
289 | 293 |
} |
290 | 294 |
} |
295 |
//modify some params of the index context |
|
296 |
modifyIndexContextParams(indexContext); |
|
291 | 297 |
|
292 | 298 |
// write the backup properties to a location outside the |
293 | 299 |
// application directories so they will be available after |
... | ... | |
339 | 345 |
} |
340 | 346 |
} |
341 | 347 |
} |
348 |
|
|
349 |
/* |
|
350 |
* In the web.xml of the Metacat-index context, there is a parameter: |
|
351 |
* <context-param> |
|
352 |
* <param-name>metacat.properties.path</param-name> |
|
353 |
* <param-value>/knb/WEB-INF/metacat.properties</param-value> |
|
354 |
* <description>The metacat.properties file for sibling metacat deployment. Note that the context can change</description> |
|
355 |
* </context-param> |
|
356 |
* It points to the default metacat context - knb. If we rename the context, we need to change the value of there. |
|
357 |
*/ |
|
358 |
private void modifyIndexContextParams(String indexContext) { |
|
359 |
if(indexContext != null) { |
|
360 |
try { |
|
361 |
String metacatContext = PropertyService.getProperty("application.context"); |
|
362 |
//System.out.println("the metacat context is ========================="+metacatContext); |
|
363 |
if(metacatContext != null && !metacatContext.equals(DEFAULTMETACATCONTEXT)) { |
|
364 |
String indexConfigFile = |
|
365 |
PropertyService.getProperty("application.deployDir") |
|
366 |
+ FileUtil.getFS() |
|
367 |
+ indexContext |
|
368 |
+ FileUtil.getFS() |
|
369 |
+ "WEB-INF" |
|
370 |
+ FileUtil.getFS() |
|
371 |
+ "web.xml"; |
|
372 |
//System.out.println("============================== the web.xml file is "+indexConfigFile); |
|
373 |
String configContents = FileUtil.readFileToString(indexConfigFile, "UTF-8"); |
|
374 |
//System.out.println("============================== the content of web.xml file is "+configContents); |
|
375 |
configContents = configContents.replace(BACKSLASH+DEFAULTMETACATCONTEXT+METACATPROPERTYAPPENDIX, BACKSLASH+metacatContext+METACATPROPERTYAPPENDIX); |
|
376 |
FileUtil.writeFile(indexConfigFile, new StringReader(configContents), "UTF-8"); |
|
377 |
} |
|
378 |
|
|
379 |
} catch (Exception e) { |
|
380 |
String errorMessage = "PropertiesAdmin.configureProperties - Problem getting/setting the \"metacat.properties.path\" in the web.xml of the index context : " + e.getMessage(); |
|
381 |
logMetacat.error(errorMessage); |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
342 | 385 |
|
343 | 386 |
/** |
344 | 387 |
* Validate the most important configuration options submitted by the user. |
Also available in: Unified diff
Add code to modify the web.xml in metacat-index context if the metacat's name is not knb.