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.WikiPage;
06: import fitnesse.wikitext.widgets.*;
07: import fitnesse.wikitext.*;
08: import java.util.*;
09:
10: public class WhereUsed implements FitNesseTraversalListener,
11: SearchObserver, WidgetVisitor {
12: private WikiPage root;
13:
14: private WikiPage subjectPage;
15:
16: private SearchObserver observer;
17:
18: private WikiPage currentPage;
19:
20: private List hits = new ArrayList();
21:
22: public WhereUsed(WikiPage root) {
23: this .root = root;
24: }
25:
26: public void hit(WikiPage referencingPage) throws Exception {
27: }
28:
29: public void visit(WikiWidget widget) throws Exception {
30: }
31:
32: public void visit(WikiWordWidget widget) throws Exception {
33: if (hits.contains(currentPage))
34: return;
35: WikiPage referencedPage = widget.getReferencedPage();
36: if (referencedPage != null
37: && referencedPage.equals(subjectPage)) {
38: hits.add(currentPage);
39: observer.hit(currentPage);
40: }
41: }
42:
43: public void visit(AliasLinkWidget widget) throws Exception {
44: }
45:
46: public void searchForReferencingPages(WikiPage subjectPage,
47: SearchObserver observer) throws Exception {
48: this .observer = observer;
49: this .subjectPage = subjectPage;
50: root.getPageCrawler().traverse(root, this );
51: }
52:
53: public List findReferencingPages(WikiPage subjectPage)
54: throws Exception {
55: hits.clear();
56: searchForReferencingPages(subjectPage, this );
57: return hits;
58: }
59:
60: public void processPage(WikiPage currentPage) throws Exception {
61: this .currentPage = currentPage;
62: String content = currentPage.getData().getContent();
63: WidgetBuilder referenceWidgetBuilder = new WidgetBuilder(
64: new Class[] { PreProcessorLiteralWidget.class,
65: WikiWordWidget.class, PreformattedWidget.class });
66: WidgetRoot widgetRoot = new WidgetRoot(content, currentPage,
67: referenceWidgetBuilder);
68: widgetRoot.acceptVisitor(this );
69: }
70:
71: public String getSearchPattern() throws Exception {
72: return subjectPage.getName();
73: }
74: }
|