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.UserDAO; 35 import com.j2biz.blogunity.exception.BlogunityException; 36 import com.j2biz.blogunity.pojo.User; 37 38 public class UserMacro extends AbstractMacro { 39 40 45 public String getName() { 46 return "user"; 47 } 48 49 54 public String getDescription() { 55 return "Shows link to a user with given nickname."; 56 } 57 58 63 public String [] getParamDescription() { 64 return new String []{"1: nickname of the user"}; 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 nickname = params.get(0); 79 User user; 80 try { 81 UserDAO dao = new UserDAO(); 82 user = dao.getUserByName(nickname); 83 } catch (BlogunityException e) { 84 return; 85 } 86 StringBuffer out = new StringBuffer (); 87 String ctxPath = BlogunityManager.getContextPath(); 88 89 out.append("<img SRC=\"" + ctxPath + "/images/" 90 + ((user.getSex() == User.MALE) ? "male.gif" : "female.gif") + "\"/> "); 91 out.append("<a HREF=\"" + ctxPath + "/users/" + user.getNickname() + "\" title=\"" 92 + user.getFirstname() + " " + user.getLastname() + "\">"); 93 out.append(user.getNickname()); 94 out.append("</a>"); 95 96 if (BlogunityManager.getSystemConfiguration().isRankingOn()) { 98 out.append("<sup>"); 99 out.append("<img SRC=\""); 100 out.append(ctxPath + "/images/ranks/newbie1.gif"); 101 out.append("\" title=\"just a simple user ranking\"/>"); 102 out.append("</sup>"); 103 } 104 105 writer.write(out.toString()); 106 107 } else 108 throw new IllegalArgumentException ("Unknown parameters within macro 'user' found!"); 109 } 110 111 } | Popular Tags |