01: package fitnesse.updates;
02:
03: import org.w3c.dom.*;
04: import fitnesse.wiki.*;
05: import fitnesse.util.*;
06:
07: public class SymLinkPropertyFormatUpdate extends PageTraversingUpdate {
08: public SymLinkPropertyFormatUpdate(Updater updater) {
09: super (updater);
10: }
11:
12: public void processPage(WikiPage currentPage) throws Exception {
13: try {
14: FileSystemPage page = (FileSystemPage) currentPage;
15: String propertiesContent = FileUtil.getFileContent(page
16: .getFileSystemPath()
17: + FileSystemPage.propertiesFilename);
18: if (propertiesContent.contains("<symbolicLink>"))
19: fixPropertiesFile(page, propertiesContent);
20: } catch (Exception e) {
21: // continue to next page
22: }
23: }
24:
25: private void fixPropertiesFile(FileSystemPage page,
26: String propertiesContent) throws Exception {
27: PageData data = page.getData();
28: WikiPageProperty symLinkProperty = getSymbolicLinkProperty(data);
29: data.getProperties().remove("symbolicLink");
30:
31: Document document = XmlUtil.newDocument(propertiesContent);
32: NodeList oldLinkElements = document
33: .getElementsByTagName("symbolicLink");
34: for (int i = 0; i < oldLinkElements.getLength(); i++) {
35: Element oldSymLink = (Element) oldLinkElements.item(i);
36: String name = XmlUtil.getLocalTextValue(oldSymLink, "name");
37: String path = XmlUtil.getLocalTextValue(oldSymLink, "path");
38: symLinkProperty.set(name, path);
39: }
40:
41: page.commit(data);
42: }
43:
44: private WikiPageProperty getSymbolicLinkProperty(PageData data)
45: throws Exception {
46: WikiPageProperties properties = data.getProperties();
47: WikiPageProperty symLinkProperty = properties
48: .getProperty(SymbolicPage.PROPERTY_NAME);
49: if (symLinkProperty == null)
50: symLinkProperty = properties
51: .set(SymbolicPage.PROPERTY_NAME);
52: return symLinkProperty;
53: }
54:
55: public String getName() {
56: return "SymLinkPropertyFormatUpdate";
57: }
58:
59: public String getMessage() {
60: return "Updating the format of SybolicLink properties";
61: }
62: }
|