01: /**
02: * TestRewriterOffline.java
03: * This class provides a very basic test framework for the Rewriter Component.
04: *
05: * @author Nawab Ali
06: * @version 1.0
07: */package com.sun.portal.rewriter.test.util;
08:
09: import com.sun.portal.rewriter.AbsoluteTranslator;
10: import com.sun.portal.rewriter.Rewriter;
11: import com.sun.portal.rewriter.RewriterModule;
12: import com.sun.portal.rewriter.RewriterPool;
13: import com.sun.portal.rewriter.engines.LanguageConstants;
14: import com.sun.portal.rewriter.rom.RuleSet;
15: import com.sun.portal.rewriter.rom.RuleSetManager;
16: import com.sun.portal.rewriter.util.Resource;
17: import com.sun.portal.rewriter.util.uri.PageSpec;
18:
19: import java.io.FileReader;
20:
21: public class TestRewriterOffline {
22: public static void main(String argv[]) throws Exception {
23: if (argv.length < 3) {
24: System.out
25: .println("Usage: java com.sun.portal.rewriter.test.util.TestRewriterOffline baseURL htmlFile rulesFile");
26: System.exit(1);
27: }
28: String baseURL = argv[0];
29: String htmlFile = argv[1];
30: String rulesFile = argv[2];
31:
32: RewriterModule.initFile();
33:
34: /* We create a RuleSet object. The I/P is the RuleSet.xml file */
35: RuleSet lRuleSet = RuleSetManager.create(new FileReader(
36: rulesFile));
37: /* Create a Rewriter object */
38: Rewriter uRewriter = RewriterPool.create(lRuleSet,
39: LanguageConstants.MARKUP_MIME);
40: PageSpec uri = new PageSpec(baseURL, "");
41: AbsoluteTranslator defTrans = new AbsoluteTranslator(uri);
42: /* Print the rewritten content to the standard O/P */
43: String content = Resource.read(htmlFile);
44: System.out.println(uRewriter.rewrite(content, defTrans));
45: }//main()
46: }//class TestRewriterOffline
|