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.wiki;
04:
05: import fitnesse.responders.ErrorResponder;
06:
07: public class VirtualCouplingExtension implements Extension {
08: private static final long serialVersionUID = 1L;
09:
10: public static final String NAME = "VirtualCoupling";
11:
12: private WikiPage hostPage;
13:
14: protected VirtualCouplingPage virtualCoupling;
15:
16: public String getName() {
17: return NAME;
18: }
19:
20: public VirtualCouplingExtension(WikiPage page) throws Exception {
21: hostPage = page;
22: resetVirtualCoupling();
23: }
24:
25: public void setVirtualCoupling(VirtualCouplingPage coupling) {
26: virtualCoupling = coupling;
27: }
28:
29: public void resetVirtualCoupling() throws Exception {
30: virtualCoupling = new NullVirtualCouplingPage(hostPage);
31: }
32:
33: public WikiPage getVirtualCoupling() throws Exception {
34: detectAndLoadVirtualChildren();
35: return virtualCoupling;
36: }
37:
38: protected void detectAndLoadVirtualChildren() throws Exception {
39: PageData data = hostPage.getData();
40: if (data
41: .hasAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE))
42: loadVirtualChildren(data
43: .getAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE));
44: }
45:
46: public void loadVirtualChildren(String url) throws Exception {
47: try {
48: ProxyPage proxy = ProxyPage.retrievePage(url);
49: virtualCoupling = new VirtualCouplingPage(hostPage, proxy);
50: } catch (Exception e) {
51: WikiPage page = hostPage
52: .getChildPage("VirtualWikiNetworkError");
53: if (page == null)
54: page = hostPage.addChildPage("VirtualWikiNetworkError");
55: PageData data = page.getData();
56: data.setContent("{{{"
57: + ErrorResponder.makeExceptionString(e) + "}}}");
58: page.commit(data);
59: }
60: }
61: }
|