1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.cms.core.wiki.engine;
17
18 import java.io.StringReader;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.seasar.tuigwaa.cms.core.CmsConstants;
23 import org.seasar.tuigwaa.cms.core.Page;
24
25
26 public class WikiParserWrapper {
27
28 private org.seasar.tuigwaa.cms.core.Page page_;
29 private boolean debug_ = false;
30
31 private static final String LINESEP = CmsConstants.LINEBREAK_CODE;
32 private Log log_ = LogFactory.getLog(this.getClass());
33 private WikiParser parser_;
34
35 public WikiParserWrapper(Page page){
36 this.page_ = page;
37 String processed = preprocess(page_.getContent().toString());
38 this.parser_ = new WikiParser(new StringReader(processed));
39 }
40
41 public SimpleNode getTree(){
42
43 long start = System.currentTimeMillis();
44 try{
45 if(debug_){
46 parser_.enable_tracing();
47 }else{
48 parser_.disable_tracing();
49 }
50 parser_.GenerateTree();
51 }catch(ParseException pe){
52 log_.error(pe.getMessage());
53 }
54 long end = System.currentTimeMillis();
55 long elapsed = end - start;
56 if(debug_)
57 log_.info("parse time: " + elapsed + "[ms]");
58 return (SimpleNode) parser_.jjtree.rootNode();
59 }
60
61 public int getNumOfParseError(){
62 return parser_.getNParseErrors();
63 }
64
65 public int getNumOfLexicalError(){
66 return parser_.getNLexicalErrors();
67 }
68
69 private String preprocess(String data){
70 StringBuffer buf = new StringBuffer(LINESEP);
71 buf.append(data);
72 buf.append(LINESEP);
73 return buf.toString();
74 }
75
76 public void setDebug(boolean debug){
77 this.debug_ = debug;
78 }
79
80
81 }