1 25 26 package org.snipsnap.render.macro; 27 28 import org.radeox.util.Encoder; 29 import org.radeox.util.i18n.ResourceManager; 30 import org.snipsnap.net.RenderServlet; 31 import org.snipsnap.render.macro.parameter.SnipMacroParameter; 32 import org.snipsnap.snip.Snip; 33 import org.snipsnap.snip.SnipLink; 34 35 import java.io.IOException ; 36 import java.io.Writer ; 37 38 45 46 public class GraphMacro extends SnipMacro { 47 public GraphMacro() { 48 } 49 50 public String getName() { 51 return "graph"; 52 } 53 54 public String getDescription() { 55 return ResourceManager.getString("i18n.messages", "macro.graph.description"); 56 } 57 58 public String [] getParamDescription() { 59 return ResourceManager.getString("i18n.messages", "macro.graph.params").split(";"); 60 } 61 62 public void execute(Writer writer, SnipMacroParameter params) 63 throws IllegalArgumentException , IOException { 64 Snip snip = params.getSnipRenderContext().getSnip(); 65 String name = snip.getName(); 66 String handler = params.get("handler", 0); 67 String size = params.get("size", 1); 68 String imageMap = params.get("ismap", 2); 69 70 writer.write("<img class=\"graph-image\" "); 71 if (null != size && size.matches("[0-9]+%")) { 72 writer.write("width=\""); 73 writer.write(size); 74 writer.write("\" "); 75 } 76 writer.write("src=\"exec/render?name="); 77 writer.write(SnipLink.encode(name)); 78 writer.write("&handler="); 79 writer.write(handler); 80 String content = Encoder.unescape(params.getContent()); 81 String renderId = RenderServlet.addContent(name, content); 82 writer.write("&id="); 83 writer.write(renderId); 84 if (null != imageMap) { 85 writer.write("\" usemap=\"#"); 86 writer.write(renderId); 87 } 88 writer.write("\"/>"); 89 90 if (null != imageMap) { 91 writer.write(RenderServlet.getImageMap(renderId, handler)); 92 } 93 } 94 95 96 } 97 | Popular Tags |