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: import fitnesse.wikitext.WidgetBuilder;
08:
09: public class PreformattedWidget extends ParentWidget {
10: public static final String REGEXP = "\\{\\{\\{.+?\\}\\}\\}";
11:
12: private static final Pattern pattern = Pattern.compile(
13: "\\{{3}(.+?)\\}{3}", Pattern.DOTALL);
14:
15: public PreformattedWidget(ParentWidget parent, String text)
16: throws Exception {
17: super (parent);
18: Matcher match = pattern.matcher(text);
19: if (match.find())
20: addChildWidgets(match.group(1));
21: }
22:
23: public String render() throws Exception {
24: StringBuffer html = new StringBuffer("<pre>");
25: html.append(childHtml()).append("</pre>");
26:
27: return html.toString();
28: }
29:
30: public String asWikiText() throws Exception {
31: return "{{{" + childWikiText() + "}}}";
32: }
33:
34: public WidgetBuilder getBuilder() {
35: return WidgetBuilder.literalAndVariableWidgetBuilder;
36: }
37: }
|