KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > weblog > tags > WeblogCategoryChooserTag


1 package org.roller.presentation.weblog.tags;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.apache.struts.util.RequestUtils;
6 import org.roller.model.WeblogManager;
7 import org.roller.pojos.UserData;
8 import org.roller.pojos.WeblogCategoryData;
9 import org.roller.presentation.RollerRequest;
10
11 import java.io.PrintWriter JavaDoc;
12 import java.util.Hashtable JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.jsp.JspException JavaDoc;
18 import javax.servlet.jsp.tagext.Tag JavaDoc;
19
20
21 /**
22  * @jsp.tag name="WeblogCatagoryChooser"
23  */

24 public class WeblogCategoryChooserTag
25     extends org.roller.presentation.tags.HybridTag
26 {
27     static final long serialVersionUID = 1553415977601404703L;
28     
29     private static Log mLogger =
30        LogFactory.getFactory().getInstance(WeblogCategoryChooserTag.class);
31
32     //-------------------------------------------------------------
33
/**
34      * Process start tag.
35      * @return EVAL_SKIP_BODY
36      */

37     public int doStartTag( PrintWriter JavaDoc pw ) throws JspException JavaDoc
38     {
39         try
40         {
41             HttpServletRequest JavaDoc req =
42                 (HttpServletRequest JavaDoc)pageContext.getRequest();
43             RollerRequest rreq = RollerRequest.getRollerRequest(
44                 (HttpServletRequest JavaDoc)pageContext.getRequest());
45
46             WeblogManager weblogMgr =
47                 rreq.getRoller().getWeblogManager();
48
49             UserData user = rreq.getUser();
50             List JavaDoc weblogCats =
51                 weblogMgr.getWeblogCategories(rreq.getWebsite(), false);
52
53             String JavaDoc rawUrl = req.getContextPath()+"/page/"+user.getUserName();
54
55             pw.println("<div class=\"rWeblogCategoryChooser\">");
56
57             Hashtable JavaDoc params = new Hashtable JavaDoc();
58             params.put( RollerRequest.USERNAME_KEY, user.getUserName() );
59             String JavaDoc weblog = RequestUtils.computeURL(
60                 pageContext,
61                 null, // forward
62
rawUrl, // href
63
null, // page
64
null,
65                 params, // params
66
null, // anchor
67
false); // redirect
68
String JavaDoc catClass = "rUnchosenCategory";
69             String JavaDoc chosenCat =
70                     req.getParameter(RollerRequest.WEBLOGCATEGORYNAME_KEY);
71             if ( chosenCat != null )
72             {
73                 pw.println(
74                     "<a HREF=\""+weblog+"\" class=\""+catClass+"\">"
75                         + "All" +
76                     "</a>");
77             }
78             else
79             {
80                 catClass = "rChosenCategory";
81                 pw.println(
82                     "<span class=\""+catClass+"\">"
83                         + "All" +
84                     "</span>");
85             }
86
87             for (Iterator JavaDoc wbcItr = weblogCats.iterator(); wbcItr.hasNext(); )
88             {
89                 WeblogCategoryData category = (WeblogCategoryData) wbcItr.next();
90                 String JavaDoc catName = category.getName();
91                 
92                 // For now don't show root category
93
if (category.getParent() == null) continue;
94                 
95                 params = new Hashtable JavaDoc();
96
97                 String JavaDoc pid = pageContext.getRequest().getParameter(
98                     RollerRequest.PAGEID_KEY );
99                 if (pid != null) params.put( RollerRequest.PAGEID_KEY,pid);
100
101                 params.put( RollerRequest.WEBLOGCATEGORYNAME_KEY, catName);
102
103                 pw.println(" | ");
104                 weblog = RequestUtils.computeURL(
105                     pageContext,
106                     null, // forward
107
rawUrl, // href
108
null, // page
109
null,
110                     params, // params
111
null, // anchor
112
false); // redirect
113

114                 catClass = "rUnchosenCategory";
115                 chosenCat = req.getParameter(
116                     RollerRequest.WEBLOGCATEGORYNAME_KEY);
117                 if ( chosenCat != null && chosenCat.equals(catName) )
118                 {
119                     catClass = "rChosenCategory";
120                     pw.println(
121                         "<span class=\""+catClass+"\">"
122                             + category.getPath() +
123                         "</span>");
124                 }
125                 else
126                 {
127                     pw.println(
128                         "<a HREF=\""+weblog+"\" class=\""+catClass+"\">"
129                             + category.getPath() +
130                         "</a>");
131                 }
132             }
133             
134             pw.println("</div>");
135         }
136         catch (Exception JavaDoc e)
137         {
138             mLogger.error("Exception",e);
139             throw new JspException JavaDoc(e);
140         }
141         return Tag.SKIP_BODY;
142     }
143 }
144
145
Popular Tags