01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.updates;
04:
05: import fitnesse.wiki.*;
06: import java.io.*;
07: import java.util.Properties;
08:
09: public class PropertiesToXmlUpdate extends PageTraversingUpdate {
10: public static final String old_propertiesFilename = "/properties";
11:
12: public PropertiesToXmlUpdate(Updater updater) {
13: super (updater);
14: }
15:
16: public String getMessage() {
17: return "Converting properties files to XML";
18: }
19:
20: public String getName() {
21: return "PropertiesToXmlUpdate";
22: }
23:
24: public void processPage(WikiPage page) throws Exception {
25: FileSystemPage fsPage = (FileSystemPage) page;
26: String path = fsPage.getFileSystemPath();
27:
28: File oldPropsFile = new File(path + old_propertiesFilename);
29: Properties oldProps = loadOldProperties(oldPropsFile);
30: saveNewProperties(path, oldProps);
31: oldPropsFile.delete();
32: }
33:
34: private void saveNewProperties(String path, Properties oldProps)
35: throws Exception {
36: File newPropsFile = new File(path
37: + FileSystemPage.propertiesFilename);
38: WikiPageProperties newProps = new WikiPageProperties(oldProps);
39: FileOutputStream os = new FileOutputStream(newPropsFile);
40: newProps.save(os);
41: os.close();
42: }
43:
44: private Properties loadOldProperties(File oldPropsFile)
45: throws IOException {
46: Properties oldProps = new Properties();
47: if (oldPropsFile.exists()) {
48: FileInputStream is = new FileInputStream(oldPropsFile);
49: oldProps.load(is);
50: is.close();
51: }
52: return oldProps;
53: }
54: }
|