01: package fitnesse.html;
02:
03: import fitnesse.FitNesseContext;
04: import fitnesse.Responder;
05: import fitnesse.http.MockRequest;
06: import fitnesse.http.SimpleResponse;
07: import fitnesse.responders.WikiPageResponder;
08: import fitnesse.runner.SuiteExporter;
09: import fitnesse.util.FileUtil;
10: import fitnesse.wiki.PathParser;
11: import fitnesse.wiki.WikiPagePath;
12:
13: public class StiqTest {
14:
15: private String testHtml;
16: private String TITLE_BEGIN = "<title>";
17: private String TITLE_END = "</title>";
18:
19: public StiqTest(FitNesseContext context, WikiPagePath pagePath)
20: throws Exception {
21: MockRequest request = new MockRequest();
22: request.setResource(PathParser.render(pagePath));
23: Responder responder = new WikiPageResponder();
24: SimpleResponse response = (SimpleResponse) responder
25: .makeResponse(context, request);
26: testHtml = response.getContent();
27: prepareHtmlForExport();
28: }
29:
30: public void writeHtml(String outputDir) throws Exception {
31: String testName = getWikiPageName();
32: String filePath = outputDir + "/" + testName
33: + SuiteExporter.FILE_EXTENSION;
34:
35: FileUtil.createFile2(filePath, testHtml);
36: }
37:
38: public String getWikiPageName() {
39: return testHtml.substring(testHtml.indexOf(TITLE_BEGIN)
40: + TITLE_BEGIN.length(), testHtml.indexOf(TITLE_END));
41: }
42:
43: public String getHtml() {
44: return this .testHtml;
45: }
46:
47: public void cleanHtml() {
48: String tempHtml = testHtml;
49: String docTypeRegex = "<!DOCTYPE.*\r\n";
50: String linkRegex = "<link rel=.*\r\n";
51: String scriptRegex = "<script src=.*\r\n";
52: String actionsRegex = "<div class=\"actions\"[\\s|\\S]*class=\"toolbarImage\"/></a></div>";
53:
54: tempHtml = tempHtml.replaceAll(docTypeRegex, "");
55: tempHtml = tempHtml.replaceAll(linkRegex, "");
56: tempHtml = tempHtml.replaceAll(scriptRegex, "");
57: tempHtml = tempHtml.replaceAll(actionsRegex, "");
58:
59: testHtml = tempHtml;
60: }
61:
62: public void prepareHtmlForExport() {
63: cleanHtml();
64: }
65:
66: }
|