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: import fitnesse.wiki.WikiPage;
09:
10: public class EmbedWidget extends ParentWidget {
11: public static final String REGEXP = "^!embed(?: +-seamless)? .*"
12: + LineBreakWidget.REGEXP + "?";
13:
14: static final Pattern pattern = Pattern
15: .compile("^!embed *(-seamless)? (.*)");
16:
17: private static final String SRC_TOKEN = "URL_Goes_Here";
18:
19: private static final String IFRAME_ID = "embeddedPage";
20:
21: protected static String srcUrl;
22:
23: protected WikiPage includingPage;
24:
25: protected WikiPage parentPage;
26:
27: public EmbedWidget(ParentWidget parent, String text)
28: throws Exception {
29: super (parent);
30: Matcher matcher = pattern.matcher(text);
31: if (matcher.find()) {
32: srcUrl = parseSrcUrl(matcher);
33: includingPage = parent.getWikiPage();
34: parentPage = includingPage.getParent();
35: handleDisplayForOption(parseOption(matcher));
36: }
37: }
38:
39: private String parseOption(Matcher match) {
40: return match.group(1);
41: }
42:
43: private String parseSrcUrl(Matcher match) {
44: return match.group(2);
45: }
46:
47: private void handleDisplayForOption(String option) throws Exception {
48: String widgetText = "<iframe class=embeddedIFrame id="
49: + IFRAME_ID + " src=" + SRC_TOKEN + "/>";
50: if ("-seamless".equals(option)) {
51: addChildWidgets(widgetText + "\n");
52: } else {
53: new CollapsableWidget(this , srcUrl, widgetText,
54: "collapse_rim");
55: }
56: }
57:
58: public String render() throws Exception {
59:
60: return childHtml().replace(SRC_TOKEN, "\"" + srcUrl + "\"");
61: }
62:
63: public boolean doEscaping() {
64: return false;
65: }
66:
67: protected WikiPage getParentPage() throws Exception {
68: return parent.getWikiPage().getParent();
69: }
70: }
|