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.*;
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();
39:
40: for (Iterator iterator = oldProps.keySet().iterator(); iterator
41: .hasNext();) {
42: String key = (String) iterator.next();
43: String value = (String) oldProps.get(key);
44: if (!"false".equals(value))
45: newProps.set(key, value);
46: }
47:
48: FileOutputStream os = new FileOutputStream(newPropsFile);
49: newProps.save(os);
50: os.close();
51: }
52:
53: private Properties loadOldProperties(File oldPropsFile)
54: throws IOException {
55: Properties oldProps = new Properties();
56: if (oldPropsFile.exists()) {
57: FileInputStream is = new FileInputStream(oldPropsFile);
58: oldProps.load(is);
59: is.close();
60: }
61: return oldProps;
62: }
63: }
|