1 25 26 package com.j2biz.blogunity.render.macro; 27 28 import java.io.IOException ; 29 import java.io.Writer ; 30 31 import org.apache.commons.lang.StringUtils; 32 import org.radeox.macro.parameter.MacroParameter; 33 34 43 public class ImageMacro extends AbstractMacro { 44 45 50 public String getName() { 51 return "image"; 52 } 53 54 59 public String getDescription() { 60 return "Shows image.\n" 61 + "This macro can be used in two ways:\n" 62 + "- Show images from internet referenced by URL. (e.g. {image:http://www.mysite.com/image.gif} )\n" 63 + "- Show images locally uploaded by the user into blog's intern \"images\"-directory.\n" 64 + " For example call: {image:image.gif} will load some image \"image.gif\" from \"images\"-directory of a current blog."; 65 } 66 67 72 public String [] getParamDescription() { 73 return new String []{"1: image-url (relative or absolute path )"}; 74 } 75 76 82 public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException , 83 IOException { 84 85 if (params != null && params.getLength() == 1) { 86 String url = params.get(0); 87 if (StringUtils.isNotEmpty(url)) { 88 89 StringBuffer out = new StringBuffer (); 90 if (url.trim().startsWith("http://")) { 91 out.append("<img SRC=\""); 92 out.append(url.trim()); 93 out.append("\"/>"); 94 } else { 95 96 if (blog != null) { 97 98 out.append("<img SRC=\""); 99 out.append(webappName + "/blogs/" + blog.getUrlName() + "/images/" 100 + url.trim()); 101 out.append("\"/>"); 102 } 103 } 104 writer.write(out.toString()); 105 } 106 } else 107 throw new IllegalArgumentException ("Unknown parameters within macro 'blog' found!"); 108 } 109 110 } | Popular Tags |