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.widgets;
04:
05: import java.util.regex.Matcher;
06: import java.util.regex.Pattern;
07:
08: public class XRefWidget extends ParentWidget implements
09: WidgetWithTextArgument {
10: public static final String REGEXP = "^!xref "
11: + WikiWordWidget.REGEXP;
12:
13: public static final String XREF_TARGET_WINDOW = "stiqWindow";
14:
15: private static final Pattern pattern = Pattern
16: .compile("^!xref (.*)");
17:
18: private static final String WINDOW_OPTIONS = "menubar,resizable,scrollbars,status,titlebar,toolbar";
19:
20: private String pageName;
21:
22: public XRefWidget(ParentWidget parent, String text)
23: throws Exception {
24: super (parent);
25: Matcher match = pattern.matcher(text);
26: if (match.find()) {
27: pageName = match.group(1);
28: addChildWidgets(pageName);
29: }
30: }
31:
32: public String render() throws Exception {
33: String html = childHtml();
34: String openScriptBegin = "<a href=\"javascript:var wnd=window.open('";
35: String openScriptEnd = "\', \'" + XREF_TARGET_WINDOW + "\', \'"
36: + WINDOW_OPTIONS + "\');wnd.focus();\">";
37: html = html.replace("<a href=\"", openScriptBegin);
38: html = html.replace("\">", openScriptEnd);
39: return "<span class=\"xref\">" + html + "</span>";
40: }
41:
42: public String asWikiText() throws Exception {
43: return "!xref " + pageName;
44: }
45:
46: public String getText() {
47: return pageName;
48: }
49: }
|