KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > render > macro > UserMacro


1 /*
2  * $Id: UserMacro.java,v 1.4 2005/01/17 21:35:26 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.render.macro;
27
28 import java.io.IOException JavaDoc;
29 import java.io.Writer JavaDoc;
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     /*
41      * (non-Javadoc)
42      *
43      * @see org.radeox.macro.Macro#getName()
44      */

45     public String JavaDoc getName() {
46         return "user";
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see org.radeox.macro.BaseMacro#getDescription()
53      */

54     public String JavaDoc getDescription() {
55         return "Shows link to a user with given nickname.";
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.radeox.macro.BaseMacro#getParamDescription()
62      */

63     public String JavaDoc[] getParamDescription() {
64         return new String JavaDoc[]{"1: nickname of the user"};
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see org.radeox.macro.Macro#execute(java.io.Writer,
71      * org.radeox.macro.parameter.MacroParameter)
72      */

73     public void execute(Writer JavaDoc writer, MacroParameter params) throws IllegalArgumentException JavaDoc,
74             IOException JavaDoc {
75
76         if (params != null && params.getLength() == 1) {
77
78             String JavaDoc 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 JavaDoc out = new StringBuffer JavaDoc();
87             String JavaDoc ctxPath = BlogunityManager.getContextPath();
88
89             out.append("<img SRC=\"" + ctxPath + "/images/"
90                     + ((user.getSex() == User.MALE) ? "male.gif" : "female.gif") + "\"/>&nbsp;");
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             // render rank for user
97
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 JavaDoc("Unknown parameters within macro 'user' found!");
109     }
110
111 }
Popular Tags