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.fixtures;
04:
05: import fit.ColumnFixture;
06: import fitnesse.wiki.*;
07: import java.util.StringTokenizer;
08:
09: public class PageCreator extends ColumnFixture {
10: public String pageName;
11:
12: public String pageContents;
13:
14: public String pageAttributes = "";
15:
16: public boolean valid() throws Exception {
17: try {
18: WikiPage root = FitnesseFixtureContext.root;
19: WikiPagePath pagePath = PathParser.parse(pageName);
20: WikiPage thePage = root.getPageCrawler().addPage(root,
21: pagePath, pageContents);
22: PageData data = thePage.getData();
23: setAttributes(data);
24: thePage.commit(data);
25: pageAttributes = "";
26: } catch (Exception e) {
27: e.printStackTrace();
28: }
29: return true;
30: }
31:
32: private void setAttributes(PageData data) throws Exception {
33: StringTokenizer tokenizer = new StringTokenizer(pageAttributes,
34: ",");
35: while (tokenizer.hasMoreTokens()) {
36: String nameValuePair = tokenizer.nextToken();
37: int equals = nameValuePair.indexOf("=");
38: if (equals < 0)
39: throw new Exception(
40: "Attribute must have form name=value");
41: String name = nameValuePair.substring(0, equals);
42: String value = nameValuePair.substring(equals + 1);
43: data.setAttribute(name, value);
44: }
45: }
46: }
|