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.components;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.wikitext.widgets.*;
07: import fitnesse.wikitext.*;
08:
09: public abstract class ReferenceRenamer implements
10: FitNesseTraversalListener {
11: protected WikiPage root;
12:
13: public ReferenceRenamer(WikiPage root) {
14: this .root = root;
15: }
16:
17: protected void renameReferences() throws Exception {
18: root.getPageCrawler().traverse(root, this );
19: }
20:
21: public void processPage(WikiPage currentPage) throws Exception {
22: PageData data = currentPage.getData();
23: String content = data.getContent();
24: WidgetRoot widgetRoot = new WidgetRoot(content, currentPage,
25: referenceModifyingWidgetBuilder);
26: widgetRoot.acceptVisitor(getVisitor());
27:
28: String newContent = widgetRoot.asWikiText();
29: boolean pageHasChanged = !newContent.equals(content);
30: if (pageHasChanged) {
31: data.setContent(newContent);
32: currentPage.commit(data);
33: }
34: }
35:
36: protected abstract WidgetVisitor getVisitor();
37:
38: public static WidgetBuilder referenceModifyingWidgetBuilder = new WidgetBuilder(
39: new Class[] { WikiWordWidget.class, LiteralWidget.class,
40: CommentWidget.class, PreformattedWidget.class,
41: LinkWidget.class, ImageWidget.class,
42: AliasLinkWidget.class, ClasspathWidget.class,
43: FixtureWidget.class, });
44: }
|