1 25 26 package com.j2biz.blogunity.render.macro; 27 28 import java.io.IOException ; 29 import java.io.Writer ; 30 31 import org.radeox.macro.parameter.MacroParameter; 32 33 import com.j2biz.blogunity.BlogunityManager; 34 import com.j2biz.blogunity.dao.BlogDAO; 35 import com.j2biz.blogunity.exception.BlogunityException; 36 import com.j2biz.blogunity.pojo.Blog; 37 38 public class BlogMacro extends AbstractMacro { 39 40 45 public String getName() { 46 return "blog"; 47 } 48 49 54 public String getDescription() { 55 return "Shows link to the blog with given name."; 56 } 57 58 63 public String [] getParamDescription() { 64 return new String []{"1: name of the blog"}; 65 } 66 67 73 public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException , 74 IOException { 75 76 if (params != null && params.getLength() == 1) { 77 78 String name = params.get(0); 79 Blog blog; 80 try { 81 BlogDAO dao = new BlogDAO(); 82 blog = dao.getBlogByUrlName(name); 83 } catch (BlogunityException e) { 84 return; 85 } 86 87 String ctxPath = BlogunityManager.getContextPath(); 88 89 String style = "individual_blog"; 90 String title = "individual blog"; 91 if (blog.getType() == Blog.COMMUNITY_BLOG) { 92 if (blog.getCommunityType() == Blog.PUBLIC_COMMUNTIY) { 93 style = "public_community_blog"; 94 title = "public community blog"; 95 } else if (blog.getCommunityType() == Blog.PRIVATE_COMMUNTIY) { 96 style = "private_community_blog"; 97 title = "private community blog"; 98 } 99 } 100 101 String icon = BlogunityManager.getBase() + "/images/" + style + ".png"; 102 StringBuffer out = new StringBuffer (); 103 out.append("<nobr>"); 104 out.append("<img SRC=\"" + icon + "\"/> "); 105 out.append("<a class=\"" + style + "\" HREF=\"" + ctxPath + "/blogs/" 106 + blog.getUrlName() + "\" title=\"" + title + "\">"); 107 out.append(blog.getFullName()); 108 out.append("</a>"); 109 out.append("</nobr>"); 110 111 112 writer.write(out.toString()); 113 114 } else 115 throw new IllegalArgumentException ("Unknown parameters within macro 'blog' found!"); 116 } 117 118 } | Popular Tags |