views:

88

answers:

3

I'm designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There's one block of text on one of the pages which we anticipate will need to be updated occasionally (a few times a year?) by a system admin. What's the best way to allow updating of that block of text?

I don't think modifying the web service to provide the text is a viable option. It would also be nice if we didn't have to reWAR the web app in order to do the update.

+4  A: 

If using a properties file is an option, you could use Commons Configuration to load it from the classpath (so it could be outside the WAR) and use the automatic reloading feature to reload it in case of changes.

(EDIT: To answer a comment about Commons Configuration, I agree that it might not be the best piece of code of Apache but I can't say that I find this to be a nightmare:

PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());

Using properties might not be ideal but, well, for a block of HTML, it should do the trick.)

Pascal Thivent
+1 properties files are way to go. Put them in classpath or add its path to the webapp's classpath and you'll be fine.
BalusC
I was asked to introduce Commons Configurations into a project I worked with some years ago. It was a nightmare! My opinion is that that `Configurations` is not one of Apache's better pieces of code. For a handful of simple settings, I agree with BalusC that property files are a much handier option.
Carl Smotricz
That's not how I understood BalusC comment but you are free to read what you want to read. Regarding the complexity, I simply do not agree.
Pascal Thivent
It sounds like having a property file outside of the war file is the best solution for most types of settings, but I'm not too sure about using it to store multiline text. Having a 30 line, possibly html formatted, text in a property file seems to be pretty awkward. Carl's answer looks promising, but I'd like to avoid creating a custom solution for this project. I think I'll start out with loading an xml file with Commons Configuration and see how that goes.
jthg
Loading XML would have been my next suggestion if using a properties file wasn't possible (but honestly, I wouldn't mind storing an HTML block that will change only a few times per year, especially if the changes are done by a tech guy, in a properties file, even if hugly).
Pascal Thivent
A: 

Having re-read your question:

If the text is the only property that needs changing, then a property file is not the right solution. And we're in a servlet environment, and you change it but rarely.

I think the text should be read (via the usual file I/O methods) from a plaintext file into the ServletContext by a lifecycle listener. If you want to change the text, take an editor to it, then quickly restart just that servlet, and you're done. The app can refer to the (single) in-memory copy that your listener puts into the context, it runs quickly and it's easy to change.

Carl Smotricz
A: 

You can keep it in propeties file format and use java.util.ResourceBundle to get the values from it. This way you can use ResourceBundle#clearCache() or provide a custom ResourceBundle#Control to control the cache.

BalusC