1 25 26 package org.snipsnap.render; 27 28 import org.radeox.api.engine.RenderEngine; 29 import org.radeox.engine.context.BaseInitialRenderContext; 30 import org.radeox.api.engine.context.InitialRenderContext; 31 import org.radeox.api.engine.context.RenderContext; 32 import org.radeox.filter.EscapeFilter; 33 import org.radeox.filter.FilterPipe; 34 import org.radeox.filter.UrlFilter; 35 import org.radeox.filter.context.BaseFilterContext; 36 import org.radeox.filter.context.FilterContext; 37 38 39 import java.io.IOException ; 40 import java.io.Writer ; 41 import java.io.Reader ; 42 import java.io.BufferedReader ; 43 44 50 51 public class PlainTextRenderEngine implements RenderEngine { 52 private InitialRenderContext initialContext; 53 protected FilterPipe fp; 54 55 public PlainTextRenderEngine() { 56 initialContext = new BaseInitialRenderContext(); 57 } 58 59 protected void init() { 60 if (null == fp) { 61 fp = new FilterPipe(initialContext); 62 fp.addFilter(new EscapeFilter()); 63 fp.addFilter(new UrlFilter()); 64 fp.init(); 65 } 66 } 67 68 public String getName() { 69 return "PlainText"; 70 } 71 72 public String render(String content, RenderContext context) { 73 init(); 74 FilterContext filterContext = new BaseFilterContext(); 75 filterContext.setRenderContext(context); 76 StringBuffer plainText = new StringBuffer ("<div id=\"code\"><pre>"); 77 plainText.append(fp.filter(content, filterContext)); 78 plainText.append("</pre></div>").toString(); 79 return plainText.toString(); 80 } 81 82 89 public String render(Reader in, RenderContext context) throws IOException { 90 StringBuffer buffer = new StringBuffer (); 91 BufferedReader inputReader = new BufferedReader (in); 92 String line; 93 while ((line = inputReader.readLine()) != null) { 94 buffer.append(line); 95 } 96 return render(buffer.toString(), context); 97 } 98 99 public void render(Writer out, String content, RenderContext context) throws IOException { 100 out.write(render(content, context)); 101 } 102 103 } 104 | Popular Tags |