1 25 26 package org.snipsnap.render; 27 28 import org.radeox.api.engine.ImageRenderEngine; 29 import org.radeox.api.engine.IncludeRenderEngine; 30 import org.radeox.api.engine.WikiRenderEngine; 31 import org.radeox.api.engine.context.RenderContext; 32 import org.radeox.engine.BaseRenderEngine; 33 import org.radeox.filter.context.FilterContext; 34 import org.radeox.util.Encoder; 35 import org.snipsnap.app.Application; 36 import org.snipsnap.config.Configuration; 37 import org.snipsnap.render.context.SnipRenderContext; 38 import org.snipsnap.render.filter.context.SnipFilterContext; 39 import org.snipsnap.serialization.StringBufferWriter; 40 import org.snipsnap.snip.Snip; 41 import org.snipsnap.snip.SnipLink; 42 import org.snipsnap.snip.SnipSpaceFactory; 43 import org.snipsnap.user.AuthenticationService; 44 45 import java.io.IOException ; 46 import java.io.Writer ; 47 48 55 56 public class SnipRenderEngine extends BaseRenderEngine 57 implements WikiRenderEngine, IncludeRenderEngine, ImageRenderEngine { 58 59 private AuthenticationService authService; 61 62 public SnipRenderEngine(AuthenticationService authService) { 63 this.authService = authService; 64 } 68 69 public String getName() { 70 return "snipsnap"; 71 } 72 73 public boolean exists(String name) { 74 return SnipSpaceFactory.getInstance().exists(name); 75 } 76 77 public boolean showCreate() { 78 return authService.isAuthenticated(Application.get().getUser()); 79 } 80 81 public void appendLink(StringBuffer buffer, String name, String view, String anchor) { 82 SnipLink.appendLink(buffer, name, view, anchor); 83 } 84 85 public void appendLink(StringBuffer buffer, String name, String view) { 86 SnipLink.appendLink(buffer, name, view); 87 } 88 89 public void appendCreateLink(StringBuffer buffer, String name, String view) { 90 Configuration config = Application.get().getConfiguration(); 91 String encodedSpace = config.getEncodedSpace(); 92 93 if (name.indexOf(encodedSpace.charAt(0)) == -1) { 94 SnipLink.appendCreateLink(buffer, name); 95 } else { 96 buffer.append("[<span class=\"error\">illegal '" + encodedSpace + "' in " + Encoder.escape(name) + "</span>]"); 97 } 98 } 99 100 public String include(String name) { 101 Snip includeSnip = SnipSpaceFactory.getInstance().load(name); 102 if (null != includeSnip) { 103 return includeSnip.getContent(); 104 } else { 105 return null; 106 } 107 } 108 109 public String getExternalImageLink() { 110 Writer writer = new StringBufferWriter(); 111 try { 112 SnipLink.appendImage(writer, "Icon-Extlink", ">>"); 113 } catch (IOException e) { 114 } 116 return writer.toString(); 117 } 118 119 public String render(String content, RenderContext context) { 120 init(); 121 FilterContext filterContext = new SnipFilterContext(((SnipRenderContext) context).getSnip()); 122 filterContext.setRenderContext(context); 123 context.setRenderEngine(this); 124 return fp.filter(content, filterContext); 125 } 126 } 127 | Popular Tags |