KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > blog > www > EntryListServlet


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: EntryListServlet.java,v 1.2 2007/02/20 03:53:30 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.blog.www;
23
24 import java.util.List JavaDoc;
25
26 import javax.servlet.ServletConfig JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.opensubsystems.blog.data.Blog;
32 import org.opensubsystems.blog.logic.BlogController;
33 import org.opensubsystems.core.data.DataConstant;
34 import org.opensubsystems.core.data.DataObject;
35 import org.opensubsystems.core.error.OSSException;
36 import org.opensubsystems.core.logic.ControllerManager;
37 import org.opensubsystems.patterns.listdata.data.ListOptions;
38 import org.opensubsystems.patterns.listdata.www.ListBrowserServlet;
39
40 /**
41  * Servlet responsible for browsing entries page by page. This servlet enhances
42  * the functionality of the generic list browser servlet and provides specific
43  * functionality related to browsing the blog entries.
44  *
45  * @version $Id: EntryListServlet.java,v 1.2 2007/02/20 03:53:30 bastafidli Exp $
46  * @author Miro Halas
47  * @code.reviewer Miro Halas
48  * @code.reviewed Initial revision
49  */

50 public class EntryListServlet extends ListBrowserServlet
51 {
52    // Configuration settings ///////////////////////////////////////////////////
53

54    /**
55     * Name of the property for page to view single blog entry.
56     */

57    public static final String JavaDoc BLOGBROWSER_BLOGENTRY_PAGE
58                                  = "blogbrowser.entry.page";
59
60    // Public methods ///////////////////////////////////////////////////////////
61

62    /**
63     * {@inheritDoc}
64     */

65    public void init(
66       ServletConfig JavaDoc scConfig
67    ) throws ServletException JavaDoc
68    {
69       super.init(scConfig);
70
71       // Page to view single blog entry
72
cacheUIPath(scConfig, BLOGBROWSER_BLOGENTRY_PAGE,
73                   "Path to entry viewer page is not set in property "
74                   + BLOGBROWSER_BLOGENTRY_PAGE);
75    }
76    
77    // Overwritten methods //////////////////////////////////////////////////////
78

79    /**
80     * {@inheritDoc}
81     */

82    protected void completeAction(
83       Object JavaDoc[] listInfo,
84       HttpServletRequest JavaDoc hsrqRequest,
85       HttpServletResponse JavaDoc hsrpResponse,
86       String JavaDoc strUIID
87    ) throws Exception JavaDoc
88    {
89       ListOptions options = (ListOptions)listInfo[0];
90       List JavaDoc lstDataObjects = (List JavaDoc)listInfo[1];
91       
92       if ((options.getParentDataType() == DataConstant.BLOG_DATA_TYPE)
93          && (options.getParentId() != DataObject.NEW_ID))
94       {
95          // The list of entries was retrieved was some specific blog so
96
// retrieve the blog as well and send it to page
97
Blog parent;
98          
99          parent = (Blog)getController().get(options.getParentId());
100          if (parent != null)
101          {
102             hsrqRequest.setAttribute("blog", parent);
103          }
104       }
105       if ((options.getExtraFilter() != null)
106          && (lstDataObjects != null) && (lstDataObjects.size() == 1))
107       {
108          // The request was retrieved using extra filter which should be the
109
// if of the entry we want to see. The list also contains only single
110
// data object which just proves this guess. Use a special page to
111
// display this entry
112
hsrqRequest.setAttribute("blogentry", lstDataObjects.get(0));
113          strUIID = BLOGBROWSER_BLOGENTRY_PAGE;
114       }
115       
116       // All URLs in the pages are not hardcoded but are instead generated by a
117
// navigator object. Create one suitable for page generated dynamically
118
// by the list pattern servlet
119
hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
120       
121       super.completeAction(listInfo, hsrqRequest, hsrpResponse, strUIID);
122    }
123
124    // Helper methods ///////////////////////////////////////////////////////////
125

126    /**
127     * Get controller to invoke business logic.
128     *
129     * @return BlogController
130     * @throws OSSException - an error has occured
131     */

132    protected BlogController getController(
133    ) throws OSSException
134    {
135       BlogController controller;
136       
137       controller = (BlogController)ControllerManager.getInstance(
138                                                         BlogController.class);
139       
140       return controller;
141    }
142
143    /**
144     * Get instance of navigator object suitable for processing current request.
145     *
146     * @param hsrqRequest - current request
147     * @return BlogNavigator - navigator for current request
148     */

149    protected BlogNavigator getNavigator(
150       HttpServletRequest JavaDoc hsrqRequest
151    )
152    {
153       return new DynamicBlogNavigator(hsrqRequest);
154    }
155 }
156
Popular Tags