KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > workflow > taglib > CategoryWithNameTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.cms.workflow.taglib;
24
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.JspTagException JavaDoc;
27
28 import org.infoglue.cms.controllers.kernel.impl.simple.CategoryController;
29 import org.infoglue.cms.entities.management.CategoryVO;
30 import org.infoglue.deliver.taglib.AbstractTag;
31
32 /**
33  * This class implements the <iw:categoryWithName> tag, which stores a category value
34  * object (with the children populated) in a page context variable.
35  */

36 public class CategoryWithNameTag extends AbstractTag
37 {
38     /**
39      * The universal version identifier.
40      */

41     private static final long serialVersionUID = 6455221936074988498L;
42     
43     /**
44      * The name of the category.
45      */

46     private String JavaDoc name;
47     
48     /**
49      * Default constructor.
50      */

51     public CategoryWithNameTag()
52     {
53         super();
54     }
55     
56     /**
57      * Process the end tag. Stores the category value object in a page context variable.
58      *
59      * @return indication of whether to continue evaluating the JSP page.
60      * @throws JspException if an error occurred while processing this tag.
61      */

62     public int doEndTag() throws JspException JavaDoc
63     {
64         setResultAttribute(findCategory());
65         return EVAL_PAGE;
66     }
67
68     /**
69      * Finds the category with the specified name.
70      *
71      * @return the category value object with the children populated.
72      * @throws JspException if an error occurs when fetching the category.
73      */

74     private CategoryVO findCategory() throws JspException JavaDoc
75     {
76         try
77         {
78             final CategoryVO categoryVO = CategoryController.getController().findByPath(name);
79             return CategoryController.getController().findWithChildren(categoryVO.getId());
80         }
81         catch(Exception JavaDoc e)
82         {
83             e.printStackTrace();
84             throw new JspTagException JavaDoc(e.getMessage());
85         }
86     }
87     
88     /**
89      * Sets the name attribute to the specified name.
90      *
91      * @param name the name to use.
92      */

93     public void setName(final String JavaDoc name)
94     {
95         this.name = name;
96     }
97 }
98
Popular Tags