KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > actions > blog > CategoryAction


1 /*
2  * $Id: CategoryAction.java,v 1.7 2005/01/17 21:36:01 michelson Exp $
3  *
4  * Copyright (c) 2005 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.web.actions.blog;
27
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 import org.apache.commons.lang.StringUtils;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import com.j2biz.blogunity.dao.CategoryDAO;
39 import com.j2biz.blogunity.dao.EntryDAO;
40 import com.j2biz.blogunity.exception.BlogunityException;
41 import com.j2biz.blogunity.pojo.Blog;
42 import com.j2biz.blogunity.pojo.Category;
43 import com.j2biz.blogunity.web.ActionResultFactory;
44 import com.j2biz.blogunity.web.IActionResult;
45 import com.j2biz.blogunity.web.actions.AbstractAction;
46
47 public class CategoryAction extends AbstractAction {
48
49     private static final Log log = LogFactory.getLog(CategoryAction.class);
50
51     private static final IActionResult BLOG_CATEGORY_FORWARD = ActionResultFactory
52             .buildForward("/categoryView.vm");
53
54     private Blog blog;
55
56     private String JavaDoc categoryId;
57
58     public CategoryAction(Blog blog, String JavaDoc categoryId) {
59         this.blog = blog;
60         this.categoryId = categoryId;
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see com.j2biz.blogunity.web.actions.AbstractAction#execute(javax.servlet.http.HttpServletRequest,
67      * javax.servlet.http.HttpServletResponse)
68      */

69     public IActionResult execute(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
70             throws BlogunityException {
71
72         List JavaDoc entries;
73         Category category;
74         if (StringUtils.isNotEmpty(categoryId)) {
75
76             Long JavaDoc catId = new Long JavaDoc(categoryId);
77
78             category = ( new CategoryDAO()).getCategoryByID(catId);
79
80             // FIXME this query returns just first 50 entries of the selected
81
// category. add paging later!
82
entries = ( new EntryDAO()).getPaginatedEntriesByCategory(blog.getUrlName(), catId, 0, 50);
83         } else {
84             // do nothing
85
category = null;
86             entries = Collections.EMPTY_LIST;
87         }
88         request.setAttribute("requestedCategory", category);
89         request.setAttribute("entries", entries);
90
91         return BLOG_CATEGORY_FORWARD;
92
93     }
94
95 }
Popular Tags