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.wikitext;
04:
05: import fitnesse.html.HtmlElement;
06: import fitnesse.html.HtmlTag;
07: import fitnesse.html.RawHtml;
08: import fitnesse.util.PropertiesUtil;
09: import fitnesse.wiki.PathParser;
10: import fitnesse.wiki.ProxyPage;
11: import fitnesse.wiki.WikiPage;
12: import fitnesse.wiki.WikiPagePath;
13: import fitnesse.wikitext.widgets.ParentWidget;
14:
15: public abstract class WikiWidget {
16: protected ParentWidget parent = null;
17:
18: // We use these for !components as well as !suite, so its in the superclass and available to both
19: public static final String SHOW_PARENT_IN_RECURSIVE_SUITE_LINKS_PROPERTY = "ShowParentInRecursiveSuiteLinks";
20:
21: public static final String SHOW_PARENT_IN_RECURSIVE_SUITE_LINKS_DEFAULT = "true";
22:
23: public static final String PARENT_CHILD_LINK_SEPARATOR_DEFAULT = ". ";
24:
25: public static final String PARENT_CHILD_LINK_SEPARATOR_PROPERTY = "ParentChildLinkSeparator";
26:
27: protected WikiWidget(ParentWidget parent) {
28: this .parent = parent;
29: addToParent();
30: }
31:
32: protected void addToParent() {
33: if (this .parent != null) {
34: this .parent.addChild(this );
35: }
36: }
37:
38: // TODO-DaC what's a better name for this?
39: public abstract String render() throws Exception;
40:
41: public void acceptVisitor(WidgetVisitor visitor) throws Exception {
42: visitor.visit(this );
43: }
44:
45: public WikiPage getWikiPage() {
46: return this .parent.getWikiPage();
47: }
48:
49: public String asWikiText() throws Exception {
50: return getClass().toString() + ".asWikiText()";
51: }
52:
53: protected String getHref(WikiPage wikiPage) throws Exception {
54: String href = null;
55: WikiPagePath wikiPagePath = wikiPage.getPageCrawler()
56: .getFullPath(wikiPage);
57: href = PathParser.render(wikiPagePath);
58: return href;
59: }
60:
61: protected HtmlElement getLinkText(WikiPage wikiPage)
62: throws Exception {
63: if (wikiPage instanceof ProxyPage) {
64: return new HtmlTag("i", wikiPage.getName());
65: } else {
66: return new RawHtml(wikiPage.getName());
67: }
68: }
69:
70: public String getShowParentInSuiteLink() {
71: return PropertiesUtil.getProperty(
72: SHOW_PARENT_IN_RECURSIVE_SUITE_LINKS_PROPERTY,
73: SHOW_PARENT_IN_RECURSIVE_SUITE_LINKS_DEFAULT).trim();
74: }
75:
76: public String getParentChildLinkSeparator() {
77: String separator = PropertiesUtil.getProperty(
78: PARENT_CHILD_LINK_SEPARATOR_PROPERTY,
79: PARENT_CHILD_LINK_SEPARATOR_DEFAULT);
80:
81: // Remove quotes if the property value has used them to include space
82: separator = separator.replace("\"", "");
83: separator = separator.replace("'", "");
84: return separator;
85: }
86: }
|