1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.cms.core.wiki;
17
18 import org.seasar.tuigwaa.cms.core.CmsConstants;
19 import org.seasar.tuigwaa.cms.core.CmsEngine;
20 import org.seasar.tuigwaa.cms.core.CmsRequest;
21 import org.seasar.tuigwaa.cms.core.CmsResponse;
22 import org.seasar.tuigwaa.cms.core.Page;
23 import org.seasar.tuigwaa.cms.core.wiki.base.CacheManager;
24 import org.seasar.tuigwaa.cms.core.wiki.base.HTMLWikiVisitor;
25 import org.seasar.tuigwaa.cms.core.wiki.base.PDFWikiVisitor;
26 import org.seasar.tuigwaa.cms.core.wiki.base.TextWikiVisitor;
27 import org.seasar.tuigwaa.cms.core.wiki.base.WikiConfiguration;
28 import org.seasar.tuigwaa.cms.core.wiki.engine.Node;
29 import org.seasar.tuigwaa.cms.core.wiki.engine.SimpleNode;
30 import org.seasar.tuigwaa.cms.core.wiki.engine.WikiParserVisitor;
31 import org.seasar.tuigwaa.cms.core.wiki.engine.WikiParserWrapper;
32
33
34 public class WikiEngine implements CmsEngine{
35
36
37
38 private WikiParserVisitor visitor_;
39
40 private CacheManager mgr_ = CacheManager.getInstance();
41
42 private WikiConfiguration config;
43
44 public WikiEngine(){
45 }
46
47 public void setConfiguration(WikiConfiguration cfg) {
48 this.config = cfg;
49 }
50
51 public void service(CmsRequest request, CmsResponse response){
52 Node rootnode = getRootNode(request,response);
53 if(config.isDebug()) ((SimpleNode) rootnode).dump(".");
54
55
56 if(request.getType() == CmsConstants.OUTPUTTYPE_HTML){
57 visitor_ = new HTMLWikiVisitor(request,response,config);
58 response.setString((String)rootnode.jjtAccept(visitor_,null));
59 }else if(request.getType() == CmsConstants.OUTPUTTYPE_PDF || request.getType() == CmsConstants.OUTPUTTYPE_RTF){
60 visitor_ = new PDFWikiVisitor(request,response,config);
61 response.setBytes((byte[])rootnode.jjtAccept(visitor_,null));
62 }else if(request.getType() == CmsConstants.OUTPUTTYPE_TEXT){
63 visitor_ = new TextWikiVisitor(request,response,config);
64 response.setString((String)rootnode.jjtAccept(visitor_,null));
65 }
66 }
67
68 private Node getRootNode(CmsRequest request, CmsResponse response){
69 Node node;
70 Page page = request.getPage();
71
72 if((node = mgr_.get(page)) == null){
73 WikiParserWrapper parser = new WikiParserWrapper(page);
74 parser.setDebug(config.isDebug());
75
76 response.setCached(false);
77 node = parser.getTree();
78
79 response.setNParseError(parser.getNumOfParseError());
80 response.setNLexicalError(parser.getNumOfLexicalError());
81 if(mgr_.isCachable(page,node))
82 mgr_.cache(page,node);
83 }
84
85 request.setRootNode(node);
86 return node;
87 }
88 }