KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: BlogMacro.java,v 1.6 2005/01/17 21:35:34 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.BlogDAO;
35 import com.j2biz.blogunity.exception.BlogunityException;
36 import com.j2biz.blogunity.pojo.Blog;
37
38 public class BlogMacro extends AbstractMacro {
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.radeox.macro.Macro#getName()
44      */

45     public String JavaDoc getName() {
46         return "blog";
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 the blog with given name.";
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: name of the blog"};
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 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 JavaDoc ctxPath = BlogunityManager.getContextPath();
88             
89             String JavaDoc style = "individual_blog";
90             String JavaDoc 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 JavaDoc icon = BlogunityManager.getBase() + "/images/" + style + ".png";
102             StringBuffer JavaDoc out = new StringBuffer JavaDoc();
103             out.append("<nobr>");
104             out.append("<img SRC=\"" + icon + "\"/>&nbsp;");
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 JavaDoc("Unknown parameters within macro 'blog' found!");
116     }
117
118 }
Popular Tags