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.html.HtmlUtil;
08:
09: public class VariableDefinitionWidget extends ParentWidget {
10: public static final String REGEXP = "^!define \\w+ (?:(?:\\{[^}]*\\})|(?:\\([^)]*\\)))";
11:
12: private static final Pattern pattern = Pattern.compile(
13: "^!define (\\w+) ([\\{\\(])(.*)[\\}\\)]", Pattern.DOTALL
14: + Pattern.MULTILINE);
15:
16: public String name;
17:
18: public String value;
19:
20: public static String defineLabel = "";
21:
22: public VariableDefinitionWidget(ParentWidget parent, String text)
23: throws Exception {
24: super (parent);
25: Matcher match = pattern.matcher(text);
26: if (match.find()) {
27: name = match.group(1);
28: value = match.group(3);
29: }
30: }
31:
32: public String render() throws Exception {
33: this .parent.addVariable(name, value);
34: return HtmlUtil.metaText(defineLabel + name + "=" + value);
35: }
36:
37: public String asWikiText() throws Exception {
38: String text = "!define " + name + " ";
39: if (value.indexOf("{") == -1)
40: text += "{" + value + "}";
41: else
42: text += "(" + value + ")";
43: return text;
44: }
45: }
|