KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenChronicle
5  *
6  * $Id: BlogEditServlet.java,v 1.10 2007/03/05 07:27:14 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.io.IOException JavaDoc;
25 import java.security.Principal JavaDoc;
26 import java.sql.Timestamp JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30
31 import javax.servlet.ServletConfig JavaDoc;
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import javax.servlet.http.HttpSession JavaDoc;
36 import javax.transaction.UserTransaction JavaDoc;
37
38 import org.opensubsystems.blog.data.Blog;
39 import org.opensubsystems.blog.data.Entry;
40 import org.opensubsystems.core.data.DataObject;
41 import org.opensubsystems.core.error.OSSConcurentModifyException;
42 import org.opensubsystems.core.error.OSSInvalidDataException;
43 import org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl;
44 import org.opensubsystems.core.util.CallContext;
45 import org.opensubsystems.core.util.DateUtils;
46 import org.opensubsystems.core.util.GlobalConstants;
47 import org.opensubsystems.core.util.Log;
48 import org.opensubsystems.core.util.TransactionUtils;
49 import org.opensubsystems.core.www.WebCommonConstants;
50 import org.opensubsystems.core.www.WebSessionUtils;
51 import org.opensubsystems.core.www.WebUtils;
52
53 /**
54  * Servlet responsible for browsing and editing of blogs and their entries.
55  * This servlets ads functionality to the browser servlet to manipulate the data.
56  *
57  * @version $Id: BlogEditServlet.java,v 1.10 2007/03/05 07:27:14 bastafidli Exp $
58  * @author Miro Halas
59  * @code.reviewer Miro Halas
60  * @code.reviewed 1.5 2006/07/21 05:44:29 bastafidli
61  */

62 public class BlogEditServlet extends BlogBrowserServlet
63 {
64    // Configuration settings ///////////////////////////////////////////////////
65

66    /**
67     * Name of the property for user name used to login.
68     */

69    public static final String JavaDoc BLOGEDIT_LOGIN = "blogedit.login.username";
70
71    /**
72     * Name of the property for password used to login.
73     */

74    public static final String JavaDoc BLOGEDIT_PASSWORD = "blogedit.login.password";
75
76    /**
77     * Name of the property for page to login.
78     */

79    public static final String JavaDoc BLOGEDIT_LOGIN_PAGE = "blogedit.login.page";
80
81    /**
82     * Name of the property for page to logout.
83     */

84    public static final String JavaDoc BLOGEDIT_LOGOUT_PAGE = "blogedit.logout.page";
85
86    /**
87     * Name of the property for page to create new blog.
88     */

89    public static final String JavaDoc BLOGEDIT_NEW_BLOG_PAGE = "blogedit.blog.new.page";
90
91    /**
92     * Name of the property for page to confirm deletion of blog.
93     */

94    public static final String JavaDoc BLOGEDIT_CONFIRMDELETE_BLOG_PAGE
95                                    = "blogedit.blog.confirmdelete.page";
96
97    /**
98     * Name of the property for page to create new blog entry.
99     */

100    public static final String JavaDoc BLOGEDIT_NEWENTRY_BLOG_PAGE = "blogedit.entry.new.page";
101
102    /**
103     * Name of the property for page to confirm deletion of blog entry
104     */

105    public static final String JavaDoc BLOGEDIT_CONFIRMDELETE_BLOGENTRY_PAGE
106                                    = "blogedit.entry.confirmdelete.page";
107    
108    // Constants ////////////////////////////////////////////////////////////////
109

110    /**
111     * Names of the form and action to display create blog dialog.
112     */

113    public static final String JavaDoc FORM_CREATE_BLOG_NAME = "FORM_CREATE_BLOG";
114
115    /**
116     * Names of the form and action to display edit blog dialog.
117     */

118    public static final String JavaDoc FORM_EDIT_BLOG_NAME = "FORM_EDIT_BLOG";
119    
120    /**
121     * Names of the form and action to create blog.
122     */

123    public static final String JavaDoc FORM_EDIT_BLOG_NAME_CREATE = "create";
124
125    /**
126     * Names of the form and action to display delete blog dialog.
127     */

128    public static final String JavaDoc FORM_EDIT_BLOG_NAME_DELETE = "delete";
129
130    /**
131     * Names of the form and action to display create blog entry dialog.
132     */

133    public static final String JavaDoc FORM_EDIT_BLOG_NAME_CREATEENTRY = "createentry";
134
135    /**
136     * Names of the form and action to delete blog.
137     */

138    public static final String JavaDoc FORM_DELETE_BLOG_NAME = "FORM_DELETE_BLOG";
139
140    /**
141     * Names of the form and action to create blog entry.
142     */

143    public static final String JavaDoc FORM_CREATE_BLOGENTRY_NAME = "FORM_CREATE_BLOGENTRY";
144
145    /**
146     * Names of the form and action to display edit blog entry dialog.
147     */

148    public static final String JavaDoc FORM_EDIT_BLOGENTRY_NAME = "FORM_EDIT_BLOGENTRY";
149
150    /**
151     * Names of the form and action to display delete blog entry dialog.
152     */

153    public static final String JavaDoc FORM_EDIT_BLOGENTRY_NAME_DELETE = "delete";
154
155    /**
156     * Names of the form and action to delete blog entry.
157     */

158    public static final String JavaDoc FORM_DELETE_BLOGENTRY_NAME = "FORM_DELETE_BLOGENTRY";
159
160    /**
161     * Names of the form and action to login to the application.
162     */

163    public static final String JavaDoc FORM_LOGIN_NAME = "FORM_LOGIN";
164
165    /**
166     * Names of the form and action to logout from the application.
167     */

168    public static final String JavaDoc FORM_LOGOUT_NAME = "FORM_LOGOUT";
169
170    /**
171     * Constants for action to display new blog dialog.
172     */

173    public static final int FORM_NEW_BLOG_ID = FORM_COUNT_BLOGBROWSER + 1;
174
175    /**
176     * Constants for action to create new blog.
177     */

178    public static final int FORM_CREATE_BLOG_ID = FORM_COUNT_BLOGBROWSER + 2;
179
180    /**
181     * Constants for action to edit blog.
182     */

183    public static final int FORM_EDIT_BLOG_ID = FORM_COUNT_BLOGBROWSER + 3;
184
185    /**
186     * Constants for action to display delete blog dialog.
187     */

188    public static final int FORM_CONFIRMDELETE_BLOG_ID = FORM_COUNT_BLOGBROWSER + 4;
189
190    /**
191     * Constants for action to delete blog.
192     */

193    public static final int FORM_DELETE_BLOG_ID = FORM_COUNT_BLOGBROWSER + 5;
194
195    /**
196     * Constants for action to display create blog entry dialog.
197     */

198    public static final int FORM_NEWENTRY_BLOG_ID = FORM_COUNT_BLOGBROWSER + 6;
199
200    /**
201     * Constants for action to create blog entry dialog.
202     */

203    public static final int FORM_CREATE_BLOGENTRY_ID = FORM_COUNT_BLOGBROWSER + 7;
204
205    /**
206     * Constants for action to edit blog entry.
207     */

208    public static final int FORM_EDIT_BLOGENTRY_ID = FORM_COUNT_BLOGBROWSER + 8;
209
210    /**
211     * Constants for action to display delete blog entry dialog.
212     */

213    public static final int FORM_CONFIRMDELETE_BLOGENTRY_ID = FORM_COUNT_BLOGBROWSER + 9;
214
215    /**
216     * Constants for action to delete blog entry.
217     */

218    public static final int FORM_DELETE_BLOGENTRY_ID = FORM_COUNT_BLOGBROWSER + 10;
219
220    /**
221     * Constants for action to login to the application.
222     */

223    public static final int FORM_LOGIN_ID = FORM_COUNT_BLOGBROWSER + 11;
224
225    /**
226     * Constants for action to logout from the application.
227     */

228    public static final int FORM_LOGOUT_ID = FORM_COUNT_BLOGBROWSER + 12;
229
230    /**
231     * How many forms this servlet recognizes.
232     */

233    public static final int FORM_COUNT_BLOGEDIT = FORM_COUNT_BLOGBROWSER + 13;
234    
235    // Cached values ////////////////////////////////////////////////////////////
236

237    /**
238     * Logger for this class
239     */

240    private static Logger JavaDoc s_logger = Log.getInstance(BlogEditServlet.class);
241
242    /**
243     * Simple counter used to generate internal session ids for the clients.
244     */

245    private static int s_iSessionCounter = 0;
246    
247    /**
248     * User name to use to login to the application.
249     */

250    protected String JavaDoc m_strLogin;
251    
252    /**
253     * Password to use to login to the application.
254     */

255    protected String JavaDoc m_strPassword;
256    
257    // Attributes ///////////////////////////////////////////////////////////////
258

259    /**
260     * Generated serial version id for this class.
261     */

262    private static final long serialVersionUID = 7525262325709883457L;
263
264    // Public methods ///////////////////////////////////////////////////////////
265

266    /**
267     * {@inheritDoc}
268     */

269    public void init(
270       ServletConfig JavaDoc scConfig
271    ) throws ServletException JavaDoc
272    {
273       super.init(scConfig);
274
275       // Allow empty user name and password if user desires so
276
m_strLogin = WebUtils.readProperty(scConfig, BLOGEDIT_LOGIN, "", true);
277       s_logger.config(BLOGEDIT_LOGIN + " = " + m_strLogin);
278       m_strPassword = WebUtils.readProperty(scConfig, BLOGEDIT_PASSWORD, "", true);
279       s_logger.config(BLOGEDIT_LOGIN + " = " + m_strPassword);
280       
281       // Load UI pages for this application
282
// Page to login
283
cacheUIPath(scConfig, BLOGEDIT_LOGIN_PAGE,
284                   "Path to page to login is not set in property "
285                   + BLOGEDIT_LOGIN_PAGE);
286       
287       // Page to logout
288
cacheUIPath(scConfig, BLOGEDIT_LOGOUT_PAGE,
289                   "Path to page to logout is not set in property "
290                   + BLOGEDIT_LOGOUT_PAGE);
291       
292       // Page to create new blog
293
cacheUIPath(scConfig, BLOGEDIT_NEW_BLOG_PAGE,
294                   "Path to page to create new blog is not set in property "
295                   + BLOGEDIT_NEW_BLOG_PAGE);
296
297       // Page to confirm deletion of blog
298
cacheUIPath(scConfig, BLOGEDIT_CONFIRMDELETE_BLOG_PAGE,
299                   "Path to page to confirm deletion of blog is not set in property "
300                   + BLOGEDIT_CONFIRMDELETE_BLOG_PAGE);
301
302       // Page to create new blog entry
303
cacheUIPath(scConfig, BLOGEDIT_NEWENTRY_BLOG_PAGE,
304                   "Path to page to create new blog entry is not set in property "
305                   + BLOGEDIT_NEWENTRY_BLOG_PAGE);
306
307       // Page to confirm deletion of blog entry
308
cacheUIPath(scConfig, BLOGEDIT_CONFIRMDELETE_BLOGENTRY_PAGE,
309                   "Path to page to confirm deletion of blog entry is not set in property "
310                   + BLOGEDIT_CONFIRMDELETE_BLOGENTRY_PAGE);
311    }
312    
313    /**
314     * {@inheritDoc}
315     */

316    public String JavaDoc getServletInfo(
317    )
318    {
319       return this.getClass().getName();
320    }
321
322    // Helper methods ///////////////////////////////////////////////////////////
323

324    /**
325     * {@inheritDoc}
326     */

327    protected void doGet(
328       HttpServletRequest JavaDoc hsrqRequest,
329       HttpServletResponse JavaDoc hsrpResponse
330    ) throws ServletException JavaDoc,
331             IOException JavaDoc
332    {
333       BlogNavigator navigator = getNavigator(hsrqRequest);
334       
335       if (navigator.isLoginPage())
336       {
337          processNewLoginForm(hsrqRequest, hsrpResponse);
338       }
339       else if (navigator.isLogoutPage())
340       {
341          processNewLogoutForm(hsrqRequest, hsrpResponse);
342       }
343       else
344       {
345          // Now let the browser servlet process the request
346
super.doGet(hsrqRequest, hsrpResponse);
347       }
348    }
349    
350    /**
351     * {@inheritDoc}
352     */

353    protected void doPost(
354       HttpServletRequest JavaDoc hsrqRequest,
355       HttpServletResponse JavaDoc hsrpResponse
356    ) throws ServletException JavaDoc, IOException JavaDoc
357    {
358       switch(getFormToProcess(hsrqRequest))
359       {
360          case FORM_LOGIN_ID :
361          {
362             processLoginForm(hsrqRequest, hsrpResponse);
363             break;
364          }
365
366          case FORM_LOGOUT_ID :
367          {
368             processLogoutForm(hsrqRequest, hsrpResponse);
369             break;
370          }
371
372          case FORM_NEW_BLOG_ID :
373          {
374             processNewBlogForm(hsrqRequest, hsrpResponse);
375             break;
376          }
377
378          case FORM_CREATE_BLOG_ID :
379          {
380             processCreateBlogForm(hsrqRequest, hsrpResponse);
381             break;
382          }
383
384          case FORM_EDIT_BLOG_ID :
385          {
386             processEditBlogForm(hsrqRequest, hsrpResponse);
387             break;
388          }
389
390          case FORM_CONFIRMDELETE_BLOG_ID :
391          {
392             processConfirmDeleteBlogForm(hsrqRequest, hsrpResponse);
393             break;
394          }
395
396          case FORM_DELETE_BLOG_ID :
397          {
398             processDeleteBlogForm(hsrqRequest, hsrpResponse);
399             break;
400          }
401
402          case FORM_NEWENTRY_BLOG_ID :
403          {
404             processNewEntryBlogForm(hsrqRequest, hsrpResponse);
405             break;
406          }
407
408          case FORM_CREATE_BLOGENTRY_ID :
409          {
410             processCreateEntryForm(hsrqRequest, hsrpResponse);
411             break;
412          }
413
414          case FORM_EDIT_BLOGENTRY_ID :
415          {
416             processEditEntryForm(hsrqRequest, hsrpResponse);
417             break;
418          }
419
420          case FORM_CONFIRMDELETE_BLOGENTRY_ID :
421          {
422             processConfirmDeleteEntryForm(hsrqRequest, hsrpResponse);
423             break;
424          }
425
426          case FORM_DELETE_BLOGENTRY_ID :
427          {
428             processDeleteEntryForm(hsrqRequest, hsrpResponse);
429             break;
430          }
431
432          default :
433          {
434             super.doPost(hsrqRequest, hsrpResponse);
435             break;
436          }
437       }
438    }
439
440    // Helper methods ///////////////////////////////////////////////////////////
441

442    /**
443     * {@inheritDoc}
444     */

445    protected int getFormToProcess(
446       HttpServletRequest JavaDoc hsrqRequest
447    )
448    {
449       String JavaDoc strFormName;
450       int iReturn = FORM_UNKNOWN_ID;
451
452       strFormName = hsrqRequest.getParameter(FORM_NAME_REQUEST_PARAM);
453
454       if (strFormName == null)
455       {
456          iReturn = super.getFormToProcess(hsrqRequest);
457       }
458       else if (strFormName.equals(FORM_LOGIN_NAME))
459       {
460          // Login to the application
461
iReturn = FORM_LOGIN_ID;
462       }
463       else if (strFormName.equals(FORM_LOGOUT_NAME))
464       {
465          // Logout from the application
466
iReturn = FORM_LOGOUT_ID;
467       }
468       else if (strFormName.equals(FORM_CREATE_BLOG_NAME))
469       {
470          // Create new blog from already supplied details
471
iReturn = FORM_CREATE_BLOG_ID;
472       }
473       else if (strFormName.equals(FORM_EDIT_BLOG_NAME))
474       {
475          // Edit blog, it can mean multiple things (Create New, Save...)
476
if (hsrqRequest.getParameter(FORM_EDIT_BLOG_NAME_CREATE) != null)
477          {
478             // Intention to create new blog, need to supply the details
479
iReturn = FORM_NEW_BLOG_ID;
480          }
481          else if (hsrqRequest.getParameter(FORM_EDIT_BLOG_NAME_DELETE) != null)
482          {
483             // Intention to delete current blog, need to be confirmed
484
iReturn = FORM_CONFIRMDELETE_BLOG_ID;
485          }
486          else if (hsrqRequest.getParameter(FORM_EDIT_BLOG_NAME_CREATEENTRY) != null)
487          {
488             // Intention to create new blog entry, need to supply the details
489
iReturn = FORM_NEWENTRY_BLOG_ID;
490          }
491          else
492          {
493             // If nothing else is specified, then save supplied data
494
iReturn = FORM_EDIT_BLOG_ID;
495          }
496       }
497       else if (strFormName.equals(FORM_DELETE_BLOG_NAME))
498       {
499          // Delete current blog
500
iReturn = FORM_DELETE_BLOG_ID;
501       }
502       else if (strFormName.equals(FORM_CREATE_BLOGENTRY_NAME))
503       {
504          // Create new blog entry
505
iReturn = FORM_CREATE_BLOGENTRY_ID;
506       }
507       else if (strFormName.equals(FORM_EDIT_BLOGENTRY_NAME))
508       {
509          // Edit blog entry, it can mean multiple things (Save, Delete...)
510
// Create New is part of modifying blog, so it is above
511
if (hsrqRequest.getParameter(FORM_EDIT_BLOGENTRY_NAME_DELETE) != null)
512          {
513             // Intention to delete current blog entry
514
iReturn = FORM_CONFIRMDELETE_BLOGENTRY_ID;
515          }
516          else
517          {
518             // Save edited blog entry
519
iReturn = FORM_EDIT_BLOGENTRY_ID;
520          }
521       }
522       else if (strFormName.equals(FORM_DELETE_BLOGENTRY_NAME))
523       {
524          // Delete current blog
525
iReturn = FORM_DELETE_BLOGENTRY_ID;
526       }
527       else
528       {
529          iReturn = super.getFormToProcess(hsrqRequest);
530       }
531
532       return iReturn;
533    }
534
535    /**
536     * Process form to display login dialog.
537     *
538     * @param hsrqRequest - the servlet request.
539     * @param hsrpResponse - the servlet response.
540     * @throws ServletException - an error while serving request
541     * @throws IOException - an error while writing response
542     */

543    protected void processNewLoginForm(
544       HttpServletRequest JavaDoc hsrqRequest,
545       HttpServletResponse JavaDoc hsrpResponse
546    ) throws IOException JavaDoc,
547             ServletException JavaDoc
548    {
549       s_logger.entering(this.getClass().getName(), "processNewLoginForm");
550
551       try
552       {
553          hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
554          displayUI(BLOGEDIT_LOGIN_PAGE, hsrqRequest, hsrpResponse);
555       }
556       catch (Exception JavaDoc eExc)
557       {
558          s_logger.log(Level.WARNING,
559                       "An error has occured while displaying login page.", eExc);
560          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
561                         getNavigator(hsrqRequest).getRootURL(),
562                         eExc.getCause());
563       }
564       finally
565       {
566          s_logger.exiting(this.getClass().getName(), "processNewLoginForm");
567       }
568    }
569    
570    /**
571     * Process form to login to the application.
572     *
573     * @param hsrqRequest - the servlet request.
574     * @param hsrpResponse - the servlet response.
575     * @throws ServletException - an error while serving request
576     * @throws IOException - an error while writing response
577     */

578    protected void processLoginForm(
579       HttpServletRequest JavaDoc hsrqRequest,
580       HttpServletResponse JavaDoc hsrpResponse
581    ) throws IOException JavaDoc,
582             ServletException JavaDoc
583    {
584       s_logger.entering(this.getClass().getName(), "processLoginForm");
585
586       try
587       {
588          HttpSession JavaDoc hsSession;
589          Principal JavaDoc currentUser;
590          String JavaDoc strSessionId;
591          String JavaDoc strURL;
592             
593          // We do not want to create new session if it doesn't exist since that
594
// is the responsibility of the parent claees. We should have session
595
// at this point
596
hsSession = hsrqRequest.getSession(false);
597          currentUser = CallContext.getInstance().getCurrentUser();
598          if (GlobalConstants.ERROR_CHECKING)
599          {
600             assert hsSession != null : "Session must exist at this point";
601          }
602
603          if (currentUser != null)
604          {
605             // If users tries to login again using the same session (by directly
606
// typing login URL) while it is already logged in,
607
// the session tracking object in the application server wouldn't be
608
// destroyed, just for that case go throught the session object and
609
// remove all values in it, this will cause logout if it was previously
610
// logged in
611
WebSessionUtils.resetSessionAndUserInfo(hsSession);
612    
613             // This needs to by synchronized so that we generate the unique id for
614
// each session
615
synchronized (FORM_LOGIN_NAME)
616             {
617                strSessionId = Integer.toString(++s_iSessionCounter);
618             }
619             
620             WebSessionUtils.setSessionAndUserInfo(hsSession, strSessionId, currentUser);
621             // Check if there is any URL specified in the session object
622
strURL = getLoginRedirect(hsSession, hsrqRequest);
623             // We are doing the redirect so reset the stored value
624
resetLoginRedirect(hsSession);
625             if ((strURL == null) || (strURL.length() == 0))
626             {
627                strURL = getNavigator(hsrqRequest).getRootURL();
628             }
629             hsrpResponse.sendRedirect(strURL);
630          }
631          else
632          {
633             // The login was incorrect so display the login page again
634
hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
635             displayUI(BLOGEDIT_LOGIN_PAGE, hsrqRequest, hsrpResponse);
636          }
637       }
638       catch (Exception JavaDoc eExc)
639       {
640          s_logger.log(Level.WARNING,
641                       "An error has occured while processing login page.", eExc);
642          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
643                         getNavigator(hsrqRequest).getRootURL(),
644                         eExc.getCause());
645       }
646       finally
647       {
648          s_logger.exiting(this.getClass().getName(), "processLoginForm");
649       }
650    }
651
652    /**
653     * Process form to display logout dialog.
654     *
655     * @param hsrqRequest - the servlet request.
656     * @param hsrpResponse - the servlet response.
657     * @throws ServletException - an error while serving request
658     * @throws IOException - an error while writing response
659     */

660    protected void processNewLogoutForm(
661       HttpServletRequest JavaDoc hsrqRequest,
662       HttpServletResponse JavaDoc hsrpResponse
663    ) throws IOException JavaDoc,
664             ServletException JavaDoc
665    {
666       s_logger.entering(this.getClass().getName(), "processNewLogoutForm");
667
668       try
669       {
670          hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
671          displayUI(BLOGEDIT_LOGOUT_PAGE, hsrqRequest, hsrpResponse);
672       }
673       catch (Exception JavaDoc eExc)
674       {
675          s_logger.log(Level.WARNING,
676                       "An error has occured while displaying logout page.", eExc);
677          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
678                         getNavigator(hsrqRequest).getRootURL(),
679                         eExc.getCause());
680       }
681       finally
682       {
683          s_logger.exiting(this.getClass().getName(), "processNewLogoutForm");
684       }
685    }
686    
687    /**
688     * Process form to logout from the application.
689     *
690     * @param hsrqRequest - the servlet request.
691     * @param hsrpResponse - the servlet response.
692     * @throws ServletException - an error while serving request
693     * @throws IOException - an error while writing response
694     */

695    protected void processLogoutForm(
696       HttpServletRequest JavaDoc hsrqRequest,
697       HttpServletResponse JavaDoc hsrpResponse
698    ) throws IOException JavaDoc,
699             ServletException JavaDoc
700    {
701       s_logger.entering(this.getClass().getName(), "processLogoutForm");
702
703       try
704       {
705          HttpSession JavaDoc hsSession;
706             
707          // We do not want to create new session if it doesn't exist since that
708
// is the responsibility of the parent claees. We should have session
709
// at this point
710
hsSession = hsrqRequest.getSession(false);
711          if (GlobalConstants.ERROR_CHECKING)
712          {
713             assert hsSession != null : "Session must exist at this point";
714          }
715          
716          WebSessionUtils.resetSessionAndUserInfo(hsSession);
717          
718          // Redirect user to the page displaying all blogs
719
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getRootURL());
720       }
721       catch (Exception JavaDoc eExc)
722       {
723          s_logger.log(Level.WARNING,
724                       "An error has occured while processing logout page.", eExc);
725          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
726                         getNavigator(hsrqRequest).getRootURL(),
727                         eExc.getCause());
728       }
729       finally
730       {
731          s_logger.exiting(this.getClass().getName(), "processLogoutForm");
732       }
733    }
734
735    /**
736     * Process form to display dialog to create new blog.
737     * It supplies template object with default information for new blog.
738     *
739     * @param hsrqRequest - the servlet request.
740     * @param hsrpResponse - the servlet response.
741     * @throws ServletException - an error while serving request
742     * @throws IOException - an error while writing response
743     */

744    protected void processNewBlogForm(
745       HttpServletRequest JavaDoc hsrqRequest,
746       HttpServletResponse JavaDoc hsrpResponse
747    ) throws IOException JavaDoc,
748             ServletException JavaDoc
749    {
750       s_logger.entering(this.getClass().getName(), "processNewBlogForm");
751
752       try
753       {
754          Blog blog;
755
756          // Create template object which will be used to will the form with
757
// default values
758
blog = (Blog)getController().get(DataObject.NEW_ID);
759
760          hsrqRequest.setAttribute("blog", blog);
761          hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
762          displayUI(BLOGEDIT_NEW_BLOG_PAGE, hsrqRequest, hsrpResponse);
763       }
764       catch (Exception JavaDoc eExc)
765       {
766          s_logger.log(Level.WARNING,
767                       "An error has occured while retrieving information about" +
768                       " new blog.", eExc);
769          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
770                         getNavigator(hsrqRequest).getRootURL(),
771                         eExc.getCause());
772       }
773       finally
774       {
775          s_logger.exiting(this.getClass().getName(), "processNewBlogForm");
776       }
777    }
778
779    /**
780     * Process form to actually create new blog from supplied information.
781     *
782     * @param hsrqRequest - the servlet request.
783     * @param hsrpResponse - the servlet response.
784     * @throws ServletException - an error while serving request
785     * @throws IOException - an error while writing response
786     */

787    protected void processCreateBlogForm(
788       HttpServletRequest JavaDoc hsrqRequest,
789       HttpServletResponse JavaDoc hsrpResponse
790    ) throws IOException JavaDoc,
791             ServletException JavaDoc
792    {
793       s_logger.entering(this.getClass().getName(), "processCreateBlogForm");
794
795       UserTransaction JavaDoc transaction = null;
796       Blog blog = null;
797       try
798       {
799          transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
800
801          blog = parseBlogFromRequest(hsrqRequest);
802          Blog blogUpdated = null;
803       
804          // Since one request corresponds to user transaction and we know we are
805
// going to modify data, start database transaction to group any
806
// databast modification and queries we may need to execute to satisfy
807
// this action.
808
transaction.begin();
809          blogUpdated = (Blog)getController().create(blog);
810          transaction.commit();
811                   
812          // Redirect user to the page displaying newly created blog
813
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getURL(blogUpdated));
814       }
815       catch (OSSInvalidDataException ideExc)
816       {
817          TransactionUtils.rollback(transaction);
818          CallContext.getInstance().getMessages().addMessages(
819                                                     ideExc.getErrorMessages());
820          // Return the submitted value with the modified entries
821
hsrqRequest.setAttribute("blog", blog);
822          hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
823          displayUI(BLOGEDIT_NEW_BLOG_PAGE, hsrqRequest, hsrpResponse);
824       }
825       catch (Throwable JavaDoc thr)
826       {
827          TransactionUtils.rollback(transaction);
828          s_logger.log(Level.WARNING, "An error has occured while creating blog.", thr);
829          messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
830                         getNavigator(hsrqRequest).getRootURL(),
831                         thr.getCause());
832       }
833       finally
834       {
835          s_logger.exiting(this.getClass().getName(), "processCreateBlogForm");
836       }
837    }
838
839    /**
840     * Process form to save modified information about blog.
841     *
842     * @param hsrqRequest - the servlet request.
843     * @param hsrpResponse - the servlet response.
844     * @throws ServletException - an error while serving request
845     * @throws IOException - an error while writing response
846     */

847    protected void processEditBlogForm(
848       HttpServletRequest JavaDoc hsrqRequest,
849       HttpServletResponse JavaDoc hsrpResponse
850    ) throws IOException JavaDoc,
851             ServletException JavaDoc
852    {
853       s_logger.entering(this.getClass().getName(), "processEditBlogForm");
854
855       UserTransaction JavaDoc transaction = null;
856       Blog blog = null;
857
858       blog = parseBlogFromRequest(hsrqRequest);
859       try
860       {
861          transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
862
863          Blog blogUpdated = null;
864
865          // Since one request corresponds to user transaction and we know we are
866
// going to modify data, start database transaction to group any
867
// databast modification and queries we may need to execute to satisfy
868
// this action.
869
transaction.begin();
870          blogUpdated = (Blog)getController().save(blog);
871          assert blogUpdated != null : "Save should return not null value.";
872          transaction.commit();
873
874          // Redirect user to the page displaying list of blogs
875
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getRootURL());
876       }
877       catch (OSSInvalidDataException ideExc)
878       {
879          TransactionUtils.rollback(transaction);
880          CallContext.getInstance().getMessages().addMessages(
881                                                     ideExc.getErrorMessages());
882          // Return the submitted value with the modified entries
883
processEditBlogError(hsrqRequest, hsrpResponse, blog);
884       }
885       catch (OSSConcurentModifyException ocmeExc)
886       {
887          TransactionUtils.rollback(transaction);
888          CallContext.getInstance().getMessages().addErrorMessage(
889                                                     ocmeExc.getMessage());
890          // Return the submitted value with the modified entries
891
processEditBlogError(hsrqRequest, hsrpResponse, blog);
892       }
893       catch (Throwable JavaDoc thr)
894       {
895          TransactionUtils.rollback(transaction);
896          s_logger.log(Level.WARNING, "An error has occured while saving blog.", thr);
897          messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
898                         getNavigator(hsrqRequest).getRootURL(), thr.getCause());
899       }
900       finally
901       {
902          s_logger.exiting(this.getClass().getName(), "processEditBlogForm");
903       }
904    }
905
906    /**
907     * Process recoverable error, which has occured while saving blog. This will
908     * show again the edit blog page but with the modified data and explanative
909     * error message.
910     *
911     * @param hsrqRequest - the servlet request.
912     * @param hsrpResponse - the servlet response.
913     * @param blog - blog with modified data submitted to the server
914     * @throws ServletException - an error while serving request
915     * @throws IOException - an error while writing response
916     */

917    protected void processEditBlogError(
918       HttpServletRequest JavaDoc hsrqRequest,
919       HttpServletResponse JavaDoc hsrpResponse,
920       Blog blog
921    ) throws IOException JavaDoc,
922             ServletException JavaDoc
923    {
924       BlogNavigator navigator;
925       
926       navigator = getNavigator(hsrqRequest);
927
928       try
929       {
930          List JavaDoc lstEntries;
931          
932          lstEntries = getController().getEntries(blog.getId());
933                   
934          // Return the submitted value with the modified entries
935
hsrqRequest.setAttribute("blog", blog);
936          if (lstEntries != null)
937          {
938             hsrqRequest.setAttribute("blogentries", lstEntries);
939          }
940          hsrqRequest.setAttribute("blognavigator", navigator);
941          displayUI(BLOGBROWSER_BLOG_VIEWER_PAGE, hsrqRequest, hsrpResponse);
942       }
943       catch (Throwable JavaDoc thr)
944       {
945          s_logger.log(Level.WARNING,
946                       "An error has occured while retrieving blog entries.",
947                       thr);
948          messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
949                         getNavigator(hsrqRequest).getRootURL(), thr.getCause());
950       }
951    }
952    
953    /**
954     * Process form to display dialog to confirm deletion of a blog.
955     *
956     * @param hsrqRequest - the servlet request.
957     * @param hsrpResponse - the servlet response.
958     * @throws ServletException - an error while serving request
959     * @throws IOException - an error while writing response
960     */

961    protected void processConfirmDeleteBlogForm(
962       HttpServletRequest JavaDoc hsrqRequest,
963       HttpServletResponse JavaDoc hsrpResponse
964    ) throws IOException JavaDoc,
965             ServletException JavaDoc
966    {
967       s_logger.entering(this.getClass().getName(), "processConfirmDeleteBlogForm");
968
969       try
970       {
971          Object JavaDoc objBlogIdentification;
972          Blog blog;
973          
974          // Get the data for blog which user wants to delete
975
objBlogIdentification = getNavigator(hsrqRequest).getBlogIdentification(
976                                                                 hsrqRequest);
977          if (objBlogIdentification instanceof Integer JavaDoc)
978          {
979             blog = (Blog)getController().get(
980                             ((Integer JavaDoc)objBlogIdentification).intValue());
981          }
982          else
983          {
984             blog = getController().get(objBlogIdentification.toString());
985          }
986          
987          if (blog != null)
988          {
989             hsrqRequest.setAttribute("blog", blog);
990          }
991          hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
992          displayUI(BLOGEDIT_CONFIRMDELETE_BLOG_PAGE, hsrqRequest, hsrpResponse);
993       }
994       catch (Throwable JavaDoc thr)
995       {
996          s_logger.log(Level.WARNING,
997                       "An error has occured while retrieving information" +
998                       " about blog to delete.", thr);
999          messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1000                        getNavigator(hsrqRequest).getRootURL(), thr.getCause());
1001      }
1002      finally
1003      {
1004         s_logger.exiting(this.getClass().getName(), "processConfirmDeleteBlogForm");
1005      }
1006   }
1007
1008   /**
1009    * Process form to delete specified blog.
1010    *
1011    * @param hsrqRequest - the servlet request.
1012    * @param hsrpResponse - the servlet response.
1013    * @throws ServletException - an error while serving request
1014    * @throws IOException - an error while writing response
1015    */

1016   protected void processDeleteBlogForm(
1017      HttpServletRequest JavaDoc hsrqRequest,
1018      HttpServletResponse JavaDoc hsrpResponse
1019   ) throws IOException JavaDoc,
1020            ServletException JavaDoc
1021   {
1022      s_logger.entering(this.getClass().getName(), "processDeleteBlogForm");
1023
1024      UserTransaction JavaDoc transaction = null;
1025      try
1026      {
1027         transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
1028
1029         int iId = parseBlogFromRequest(hsrqRequest).getId();
1030         
1031         // Since one request corresponds to user transaction and we know we are
1032
// going to modify data, start database transaction to group any
1033
// databast modification and queries we may need to execute to satisfy
1034
// this action.
1035
transaction.begin();
1036         getController().delete(iId);
1037         transaction.commit();
1038
1039         // Redirect user to the list of blogs
1040
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getRootURL());
1041      }
1042      catch (Throwable JavaDoc thr)
1043      {
1044         TransactionUtils.rollback(transaction);
1045         s_logger.log(Level.WARNING, "An error has occured while deleting blog.", thr);
1046         messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1047                        getNavigator(hsrqRequest).getRootURL(), thr.getCause());
1048      }
1049      finally
1050      {
1051         s_logger.exiting(this.getClass().getName(), "processDeleteBlogForm");
1052      }
1053   }
1054
1055   /**
1056    * Process form to display dialog to create new blog entry.
1057    *
1058    * @param hsrqRequest - the servlet request.
1059    * @param hsrpResponse - the servlet response.
1060    * @throws ServletException - an error while serving request
1061    * @throws IOException - an error while writing response
1062    */

1063   protected void processNewEntryBlogForm(
1064      HttpServletRequest JavaDoc hsrqRequest,
1065      HttpServletResponse JavaDoc hsrpResponse
1066   ) throws IOException JavaDoc,
1067            ServletException JavaDoc
1068   {
1069      s_logger.entering(this.getClass().getName(), "processNewEntryBlogForm");
1070
1071      try
1072      {
1073         Object JavaDoc[] arObjects = null;
1074
1075         // Get the data for blog where user wants to create new entry
1076
arObjects = getController().getWithEntry(
1077                        parseBlogFromRequest(hsrqRequest).getId(),
1078                        DataObject.NEW_ID);
1079         
1080         if (arObjects != null)
1081         {
1082            if (arObjects[0] != null)
1083            {
1084               hsrqRequest.setAttribute("blog", arObjects[0]);
1085            }
1086            if (arObjects[1] != null)
1087            {
1088               hsrqRequest.setAttribute("blogentry", arObjects[1]);
1089            }
1090         }
1091
1092         hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
1093         displayUI(BLOGEDIT_NEWENTRY_BLOG_PAGE, hsrqRequest, hsrpResponse);
1094      }
1095      catch (Throwable JavaDoc thr)
1096      {
1097         s_logger.log(Level.WARNING,
1098                      "An error has occured while retrieving information" +
1099                      " about new blog entry.", thr);
1100         messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1101                        getNavigator(hsrqRequest).getRootURL(), thr.getCause());
1102      }
1103      finally
1104      {
1105         s_logger.exiting(this.getClass().getName(), "processNewEntryBlogForm");
1106      }
1107   }
1108
1109   /**
1110    * Process form to actually create new blog entry.
1111    *
1112    * @param hsrqRequest - the servlet request.
1113    * @param hsrpResponse - the servlet response.
1114    * @throws ServletException - an error while serving request
1115    * @throws IOException - an error while writing response
1116    */

1117   protected void processCreateEntryForm(
1118      HttpServletRequest JavaDoc hsrqRequest,
1119      HttpServletResponse JavaDoc hsrpResponse
1120   ) throws IOException JavaDoc,
1121            ServletException JavaDoc
1122   {
1123      s_logger.entering(this.getClass().getName(), "processCreateEntryForm");
1124
1125      UserTransaction JavaDoc transaction = null;
1126      try
1127      {
1128         transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
1129
1130         Object JavaDoc objBlogIdentification;
1131         Entry entry = parseEntryFromRequest(hsrqRequest);
1132         Entry entryUpdated = null;
1133         
1134         // Get the data for blog where user wants to create new entry
1135
objBlogIdentification = getNavigator(hsrqRequest).getBlogIdentification(
1136                                                                hsrqRequest);
1137                                                                
1138         // Since one request corresponds to user transaction and we know we are
1139
// going to modify data, start database transaction to group any
1140
// databast modification and queries we may need to execute to satisfy
1141
// this action.
1142
transaction.begin();
1143         entryUpdated = (Entry)getController().create(entry);
1144         assert entryUpdated != null : "Create should return not null value.";
1145         transaction.commit();
1146
1147         // Redirect user to the page displaying the blog
1148
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getBlogURL(
1149                                      objBlogIdentification));
1150      }
1151      catch (Throwable JavaDoc thr)
1152      {
1153         TransactionUtils.rollback(transaction);
1154         s_logger.log(Level.WARNING,
1155                      "An error has occured while creating new blog entry.", thr);
1156         messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1157                        getNavigator(hsrqRequest).getBlogURL(
1158                           getNavigator(hsrqRequest).getBlogIdentification(hsrqRequest)),
1159                        thr.getCause());
1160      }
1161      finally
1162      {
1163         s_logger.exiting(this.getClass().getName(), "processCreateEntryForm");
1164      }
1165   }
1166
1167   /**
1168    * Process form to save modified blog entry.
1169    *
1170    * @param hsrqRequest - the servlet request.
1171    * @param hsrpResponse - the servlet response.
1172    * @throws ServletException - an error while serving request
1173    * @throws IOException - an error while writing response
1174    */

1175   protected void processEditEntryForm(
1176      HttpServletRequest JavaDoc hsrqRequest,
1177      HttpServletResponse JavaDoc hsrpResponse
1178   ) throws IOException JavaDoc,
1179            ServletException JavaDoc
1180   {
1181      s_logger.entering(this.getClass().getName(), "processEditEntryForm");
1182
1183      UserTransaction JavaDoc transaction = null;
1184      Entry entry = null;
1185      try
1186      {
1187         transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
1188
1189         Object JavaDoc objBlogIdentification;
1190         Entry entryUpdated = null;
1191         
1192         entry = parseEntryFromRequest(hsrqRequest);
1193         // Get the data for blog where user wants to edit entry
1194
objBlogIdentification = getNavigator(hsrqRequest).getBlogIdentification(
1195                                                                hsrqRequest);
1196                                                                
1197         // Since one request corresponds to user transaction and we know we are
1198
// going to modify data, start database transaction to group any
1199
// databast modification and queries we may need to execute to satisfy
1200
// this action.
1201
transaction.begin();
1202         entryUpdated = (Entry)getController().save(entry);
1203         assert entryUpdated != null : "Save should return not null value.";
1204         transaction.commit();
1205
1206         // Redirect user to the page displaying the blog
1207
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getBlogURL(
1208                                      objBlogIdentification));
1209      }
1210      catch (OSSInvalidDataException ideExc)
1211      {
1212         TransactionUtils.rollback(transaction);
1213         CallContext.getInstance().getMessages().addMessages(
1214                                                    ideExc.getErrorMessages());
1215         // Return the submitted value
1216
processEditEntryError(hsrqRequest, hsrpResponse, entry);
1217      }
1218      catch (OSSConcurentModifyException ocmeExc)
1219      {
1220         TransactionUtils.rollback(transaction);
1221         CallContext.getInstance().getMessages().addErrorMessage(
1222                                                    ocmeExc.getMessage());
1223         // Return the submitted value
1224
processEditEntryError(hsrqRequest, hsrpResponse, entry);
1225      }
1226      catch (Throwable JavaDoc thr)
1227      {
1228         TransactionUtils.rollback(transaction);
1229         s_logger.log(Level.WARNING,
1230                      "An error has occured while saving blog entry.", thr);
1231         try
1232         {
1233            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1234                           getNavigator(hsrqRequest).getURL(
1235                              getNavigator(hsrqRequest).getBlogEntryIdentification(hsrqRequest)),
1236                              thr.getCause());
1237         }
1238         catch (Exception JavaDoc eExc2)
1239         {
1240            s_logger.log(Level.SEVERE,
1241                         "An error has occured while generating error message.",
1242                         thr);
1243            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1244                           WebCommonConstants.DEFAULT_DIRECTORY_WEB_PAGE,
1245                           eExc2.getCause());
1246         }
1247      }
1248      finally
1249      {
1250         s_logger.exiting(this.getClass().getName(), "processEditEntryForm");
1251      }
1252   }
1253
1254   /**
1255    * Process recoverable error, which has occured while saving entry. This will
1256    * show again the edit entry page but with the modified data and explanative
1257    * error message.
1258    *
1259    * @param hsrqRequest - the servlet request.
1260    * @param hsrpResponse - the servlet response.
1261    * @param entry - entry with modified data submitted to the server
1262    * @throws ServletException - an error while serving request
1263    * @throws IOException - an error while writing response
1264    */

1265   protected void processEditEntryError(
1266      HttpServletRequest JavaDoc hsrqRequest,
1267      HttpServletResponse JavaDoc hsrpResponse,
1268      Entry entry
1269   ) throws IOException JavaDoc,
1270            ServletException JavaDoc
1271   {
1272      try
1273      {
1274         Blog blog = (Blog)getController().get(entry.getParentId());
1275         
1276         if (blog != null)
1277         {
1278            hsrqRequest.setAttribute("blog", blog);
1279            hsrqRequest.setAttribute("blogentry", entry);
1280            hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
1281            displayUI(BLOGBROWSER_BLOGENTRY_VIEWER_PAGE, hsrqRequest, hsrpResponse);
1282         }
1283         else
1284         {
1285            // We have not found either the blog or the entry so tell the user
1286
// about it
1287
hsrpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
1288         }
1289      }
1290      catch (Exception JavaDoc eExc)
1291      {
1292         s_logger.log(Level.WARNING,
1293                      "An error has occured while retrieving blog entry.",
1294                      eExc);
1295         messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
1296                        getNavigator(hsrqRequest).getRootURL(), eExc.getCause());
1297      }
1298   }
1299   
1300   /**
1301    * Process form to display dialog to confirm deletion of a blog entry.
1302    *
1303    * @param hsrqRequest - the servlet request.
1304    * @param hsrpResponse - the servlet response.
1305    * @throws ServletException - an error while serving request
1306    * @throws IOException - an error while writing response
1307    */

1308   protected void processConfirmDeleteEntryForm(
1309      HttpServletRequest JavaDoc hsrqRequest,
1310      HttpServletResponse JavaDoc hsrpResponse
1311   ) throws IOException JavaDoc,
1312            ServletException JavaDoc
1313   {
1314      s_logger.entering(this.getClass().getName(), "processConfirmDeleteEntryForm");
1315
1316      try
1317      {
1318         BlogEntryIdentification entryIdentification;
1319         Object JavaDoc[] arObjects = null;
1320
1321         // Get the information about blog and entry to delete
1322
entryIdentification = getNavigator(hsrqRequest).getBlogEntryIdentification(
1323                                                            hsrqRequest);
1324         if (entryIdentification != null)
1325         {
1326            Object JavaDoc objBlogIdentification;
1327            
1328            objBlogIdentification= entryIdentification.getBlogIdentification();
1329            if (objBlogIdentification instanceof Integer JavaDoc)
1330            {
1331               arObjects = getController().getWithEntry(
1332                        ((Integer JavaDoc)objBlogIdentification).intValue(),
1333                        entryIdentification.getBlogEntryIdentification());
1334            }
1335            else
1336            {
1337               arObjects = getController().getWithEntry(
1338                              objBlogIdentification.toString(),
1339                              entryIdentification.getBlogEntryIdentification());
1340            }
1341         }
1342         
1343         if (arObjects != null)
1344         {
1345            if (arObjects[0] != null)
1346            {
1347               hsrqRequest.setAttribute("blog", arObjects[0]);
1348            }
1349            if (arObjects[1] != null)
1350            {
1351               hsrqRequest.setAttribute("blogentry", arObjects[1]);
1352            }
1353         }
1354         
1355         hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest));
1356         displayUI(BLOGEDIT_CONFIRMDELETE_BLOGENTRY_PAGE, hsrqRequest, hsrpResponse);
1357      }
1358      catch (Throwable JavaDoc thr)
1359      {
1360         s_logger.log(Level.WARNING,
1361                      "An error has occured while retrieving information" +
1362                      " about blog entry to delete.", thr);
1363         try
1364         {
1365            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1366                           getNavigator(hsrqRequest).getURL(
1367                              getNavigator(hsrqRequest).getBlogEntryIdentification(hsrqRequest)),
1368                              thr.getCause());
1369         }
1370         catch (Exception JavaDoc eExc2)
1371         {
1372            s_logger.log(Level.SEVERE,
1373                         "An error has occured while generating error message.",
1374                         thr);
1375            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1376                           WebCommonConstants.DEFAULT_DIRECTORY_WEB_PAGE,
1377                           eExc2.getCause());
1378         }
1379      }
1380      finally
1381      {
1382         s_logger.exiting(this.getClass().getName(), "processConfirmDeleteEntryForm");
1383      }
1384   }
1385
1386   /**
1387    * Process form to delete specified blog entry.
1388    *
1389    * @param hsrqRequest - the servlet request.
1390    * @param hsrpResponse - the servlet response.
1391    * @throws ServletException - an error while serving request
1392    * @throws IOException - an error while writing response
1393    */

1394   protected void processDeleteEntryForm(
1395      HttpServletRequest JavaDoc hsrqRequest,
1396      HttpServletResponse JavaDoc hsrpResponse
1397   ) throws IOException JavaDoc,
1398            ServletException JavaDoc
1399   {
1400      s_logger.entering(this.getClass().getName(), "processDeleteEntryForm");
1401
1402      UserTransaction JavaDoc transaction = null;
1403      try
1404      {
1405         transaction = DatabaseTransactionFactoryImpl.getInstance().requestTransaction();
1406
1407         Object JavaDoc objBlogIdentification;
1408         Entry entry = parseEntryFromRequest(hsrqRequest);
1409         
1410         // Get the data for blog where user wants to delete new entry
1411
objBlogIdentification = getNavigator(hsrqRequest).getBlogIdentification(
1412                                                                hsrqRequest);
1413
1414         // Since one request corresponds to user transaction and we know we are
1415
// going to modify data, start database transaction to group any
1416
// databast modification and queries we may need to execute to satisfy
1417
// this action.
1418
transaction.begin();
1419         getController().deleteEntry(entry.getId());
1420         transaction.commit();
1421         
1422         // Redirect user to the page displaying blog which contained now deleted entry
1423
hsrpResponse.sendRedirect(getNavigator(hsrqRequest).getBlogURL(
1424                                      objBlogIdentification));
1425      }
1426      catch (Throwable JavaDoc thr)
1427      {
1428         TransactionUtils.rollback(transaction);
1429         s_logger.log(Level.WARNING,
1430                      "An error has occured while deleting blog entry.", thr);
1431         try
1432         {
1433            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1434                           getNavigator(hsrqRequest).getURL(
1435                              getNavigator(hsrqRequest).getBlogEntryIdentification(hsrqRequest)),
1436                              thr.getCause());
1437         }
1438         catch (Exception JavaDoc eExc2)
1439         {
1440            s_logger.log(Level.SEVERE,
1441                         "An error has occured while generating error message.",
1442                         thr);
1443            messageBoxPage(hsrqRequest, hsrpResponse, "Error", thr.getMessage(),
1444                           WebCommonConstants.DEFAULT_DIRECTORY_WEB_PAGE,
1445                           eExc2.getCause());
1446         }
1447      }
1448      finally
1449      {
1450         s_logger.exiting(this.getClass().getName(), "processDeleteEntryForm");
1451      }
1452   }
1453
1454   /**
1455    * Create new instance of blog from a HTTP request.
1456    *
1457    * @param hsrqRequest - HTTP request from HTML form
1458    * @return Blog
1459    */

1460   protected Blog parseBlogFromRequest(
1461      HttpServletRequest JavaDoc hsrqRequest
1462   )
1463   {
1464      String JavaDoc strTemp;
1465      int iBlogId;
1466      int iDomainId = DataObject.NEW_ID;
1467      String JavaDoc strFolder;
1468      String JavaDoc strCaption;
1469      String JavaDoc strComments;
1470      Timestamp JavaDoc creationDate;
1471      Timestamp JavaDoc modificationDate;
1472      
1473      strTemp = hsrqRequest.getParameter("BLOG_ID");
1474      if (strTemp == null)
1475      {
1476         throw new IllegalArgumentException JavaDoc("Blog id is not specified.");
1477      }
1478      iBlogId = Integer.parseInt(strTemp);
1479      
1480      iDomainId = CallContext.getInstance().getCurrentDomainId();
1481      
1482      strFolder = hsrqRequest.getParameter("BLOG_FOLDER");
1483      if (strFolder == null)
1484      {
1485         strFolder = "";
1486      }
1487      strCaption = hsrqRequest.getParameter("BLOG_CAPTION");
1488      if (strCaption == null)
1489      {
1490         strCaption = "";
1491      }
1492      strComments = hsrqRequest.getParameter("BLOG_COMMENTS");
1493      if (strComments == null)
1494      {
1495         strComments = "";
1496      }
1497      // User can never change creation date, therefore we require to store
1498
// it as the millisecond value since that is independent from the display format
1499
strTemp = hsrqRequest.getParameter("BLOG_CREATION_DATE");
1500      if (strTemp == null)
1501      {
1502         creationDate = null;
1503      }
1504      else
1505      {
1506         creationDate = DateUtils.parseTimestamp(strTemp);
1507      }
1508      // User can never change modification date, therefore we require to store
1509
// it as the millisecond value since that is independent from the display format
1510
strTemp = hsrqRequest.getParameter("BLOG_MODIFICATION_DATE");
1511      if (strTemp == null)
1512      {
1513         modificationDate = null;
1514      }
1515      else
1516      {
1517         modificationDate = DateUtils.parseTimestamp(strTemp);
1518      }
1519
1520      return new Blog(iBlogId, iDomainId, strFolder, strCaption, strComments,
1521                      creationDate, modificationDate);
1522   }
1523
1524   /**
1525    * Create new instance of blog entry from a HTTP request..
1526    *
1527    * @param hsrqRequest - HTTP request from HTML form
1528    * @return Entry
1529    */

1530   protected Entry parseEntryFromRequest(
1531      HttpServletRequest JavaDoc hsrqRequest
1532   )
1533   {
1534      String JavaDoc strTemp;
1535      int iEntryId;
1536      int iDomainId = DataObject.NEW_ID;
1537      int iBlogId;
1538      String JavaDoc strCaption;
1539      String JavaDoc strComments;
1540      String JavaDoc strImageURL;
1541      String JavaDoc strTargetURL;
1542      Timestamp JavaDoc creationDate;
1543      Timestamp JavaDoc modificationDate;
1544      
1545      strTemp = hsrqRequest.getParameter("BLOGENTRY_ID");
1546      if (strTemp == null)
1547      {
1548         throw new IllegalArgumentException JavaDoc("Entry id is not specified.");
1549      }
1550      iEntryId = Integer.parseInt(strTemp);
1551      
1552      iDomainId = CallContext.getInstance().getCurrentDomainId();
1553      
1554      strTemp = hsrqRequest.getParameter("BLOGENTRY_BLOG_ID");
1555      if (strTemp == null)
1556      {
1557         iBlogId = DataObject.NEW_ID;
1558      }
1559      else
1560      {
1561         iBlogId = Integer.parseInt(strTemp);
1562      }
1563      strCaption = hsrqRequest.getParameter("BLOGENTRY_CAPTION");
1564      if (strCaption == null)
1565      {
1566         strCaption = "";
1567      }
1568      strComments = hsrqRequest.getParameter("BLOGENTRY_COMMENTS");
1569      if (strComments == null)
1570      {
1571         strComments = "";
1572      }
1573      strImageURL = hsrqRequest.getParameter("BLOGENTRY_IMAGEURL");
1574      if (strImageURL == null)
1575      {
1576         strImageURL = "";
1577      }
1578      strTargetURL = hsrqRequest.getParameter("BLOGENTRY_TARGETURL");
1579      if (strTargetURL == null)
1580      {
1581         strTargetURL = "";
1582      }
1583      // User can never change creation date, therefore we require to store
1584
// it as the millisecond value since that is independent from the display format
1585
strTemp = hsrqRequest.getParameter("BLOGENTRY_CREATION_DATE");
1586      if (strTemp == null)
1587      {
1588         creationDate = null;
1589      }
1590      else
1591      {
1592         creationDate = DateUtils.parseTimestamp(strTemp);
1593      }
1594      // User can never change modification date, therefore we require to store
1595
// it as the millisecond value since that is independent from the display format
1596
strTemp = hsrqRequest.getParameter("BLOGENTRY_MODIFICATION_DATE");
1597      if (strTemp == null)
1598      {
1599         modificationDate = null;
1600      }
1601      else
1602      {
1603         modificationDate = DateUtils.parseTimestamp(strTemp);
1604      }
1605      
1606      return new Entry(iEntryId, iDomainId, iBlogId, strCaption, strComments,
1607                       strImageURL, strTargetURL, creationDate,
1608                       modificationDate);
1609   }
1610
1611   /**
1612    * {@inheritDoc}
1613    */

1614   protected Principal JavaDoc verifyLogin(
1615      HttpSession JavaDoc hsSession,
1616      HttpServletRequest JavaDoc hsrqRequest,
1617      HttpServletResponse JavaDoc hsrpResponse
1618   ) throws ServletException JavaDoc,
1619            IOException JavaDoc
1620   {
1621      Principal JavaDoc currentUser = null;
1622      
1623      if (getFormToProcess(hsrqRequest) == FORM_LOGIN_ID)
1624      {
1625         // User is trying to log in, so try to log him/her in
1626
final String JavaDoc strLogin;
1627         String JavaDoc strPassword;
1628         
1629         strLogin = hsrqRequest.getParameter("LOGIN");
1630         strPassword = hsrqRequest.getParameter("PASSWORD");
1631
1632         // Verify the user name and password and if it is valid, let the
1633
// user proceed otherwise return an error message
1634
if ((m_strLogin.equals(strLogin))
1635            && (m_strPassword.equals(strPassword)))
1636         {
1637            currentUser = new Principal JavaDoc()
1638            {
1639               public String JavaDoc getName()
1640               {
1641                  return strLogin;
1642               }
1643            };
1644         }
1645         else
1646         {
1647            CallContext.getInstance().getMessages().addErrorMessage(
1648               "The user name or password is not valid.");
1649            // User have tried to login again so reset the info from previous
1650
// login since it is no longer valid
1651
WebSessionUtils.resetSessionAndUserInfo(hsSession);
1652         }
1653      }
1654      else
1655      {
1656         // User is not trying to log in so see if he is already logged in
1657
if (WebSessionUtils.isLoggedIn(hsSession))
1658         {
1659            currentUser = WebSessionUtils.getLoggedInUserInfo(hsSession);
1660         }
1661      }
1662      
1663      return currentUser;
1664   }
1665   
1666   /**
1667    * {@inheritDoc}
1668    */

1669   protected void redirectToLogin(
1670      HttpServletRequest JavaDoc hsrqRequest,
1671      HttpServletResponse JavaDoc hsrpResponse
1672   ) throws ServletException JavaDoc,
1673             IOException JavaDoc
1674   {
1675      BlogNavigator navigator = getNavigator(hsrqRequest);
1676      
1677      if (navigator.isLoginPage())
1678      {
1679         // User is already trying to display login page, just show it
1680
processNewLoginForm(hsrqRequest, hsrpResponse);
1681      }
1682      else
1683      {
1684         // We were asked to display login page so just let client go to the
1685
// the login page to get correct URL to the address bar and we will
1686
// most likely come back through the if above
1687
super.redirectToLogin(hsrqRequest, hsrpResponse);
1688      }
1689   }
1690}
1691
Popular Tags