001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.wiki;
004:
005: import java.util.*;
006:
007: public abstract class BaseWikiPage implements WikiPage {
008: protected String name;
009:
010: protected WikiPage parent;
011:
012: protected BaseWikiPage(String name, WikiPage parent) {
013: this .name = name;
014: this .parent = parent;
015: }
016:
017: public String getName() throws Exception {
018: return name;
019: }
020:
021: public PageCrawler getPageCrawler() {
022: return new PageCrawlerImpl();
023: }
024:
025: public WikiPage getParent() throws Exception {
026: return parent == null ? this : parent;
027: }
028:
029: protected abstract List getNormalChildren() throws Exception;
030:
031: public List getChildren() throws Exception {
032: List children = getNormalChildren();
033: WikiPageProperties props = getData().getProperties();
034: for (Iterator iterator = props.getSymbolicLinkNames()
035: .iterator(); iterator.hasNext();) {
036: String linkName = (String) iterator.next();
037: WikiPage page = createSymbolicPage(props, linkName);
038: if (page != null)
039: children.add(page);
040: }
041: return children;
042: }
043:
044: private WikiPage createSymbolicPage(WikiPageProperties props,
045: String linkName) throws Exception {
046: WikiPagePath path = props.getSymbolicLink(linkName);
047: PageCrawler crawler = getPageCrawler();
048: WikiPage page = crawler.getPage(crawler.getRoot(this ), path);
049: if (page != null)
050: page = new SymbolicPage(linkName, page, this );
051: return page;
052: }
053:
054: protected abstract WikiPage getNormalChildPage(String name)
055: throws Exception;
056:
057: public WikiPage getChildPage(String name) throws Exception {
058: WikiPage page = getNormalChildPage(name);
059: if (page == null)
060: page = createSymbolicPage(getData().getProperties(), name);
061: return page;
062: }
063:
064: public String toString() {
065: return this .getClass().getName() + ": " + name;
066: }
067:
068: public int compareTo(Object o) {
069: try {
070: return getName().compareTo(((WikiPage) o).getName());
071: } catch (Exception e) {
072: return 0;
073: }
074: }
075:
076: public boolean equals(Object o) {
077: if (this == o)
078: return true;
079: if (!(o instanceof WikiPage))
080: return false;
081: try {
082: PageCrawler crawler = getPageCrawler();
083: return crawler.getFullPath(this ).equals(
084: crawler.getFullPath(((WikiPage) o)));
085: } catch (Exception e) {
086: return false;
087: }
088: }
089:
090: public int hashCode() {
091: try {
092: return getPageCrawler().getFullPath(this ).hashCode();
093: } catch (Exception e) {
094: return 0;
095: }
096: }
097:
098: protected boolean isOfType(String pageType) {
099: try {
100: return getData().getProperties().is(pageType);
101: } catch (Exception e) {
102: // property doesn't exist, fall through to false result
103: }
104: return false;
105: }
106:
107: protected boolean containsWidget(String widgetTag) {
108: try {
109: return getData().getContent().indexOf("!" + widgetTag) != -1;
110: } catch (Exception ex) {
111: return false;
112: }
113: }
114:
115: public boolean isSTIQTest() {
116: return isOfType(WikiPage.STIQ_TEST);
117: }
118:
119: public boolean isSTIQTestComponent() {
120: return isOfType(WikiPage.STIQ_COMPONENT);
121: }
122:
123: public boolean isSTIQBranch() {
124: return containsWidget("STIQsuite")
125: || containsWidget("STIQtestcomponents")
126: || containsWidget("seleniumsuite");
127: }
128:
129: }
|