KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > www > ListBrowserServlet


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListBrowserServlet.java,v 1.26 2007/02/20 04:17:00 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.patterns.listdata.www;
23
24 import java.io.IOException JavaDoc;
25 import java.sql.Timestamp JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33
34 import javax.servlet.ServletConfig JavaDoc;
35 import javax.servlet.ServletException JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38
39 import org.opensubsystems.core.data.DataConstant;
40 import org.opensubsystems.core.data.DataObject;
41 import org.opensubsystems.core.error.OSSException;
42 import org.opensubsystems.core.logic.ControllerManager;
43 import org.opensubsystems.core.util.DateUtils;
44 import org.opensubsystems.core.util.GlobalConstants;
45 import org.opensubsystems.core.util.Log;
46 import org.opensubsystems.core.util.StringUtils;
47 import org.opensubsystems.core.www.WebUIServlet;
48 import org.opensubsystems.core.www.WebUtils;
49 import org.opensubsystems.patterns.listdata.data.DataCondition;
50 import org.opensubsystems.patterns.listdata.data.ListDefinition;
51 import org.opensubsystems.patterns.listdata.data.ListOptions;
52 import org.opensubsystems.patterns.listdata.data.SimpleRule;
53 import org.opensubsystems.patterns.listdata.logic.ListController;
54
55 /**
56  * Servlet responsible for loading list of data objects based on various
57  * criteria at specified position within larger set of data. This servlet
58  * contains read-only functionality so it can be safely used, when user isn't
59  * be allowed to modify the data.
60  *
61  * @version $Id: ListBrowserServlet.java,v 1.26 2007/02/20 04:17:00 bastafidli Exp $
62  * @author Julo Legeny
63  * @code.reviewer Miro Halas
64  * @code.reviewed 1.21 2006/06/05 05:51:26 bastafidlis
65  */

66 public class ListBrowserServlet extends WebUIServlet
67 {
68    // Configuration settings ///////////////////////////////////////////////////
69

70    /**
71     * Name of the property for page which is the main entry point to the list.
72     */

73    public static final String JavaDoc LISTBROWSER_LIST_MAIN_PAGE
74                                  = "oss.listbrowser.list.page";
75
76    /**
77     * Names of the list options parameter in request forward.
78     */

79    public static final String JavaDoc LISTBROWSER_DATA_FACTORY_CLASS_NAME
80                                    = "oss.listbrowser.datafactory.classname";
81
82    // Constants ////////////////////////////////////////////////////////////////
83

84    /**
85     * Constant for special ID extention separator.
86     */

87    public static final String JavaDoc LISTBROWSER_ITEM_ID_EXTENTION_SEPARATOR = "_";
88
89    /**
90     * Names of the data object list parameter in request forward.
91     */

92    public static final String JavaDoc PARAMETER_DATA_OBJECT_LIST_NAME = "listdata";
93
94    /**
95     * Names of the data object list parameter in request forward.
96     */

97    public static final String JavaDoc PARAMETER_GENERIC_DATA_LIST_NAME
98                                  = "listdefinitiondata";
99
100    /**
101     * Names of the list options parameter in request forward.
102     */

103    public static final String JavaDoc PARAMETER_LIST_OPTIONS_NAME = "listoptions";
104    
105    /**
106     * Names of the extra condition parameter in request forward.
107     */

108    public static final String JavaDoc PARAMETER_EXTRA_CONDITION_NAME = "extracondition";
109
110    // Action string codes for GUI -> Servlet interface
111

112    /**
113     * Names of the action to display list with default parameters.
114     */

115    public static final String JavaDoc ACTION_SHOW_LIST_NAME = "show";
116    
117    /**
118     * Names of the action to submit list filter change.
119     */

120    public static final String JavaDoc ACTION_SET_FILTER_NAME = "filter";
121
122    /**
123     * Names of the action to submit order change.
124     */

125    public static final String JavaDoc ACTION_SET_ORDER_NAME = "order";
126
127    /**
128     * Names of the action to submit page size change.
129     */

130    public static final String JavaDoc ACTION_PAGE_SIZE_NAME = "pagesize";
131
132    /**
133     * Names of the action to display previous page.
134     */

135    public static final String JavaDoc ACTION_PREV_PAGE_NAME = "previous";
136
137    /**
138     * Names of the action to display next page.
139     */

140    public static final String JavaDoc ACTION_NEXT_PAGE_NAME = "next";
141
142    /**
143     * Names of the action to display specific page.
144     */

145    public static final String JavaDoc ACTION_GO_TO_PAGE_NAME = "goto";
146
147    // Action int codes for ListOptions parameter value and switch of actions
148

149    /**
150     * Names of the action to display list with default parameters.
151     */

152    public static final int ACTION_SHOW_LIST_ID = FORM_COUNT_WEBUI + 1;
153    
154    /**
155     * Names of the action to submit list filter change.
156     */

157    public static final int ACTION_SET_FILTER_ID = FORM_COUNT_WEBUI + 2;
158
159    /**
160     * Names of the action to submit order change ascending.
161     */

162    public static final int ACTION_SET_ORDER_ID = FORM_COUNT_WEBUI + 3;
163
164    /**
165     * Names of the action to submit page size change.
166     */

167    public static final int ACTION_PAGE_SIZE_ID = FORM_COUNT_WEBUI + 4;
168
169    /**
170     * Names of the action to display previous page.
171     */

172    public static final int ACTION_PREV_PAGE_ID = FORM_COUNT_WEBUI + 5;
173
174    /**
175     * Names of the action to display next page.
176     */

177    public static final int ACTION_NEXT_PAGE_ID = FORM_COUNT_WEBUI + 6;
178
179    /**
180     * Names of the action to display specific page.
181     */

182    public static final int ACTION_GO_TO_PAGE_ID = FORM_COUNT_WEBUI + 7;
183
184    /**
185     * How many actions this servlet recognizes.
186     */

187    public static final int FORM_COUNT_LISTBROWSER = FORM_COUNT_WEBUI + 8;
188    
189    // Names of the parameters specifying values for ListOptions to load the list
190

191    /**
192     * Parameter used to identify filter to apply to the list.
193     */

194    public static final String JavaDoc LIST_PARAM_LIST_FILTER_ID = "LIST_FILTER_ID";
195    
196    /**
197     * Parameter used to specify how many items to retrieve at once.
198     */

199    public static final String JavaDoc LIST_PARAM_LIST_PAGE_SIZE = "LIST_PAGE_SIZE";
200    
201    /**
202     * Parameter used to specify what column(s) to use for sorting the list.
203     */

204    public static final String JavaDoc LIST_PARAM_ORDER_CODE = "ORDER_CODE";
205    
206    /**
207     * Parameter used to specify what directions should the list be sorted in.
208     */

209    public static final String JavaDoc LIST_PARAM_ORDER_TYPE = "ORDER_TYPE";
210    
211    /**
212     * Parameter used to specify what column(s) to use for sorting the loaded
213     * portion of the data on the client.
214     */

215    public static final String JavaDoc LIST_PARAM_CLIENT_ORDER_CODE = "CLIENT_ORDER_CODE";
216    
217    /**
218     * Parameter used to specify what directions should the loaded portion of the
219     * data be sorted on the client.
220     */

221    public static final String JavaDoc LIST_PARAM_CLIENT_ORDER_TYPE = "CLIENT_ORDER_TYPE";
222    
223    /**
224     * Parameter used to specify the position of the first loaded item in the list.
225     */

226    public static final String JavaDoc LIST_PARAM_BEGIN_POSITION = "BEGIN_POSITION";
227    
228    /**
229     * Parameter used to specify the position of the last loaded item in the list.
230     */

231    public static final String JavaDoc LIST_PARAM_END_POSITION = "END_POSITION";
232    
233    /**
234     * Parameter used to specify the actual page of the loaded items.
235     */

236    public static final String JavaDoc LIST_PARAM_ACTUAL_PAGE = "ACTUAL_PAGE";
237    
238    /**
239     * Parameter used to specify what columns to display for each item in the
240     * list on the client.
241     */

242    public static final String JavaDoc LIST_PARAM_SHOW_COLUMN_CODES = "SHOW_COLUMN_CODES";
243    
244    /**
245     * Parameter used to specify what should be the first visible item from the
246     * list of loaded items on the client (for example in the case the list is
247     * too long and needs to be scrolled to show the specific item).
248     */

249    public static final String JavaDoc LIST_PARAM_FIRST_VISIBLE_ITEM
250                                  = "FIRST_VISIBLE_ITEM";
251    
252    /**
253     * Parameter specifying comma separated list of selected items.
254     */

255    public static final String JavaDoc LIST_PARAM_SELECTED_ITEMS = "SELECTED_ITEMS";
256    
257    /**
258     * Parameter specifying comma separated list of highlighted items.
259     */

260    public static final String JavaDoc LIST_PARAM_MARKED_ITEMS = "MARKED_ITEMS";
261
262    /**
263     * Parameter specifying comma separated list of items to do not load.
264     */

265    public static final String JavaDoc LIST_PARAM_IGNORED_ITEMS = "IGNORED_ITEMS";
266    
267    /**
268     * Parameter specifying data type of item which should be parent to all
269     * loaded items in the list.
270     */

271    public static final String JavaDoc LIST_PARAM_LIST_PARENT_DATA_TYPE
272                                  = "LIST_PARENT_DATA_TYPE";
273    
274    /**
275     * Parameter specifying identification of item which should be parent to all
276     * loaded items in the list.
277     */

278    public static final String JavaDoc LIST_PARAM_LIST_PARENT_IDENTIFIER
279                                  = "LIST_PARENT_IDENTIFIER";
280    
281    /**
282     * Parameter specifying if the selected items should be loaded even if they
283     * wouldn't be normally in the list.
284     */

285    public static final String JavaDoc LIST_PARAM_KEEP_SELECTED = "KEEP_SELECTED";
286    
287    /**
288     * Parameter specifying id of the domain from which to load items.
289     */

290    public static final String JavaDoc LIST_PARAM_LIST_DOMAIN_ID = "LIST_DOMAIN_ID";
291    
292    /**
293     * Parameter specifying what attribute of the items in the list does the
294     * extra condition applies to.
295     */

296    public static final String JavaDoc LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE
297                                  = "EXTRA_CONDITION_ATTRIBUTE";
298    
299    /**
300     * Parameter specifying what operations to apply on the attribute of the
301     * items in the list does the extra condition applies to.
302     */

303    public static final String JavaDoc LIST_PARAM_EXTRA_CONDITION_OPERAND
304                                  = "EXTRA_CONDITION_OPERAND";
305    
306    /**
307     * Parameter specifying type of value for the operation applied to the
308     * attribute of the items in the list does the extra condition applies to.
309     */

310    public static final String JavaDoc LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE
311                                  = "EXTRA_CONDITION_VALUE_TYPE";
312    
313    /**
314     * Parameter specifying the value for the operation applied to the
315     * attribute of the items in the list does the extra condition applies to.
316     */

317    public static final String JavaDoc LIST_PARAM_EXTRA_CONDITION_VALUE
318                                  = "EXTRA_CONDITION_VALUE";
319    
320    // Cached values ////////////////////////////////////////////////////////////
321

322    /**
323     * Logger for this class
324     */

325    private static Logger JavaDoc s_logger = Log.getInstance(ListBrowserServlet.class);
326
327    // Attributes ///////////////////////////////////////////////////////////////
328

329    /**
330     * Generated serial version id for this class.
331     */

332    private static final long serialVersionUID = -5132755699822556778L;
333
334    /**
335     * List data factory class name to be used by this servlet
336     */

337    protected String JavaDoc m_strFactoryClassName;
338    
339    /**
340     * Class representing the factory used to load data
341     */

342    protected Class JavaDoc m_clsFactory;
343    
344    // Public methods ///////////////////////////////////////////////////////////
345

346    /**
347     * {@inheritDoc}
348     */

349    public void init(
350       ServletConfig JavaDoc scConfig
351    ) throws ServletException JavaDoc
352    {
353       super.init(scConfig);
354
355       // Load UI page for list display
356
cacheUIPath(scConfig, LISTBROWSER_LIST_MAIN_PAGE,
357                   "Path to main list page is not set in property "
358                   + LISTBROWSER_LIST_MAIN_PAGE);
359
360       m_strFactoryClassName = WebUtils.readProperty(scConfig,
361                                 LISTBROWSER_DATA_FACTORY_CLASS_NAME,
362                                 null, false);
363       s_logger.config(LISTBROWSER_DATA_FACTORY_CLASS_NAME + " = "
364                       + m_strFactoryClassName);
365       if (m_strFactoryClassName == null)
366       {
367          throw new ServletException JavaDoc("Name of list data factory is not specified in property "
368                                      + LISTBROWSER_DATA_FACTORY_CLASS_NAME);
369       }
370       try
371       {
372          m_clsFactory = Class.forName(m_strFactoryClassName);
373       }
374       catch (ClassNotFoundException JavaDoc cnfExc)
375       {
376          throw new ServletException JavaDoc("Cannot create class " + m_strFactoryClassName,
377                                     cnfExc);
378       }
379    }
380
381    /**
382     * {@inheritDoc}
383     */

384    public String JavaDoc getServletInfo(
385    )
386    {
387       return this.getClass().getName();
388    }
389
390    // Helper methods ///////////////////////////////////////////////////////////
391

392    /**
393     * {@inheritDoc}
394     */

395    protected void doGet(
396       HttpServletRequest JavaDoc hsrqRequest,
397       HttpServletResponse JavaDoc hsrpResponse
398    ) throws ServletException JavaDoc,
399             IOException JavaDoc
400    {
401       switch (getFormToProcess(hsrqRequest))
402       {
403          case ACTION_SHOW_LIST_ID :
404          {
405             processShowList(hsrqRequest, hsrpResponse);
406             break;
407          }
408          case ACTION_SET_FILTER_ID :
409          {
410             processSetListFilter(hsrqRequest, hsrpResponse);
411             break;
412          }
413          case ACTION_SET_ORDER_ID :
414          {
415             processSetOrder(hsrqRequest, hsrpResponse);
416             break;
417          }
418          case ACTION_PAGE_SIZE_ID :
419          {
420             processSetPageSize(hsrqRequest, hsrpResponse);
421             break;
422          }
423          case ACTION_PREV_PAGE_ID :
424          {
425             processSetPrevPage(hsrqRequest, hsrpResponse);
426             break;
427          }
428          case ACTION_NEXT_PAGE_ID :
429          {
430             processSetNextPage(hsrqRequest, hsrpResponse);
431             break;
432          }
433          case ACTION_GO_TO_PAGE_ID :
434          {
435             processSetExactPage(hsrqRequest, hsrpResponse);
436             break;
437          }
438          default :
439          {
440             super.doGet(hsrqRequest, hsrpResponse);
441             break;
442          }
443       }
444    }
445    
446    /**
447     * {@inheritDoc}
448     */

449    protected void doPost(
450       HttpServletRequest JavaDoc hsrqRequest,
451       HttpServletResponse JavaDoc hsrpResponse
452    ) throws ServletException JavaDoc,
453             IOException JavaDoc
454    {
455       switch (getFormToProcess(hsrqRequest))
456       {
457          case ACTION_SHOW_LIST_ID :
458          {
459             processShowList(hsrqRequest, hsrpResponse);
460             break;
461          }
462          case ACTION_SET_FILTER_ID :
463          {
464             processSetListFilter(hsrqRequest, hsrpResponse);
465             break;
466          }
467          case ACTION_SET_ORDER_ID :
468          {
469             processSetOrder(hsrqRequest, hsrpResponse);
470             break;
471          }
472          case ACTION_PAGE_SIZE_ID :
473          {
474             processSetPageSize(hsrqRequest, hsrpResponse);
475             break;
476          }
477          case ACTION_PREV_PAGE_ID :
478          {
479             processSetPrevPage(hsrqRequest, hsrpResponse);
480             break;
481          }
482          case ACTION_NEXT_PAGE_ID :
483          {
484             processSetNextPage(hsrqRequest, hsrpResponse);
485             break;
486          }
487          case ACTION_GO_TO_PAGE_ID :
488          {
489             processSetExactPage(hsrqRequest, hsrpResponse);
490             break;
491          }
492          default :
493          {
494             super.doPost(hsrqRequest, hsrpResponse);
495             break;
496          }
497       }
498    }
499
500    /**
501     * Process action to show default list.
502     *
503     * @param hsrqRequest - the servlet request.
504     * @param hsrpResponse - the servlet response.
505     * @throws ServletException - an error while serving request
506     * @throws IOException - an error while writing response
507     */

508    protected void processShowList(
509       HttpServletRequest JavaDoc hsrqRequest,
510       HttpServletResponse JavaDoc hsrpResponse
511    ) throws IOException JavaDoc,
512             ServletException JavaDoc
513    {
514       s_logger.entering("ListBrowserServlet", "processShowList");
515       try
516       {
517          Object JavaDoc[] listInfo = getListController().getShowList(
518                                 parseListFromRequest(hsrqRequest,
519                                                      ACTION_SHOW_LIST_ID));
520          
521          completeAction(listInfo, hsrqRequest, hsrpResponse,
522                         LISTBROWSER_LIST_MAIN_PAGE);
523       }
524       catch (Throwable JavaDoc eExc)
525       {
526          s_logger.log(Level.WARNING,
527                       "An error has occured while retrieving information" +
528                       " about the default list.", eExc);
529          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
530             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
531       }
532       finally
533       {
534          s_logger.exiting("ListBrowseServlet", "processShowList");
535       }
536    }
537          
538    /**
539     * Process action to show list with new filter and its paramaters.
540     *
541     * @param hsrqRequest - the servlet request.
542     * @param hsrpResponse - the servlet response.
543     * @throws ServletException - an error while serving request
544     * @throws IOException - an error while writing response
545     */

546    protected void processSetListFilter(
547       HttpServletRequest JavaDoc hsrqRequest,
548       HttpServletResponse JavaDoc hsrpResponse
549    ) throws IOException JavaDoc,
550             ServletException JavaDoc
551    {
552       s_logger.entering("ListBrowserServlet", "processSetListFilter");
553       try
554       {
555          Object JavaDoc[] listInfo = getListController().getSetDefinition(
556                                 parseListFromRequest(hsrqRequest,
557                                                     ACTION_SET_FILTER_ID));
558          
559          completeAction(listInfo, hsrqRequest, hsrpResponse,
560                         LISTBROWSER_LIST_MAIN_PAGE);
561
562       }
563       catch (Throwable JavaDoc eExc)
564       {
565          s_logger.log(Level.WARNING,
566                       "An error has occured while retrieving information" +
567                       " about list with new filter set.", eExc);
568          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
569             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
570       }
571       finally
572       {
573          s_logger.exiting("ListBrowseServlet", "processSetListFilter");
574       }
575       
576    }
577
578    /**
579     * Process action to show list with new order column - ASC.
580     *
581     * @param hsrqRequest - the servlet request.
582     * @param hsrpResponse - the servlet response.
583     * @throws ServletException - an error while serving request
584     * @throws IOException - an error while writing response
585     */

586    protected void processSetOrder(
587       HttpServletRequest JavaDoc hsrqRequest,
588       HttpServletResponse JavaDoc hsrpResponse
589    ) throws IOException JavaDoc,
590             ServletException JavaDoc
591    {
592       s_logger.entering("ListBrowserServlet", "processSetOrder");
593       try
594       {
595          Object JavaDoc[] listInfo = getListController().getSetOrder(
596                                 parseListFromRequest(hsrqRequest,
597                                                      ACTION_SET_ORDER_ID));
598          
599          completeAction(listInfo, hsrqRequest, hsrpResponse,
600                         LISTBROWSER_LIST_MAIN_PAGE);
601
602       }
603       catch (Throwable JavaDoc eExc)
604       {
605          s_logger.log(Level.WARNING,
606                       "An error has occured while retrieving information" +
607                       " about list with order change.", eExc);
608          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
609             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
610       }
611       finally
612       {
613          s_logger.exiting("ListBrowseServlet", "processSetOrder");
614       }
615    }
616
617    /**
618     * Process action to show list for new page size.
619     *
620     * @param hsrqRequest - the servlet request.
621     * @param hsrpResponse - the servlet response.
622     * @throws ServletException - an error while serving request
623     * @throws IOException - an error while writing response
624     */

625    protected void processSetPageSize(
626       HttpServletRequest JavaDoc hsrqRequest,
627       HttpServletResponse JavaDoc hsrpResponse
628    ) throws IOException JavaDoc,
629             ServletException JavaDoc
630    {
631       s_logger.entering("ListBrowserServlet", "processSetPageSize");
632       try
633       {
634          Object JavaDoc[] listInfo = getListController().getSetPageSize(
635                                 parseListFromRequest(hsrqRequest,
636                                                      ACTION_PAGE_SIZE_ID));
637          
638          completeAction(listInfo, hsrqRequest, hsrpResponse,
639                         LISTBROWSER_LIST_MAIN_PAGE);
640
641       }
642       catch (Throwable JavaDoc eExc)
643       {
644          s_logger.log(Level.WARNING,
645                       "An error has occured while retrieving information" +
646                       " about list with new page size.", eExc);
647          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
648             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
649       }
650       finally
651       {
652          s_logger.exiting("ListBrowseServlet", "processSetPageSize");
653       }
654    }
655
656    /**
657     * Process action to show previous page of the list.
658     *
659     * @param hsrqRequest - the servlet request.
660     * @param hsrpResponse - the servlet response.
661     * @throws ServletException - an error while serving request
662     * @throws IOException - an error while writing response
663     */

664    protected void processSetPrevPage(
665       HttpServletRequest JavaDoc hsrqRequest,
666       HttpServletResponse JavaDoc hsrpResponse
667    ) throws IOException JavaDoc,
668             ServletException JavaDoc
669    {
670       s_logger.entering("ListBrowserServlet", "processSetPrevPage");
671       try
672       {
673          Object JavaDoc[] listInfo = getListController().getPreviousPage(
674                                 parseListFromRequest(hsrqRequest,
675                                                      ACTION_PREV_PAGE_ID));
676          
677          completeAction(listInfo, hsrqRequest, hsrpResponse,
678                         LISTBROWSER_LIST_MAIN_PAGE);
679
680       }
681       catch (Throwable JavaDoc eExc)
682       {
683          s_logger.log(Level.WARNING,
684                       "An error has occured while retrieving information" +
685                       " about previous page list.", eExc);
686          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
687             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
688       }
689       finally
690       {
691          s_logger.exiting("ListBrowseServlet", "processSetPrevPage");
692       }
693       
694    }
695
696    /**
697     * Process action to show next page of the list.
698     *
699     * @param hsrqRequest - the servlet request.
700     * @param hsrpResponse - the servlet response.
701     * @throws ServletException - an error while serving request
702     * @throws IOException - an error while writing response
703     */

704    protected void processSetNextPage(
705       HttpServletRequest JavaDoc hsrqRequest,
706       HttpServletResponse JavaDoc hsrpResponse
707    ) throws IOException JavaDoc,
708             ServletException JavaDoc
709    {
710       s_logger.entering("ListBrowserServlet", "processSetNextPage");
711       try
712       {
713          Object JavaDoc[] listInfo = getListController().getNextPage(
714                                 parseListFromRequest(hsrqRequest,
715                                                      ACTION_NEXT_PAGE_ID));
716          
717          completeAction(listInfo, hsrqRequest, hsrpResponse,
718                         LISTBROWSER_LIST_MAIN_PAGE);
719
720       }
721       catch (Throwable JavaDoc eExc)
722       {
723          s_logger.log(Level.WARNING,
724                       "An error has occured while retrieving information" +
725                       " about next page list.", eExc);
726          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
727             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
728       }
729       finally
730       {
731          s_logger.exiting("ListBrowseServlet", "processSetNextPage");
732       }
733    }
734
735    /**
736     * Process action to show exact-selected page of the list.
737     *
738     * @param hsrqRequest - the servlet request.
739     * @param hsrpResponse - the servlet response.
740     * @throws ServletException - an error while serving request
741     * @throws IOException - an error while writing response
742     */

743    protected void processSetExactPage(
744       HttpServletRequest JavaDoc hsrqRequest,
745       HttpServletResponse JavaDoc hsrpResponse
746    ) throws IOException JavaDoc,
747             ServletException JavaDoc
748    {
749       s_logger.entering("ListBrowserServlet", "processSetExactPage");
750       try
751       {
752          Object JavaDoc[] listInfo = getListController().getExactPage(
753                                 parseListFromRequest(hsrqRequest,
754                                                      ACTION_GO_TO_PAGE_ID));
755          
756          completeAction(listInfo, hsrqRequest, hsrpResponse,
757                         LISTBROWSER_LIST_MAIN_PAGE);
758       }
759       catch (Throwable JavaDoc eExc)
760       {
761          s_logger.log(Level.WARNING,
762                       "An error has occured while retrieving information" +
763                       " about exact page.", eExc);
764          messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(),
765             hsrqRequest.getContextPath() + hsrqRequest.getServletPath(), eExc);
766       }
767       finally
768       {
769          s_logger.exiting("ListBrowseServlet", "processSetExactPage");
770       }
771    }
772     
773    // Helper methods for processing forms
774

775    /**
776     * {@inheritDoc}
777     */

778    protected int getFormToProcess(
779       HttpServletRequest JavaDoc hsrqRequest
780    )
781    {
782       String JavaDoc strActionName;
783       int iReturn = FORM_UNKNOWN_ID;
784
785       strActionName = hsrqRequest.getParameter(FORM_NAME_REQUEST_PARAM);
786
787       // See Java Performance Tuning page 151, equals runs faster than
788
// equalsIgnoreCase when Strings are identical
789
if (strActionName == null)
790       {
791          iReturn = ACTION_SHOW_LIST_ID;
792       }
793       else if (strActionName.equals(ACTION_SHOW_LIST_NAME))
794       {
795          // Create new weblog from already supplied details
796
iReturn = ACTION_SHOW_LIST_ID;
797       }
798       else if (strActionName.equals(ACTION_SET_FILTER_NAME))
799       {
800          // Create new weblog from already supplied details
801
iReturn = ACTION_SET_FILTER_ID;
802       }
803       else if (strActionName.equals(ACTION_SET_ORDER_NAME))
804       {
805          // Create new weblog from already supplied details
806
iReturn = ACTION_SET_ORDER_ID;
807       }
808       else if (strActionName.equals(ACTION_PAGE_SIZE_NAME))
809       {
810          // Create new weblog from already supplied details
811
iReturn = ACTION_PAGE_SIZE_ID;
812       }
813       else if (strActionName.equals(ACTION_PREV_PAGE_NAME))
814       {
815          // Create new weblog from already supplied details
816
iReturn = ACTION_PREV_PAGE_ID;
817       }
818       else if (strActionName.equals(ACTION_NEXT_PAGE_NAME))
819       {
820          // Create new weblog from already supplied details
821
iReturn = ACTION_NEXT_PAGE_ID;
822       }
823       else if (strActionName.equals(ACTION_GO_TO_PAGE_NAME))
824       {
825          // Create new weblog from already supplied details
826
iReturn = ACTION_GO_TO_PAGE_ID;
827       }
828       else
829       {
830          iReturn = ACTION_SHOW_LIST_ID;
831       }
832
833       return iReturn;
834    }
835
836    /**
837     * Create new instance of list from a HTTP request.
838     *
839     * @param hsrqRequest - HTTP request from HTML form
840     * @param actionCode - code of submited action
841     * @return ListOptions
842     * @throws OSSException - an error has occured while parsing request
843     */

844    protected ListOptions parseListFromRequest(
845       HttpServletRequest JavaDoc hsrqRequest,
846       int actionCode
847    ) throws OSSException
848    {
849       String JavaDoc strFilterID = DataObject.NEW_ID_STR;
850       int iPageSize = -1;
851       int iActualListSize = 0;
852       int[] arrOrderCodes = null;
853       String JavaDoc[] arrOrderTypes = null;
854       int iClientOrderCode = 0;
855       String JavaDoc strClientOrderType = ListDefinition.ORDER_ASCENDING;
856       int iBeginPosition = 0;
857       int iEndPosition = 0;
858       int iActualPage = 0;
859       int iFirstVisibleItem = 0;
860       int iParentDataType = DataConstant.NO_DATA_TYPE;
861       int iParentIdentifier = DataObject.NEW_ID;
862       String JavaDoc strSelectedItemIDs = null;
863       String JavaDoc strMarkedItemIDs = null;
864       int[] arrShowColumnCodes = null;
865       String JavaDoc strIgnoredItemIDs = null;
866       int iExtraConditionAttribute = DataCondition.NO_ATTRIBUTE;
867       int iExtraConditionOperand = DataCondition.NO_OPERAND;
868       Object JavaDoc oExtraConditionValue = null;
869       int iExtraConditionValueType = DataCondition.VALUE_TYPE_BOOLEAN;
870       boolean bKeepSelected = false;
871       int iDomainID = DataObject.NEW_ID;
872       String JavaDoc strTemp;
873       
874       strTemp = hsrqRequest.getParameter(LIST_PARAM_SELECTED_ITEMS);
875       if (strTemp != null)
876       {
877          strSelectedItemIDs = strTemp;
878       }
879
880       strTemp = hsrqRequest.getParameter(LIST_PARAM_MARKED_ITEMS);
881       if (strTemp != null)
882       {
883          strMarkedItemIDs = strTemp;
884       }
885
886       if (actionCode != ACTION_SHOW_LIST_ID)
887       {
888          strTemp = hsrqRequest.getParameter(
889                       ListBrowserServlet.LIST_PARAM_LIST_FILTER_ID);
890          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
891          {
892             // don't show exception if there is processed action for set filter
893
throw new IllegalArgumentException JavaDoc("Filter ID is not specified.");
894          }
895          strFilterID = strTemp;
896
897          strTemp = hsrqRequest.getParameter(LIST_PARAM_SHOW_COLUMN_CODES);
898          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
899          {
900             // don't show exception if there is processed action for set filter
901
throw new IllegalArgumentException JavaDoc("Show column codes are not specified.");
902          }
903          arrShowColumnCodes = StringUtils.parseStringToIntArray(strTemp, ",");
904
905          if (actionCode != ACTION_SET_FILTER_ID)
906          {
907             strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PAGE_SIZE);
908             if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
909             {
910                // don't show exception if there is processed action for set filter
911
throw new IllegalArgumentException JavaDoc("Page size is not specified.");
912             }
913             iPageSize = Integer.parseInt(strTemp);
914    
915             strTemp = hsrqRequest.getParameter(LIST_PARAM_ORDER_CODE);
916             if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
917             {
918                // don't show exception if there is processed action for set filter
919
throw new IllegalArgumentException JavaDoc("Order code is not specified.");
920             }
921             arrOrderCodes = StringUtils.parseStringToIntArray(strTemp, ",");
922    
923             strTemp = hsrqRequest.getParameter(LIST_PARAM_ORDER_TYPE);
924             if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
925             {
926                // don't show exception if there is processed action for set filter
927
throw new IllegalArgumentException JavaDoc("Order type is not specified.");
928             }
929             arrOrderTypes = StringUtils.parseStringToStringArray(strTemp, ",");
930          }
931       }
932
933       if (actionCode == ACTION_PAGE_SIZE_ID
934          || actionCode == ACTION_PREV_PAGE_ID
935          || actionCode == ACTION_NEXT_PAGE_ID
936          || actionCode == ACTION_GO_TO_PAGE_ID
937          )
938       {
939          strTemp = hsrqRequest.getParameter(LIST_PARAM_CLIENT_ORDER_CODE);
940          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
941          {
942             // don't show exception if there is processed action for set filter
943
throw new IllegalArgumentException JavaDoc("Client order code is not specified.");
944          }
945          iClientOrderCode = Integer.parseInt(strTemp);
946
947          strTemp = hsrqRequest.getParameter(LIST_PARAM_CLIENT_ORDER_TYPE);
948          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
949          {
950             // don't show exception if there is processed action for set filter
951
throw new IllegalArgumentException JavaDoc("Client order type is not specified.");
952          }
953          
954          if (ListDefinition.ORDER_ASCENDING.equals(strTemp))
955          {
956             strClientOrderType = ListDefinition.ORDER_ASCENDING;
957          }
958          else if (ListDefinition.ORDER_DESCENDING.equals(strTemp))
959          {
960             strClientOrderType = ListDefinition.ORDER_DESCENDING;
961          }
962          else
963          {
964             throw new IllegalArgumentException JavaDoc("Invalid value for client order " +
965                                                "type is specified.");
966          }
967
968          strTemp = hsrqRequest.getParameter(LIST_PARAM_FIRST_VISIBLE_ITEM);
969          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
970          {
971             // don't show exception if there is processed action for set filter
972
throw new IllegalArgumentException JavaDoc("First visible item is not specified.");
973          }
974          iFirstVisibleItem = Integer.parseInt(strTemp);
975       }
976
977       if (actionCode == ACTION_PAGE_SIZE_ID || actionCode == ACTION_PREV_PAGE_ID)
978       {
979          strTemp = hsrqRequest.getParameter(LIST_PARAM_BEGIN_POSITION);
980          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
981          {
982             // don't show exception if there is processed action for set filter
983
throw new IllegalArgumentException JavaDoc("Begin position is not specified.");
984          }
985          iBeginPosition = Integer.parseInt(strTemp);
986       }
987
988       if (actionCode == ACTION_NEXT_PAGE_ID)
989       {
990          strTemp = hsrqRequest.getParameter(LIST_PARAM_END_POSITION);
991          if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
992          {
993             // don't show exception if there is processed action for set filter
994
throw new IllegalArgumentException JavaDoc("End position is not specified.");
995          }
996          iEndPosition = Integer.parseInt(strTemp);
997       }
998
999       if (actionCode == ACTION_GO_TO_PAGE_ID)
1000      {
1001         strTemp = hsrqRequest.getParameter(LIST_PARAM_ACTUAL_PAGE);
1002         if ((strTemp == null) && (actionCode != ACTION_SET_FILTER_ID))
1003         {
1004            // don't show exception if there is processed action for set filter
1005
throw new IllegalArgumentException JavaDoc("Actual page is not specified.");
1006         }
1007         iActualPage = Integer.parseInt(strTemp);
1008      }
1009      
1010      strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PARENT_DATA_TYPE);
1011      if (strTemp != null)
1012      {
1013         iParentDataType = Integer.parseInt(strTemp);
1014      }
1015      
1016      strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_PARENT_IDENTIFIER);
1017      if (strTemp != null)
1018      {
1019         iParentIdentifier = Integer.parseInt(strTemp);
1020      }
1021      
1022      strTemp = hsrqRequest.getParameter(LIST_PARAM_IGNORED_ITEMS);
1023      if (strTemp != null)
1024      {
1025         strIgnoredItemIDs = strTemp;
1026      }
1027      
1028      strTemp = hsrqRequest.getParameter(LIST_PARAM_KEEP_SELECTED);
1029      if (strTemp != null)
1030      {
1031         bKeepSelected = Integer.parseInt(strTemp) == 1;
1032      }
1033
1034      strTemp = hsrqRequest.getParameter(LIST_PARAM_LIST_DOMAIN_ID);
1035      if (strTemp != null)
1036      {
1037         iDomainID = Integer.parseInt(strTemp);
1038      }
1039      
1040      //----- parse extra condition parameters -------
1041
strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE);
1042      if (strTemp != null)
1043      {
1044         iExtraConditionAttribute = Integer.parseInt(strTemp);
1045      }
1046      
1047      strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_OPERAND);
1048      if (strTemp != null)
1049      {
1050         iExtraConditionOperand = Integer.parseInt(strTemp);
1051      }
1052      
1053      strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE);
1054      if (strTemp != null)
1055      {
1056         iExtraConditionValueType = Integer.parseInt(strTemp);
1057      }
1058      
1059      //------ parse extra condition value --------
1060
strTemp = hsrqRequest.getParameter(LIST_PARAM_EXTRA_CONDITION_VALUE);
1061      if (strTemp != null && iExtraConditionAttribute != DataCondition.NO_ATTRIBUTE)
1062      {
1063         if (iExtraConditionOperand != DataCondition.OPERAND_IN
1064            && iExtraConditionOperand != DataCondition.OPERAND_NOT_IN)
1065         {
1066            // parse extra condition simple value
1067
switch (iExtraConditionValueType)
1068            {
1069               case (DataCondition.VALUE_TYPE_ID) :
1070               {
1071                  oExtraConditionValue = new Integer JavaDoc(Integer.parseInt(strTemp));
1072                  break;
1073               }
1074               case (DataCondition.VALUE_TYPE_BOOLEAN) :
1075               {
1076                  oExtraConditionValue = Boolean.valueOf(strTemp);
1077                  break;
1078               }
1079               case (DataCondition.VALUE_TYPE_INTEGER) :
1080               {
1081                  oExtraConditionValue = new Integer JavaDoc(Integer.parseInt(strTemp));
1082                  break;
1083               }
1084               case (DataCondition.VALUE_TYPE_DOUBLE) :
1085               {
1086                  oExtraConditionValue = new Double JavaDoc(Double.parseDouble(strTemp));
1087                  break;
1088               }
1089               case (DataCondition.VALUE_TYPE_STRING) :
1090               {
1091                  oExtraConditionValue = strTemp;
1092                  break;
1093               }
1094               case (DataCondition.VALUE_TYPE_TIMESTAMP) :
1095               {
1096                  oExtraConditionValue = DateUtils.parseTimestamp(strTemp);
1097                  break;
1098               }
1099               default :
1100               {
1101                  throw new IllegalArgumentException JavaDoc("Not supported extra condition value type.");
1102               }
1103            }
1104         }
1105         else
1106         {
1107            // parse extra condition multiple value (IN or NOT IN operands)
1108
List JavaDoc lstValues = StringUtils.parseStringToList(strTemp, ",");
1109            Integer JavaDoc[] arrInteger = null;
1110            Boolean JavaDoc[] arrBoolean = null;
1111            Double JavaDoc[] arrDouble = null;
1112            String JavaDoc[] arrString = null;
1113            Timestamp JavaDoc[] arrTimestamp = null;
1114            // init final arrays
1115
if (lstValues != null && lstValues.size() > 0)
1116            {
1117               switch (iExtraConditionValueType)
1118               {
1119                  case (DataCondition.VALUE_TYPE_ID) :
1120                  {
1121                     arrInteger = new Integer JavaDoc[lstValues.size()];
1122                     break;
1123                  }
1124                  case (DataCondition.VALUE_TYPE_BOOLEAN) :
1125                  {
1126                     arrBoolean = new Boolean JavaDoc[lstValues.size()];
1127                     break;
1128                  }
1129                  case (DataCondition.VALUE_TYPE_INTEGER) :
1130                  {
1131                     arrInteger = new Integer JavaDoc[lstValues.size()];
1132                     break;
1133                  }
1134                  case (DataCondition.VALUE_TYPE_DOUBLE) :
1135                  {
1136                     arrDouble = new Double JavaDoc[lstValues.size()];
1137                     break;
1138                  }
1139                  case (DataCondition.VALUE_TYPE_STRING) :
1140                  {
1141                     arrString = new String JavaDoc[lstValues.size()];
1142                     break;
1143                  }
1144                  case (DataCondition.VALUE_TYPE_TIMESTAMP) :
1145                  {
1146                     arrTimestamp = new Timestamp JavaDoc[lstValues.size()];
1147                     break;
1148                  }
1149                  default :
1150                  {
1151                     throw new IllegalArgumentException JavaDoc(
1152                              "Not supported extra condition value type.");
1153                  }
1154               }
1155               // fill arrays with objects
1156
int iCounter = 0;
1157               String JavaDoc strHelp;
1158               for (Iterator JavaDoc itHelp = lstValues.iterator(); itHelp.hasNext();)
1159               {
1160                  strHelp = (String JavaDoc) itHelp.next();
1161                  switch (iExtraConditionValueType)
1162                  {
1163                     case (DataCondition.VALUE_TYPE_ID) :
1164                     {
1165                        arrInteger[iCounter++] = new Integer JavaDoc(Integer.parseInt(strHelp));
1166                        break;
1167                     }
1168                     case (DataCondition.VALUE_TYPE_BOOLEAN) :
1169                     {
1170                        arrBoolean[iCounter++] = Boolean.valueOf(strHelp);
1171                        break;
1172                     }
1173                     case (DataCondition.VALUE_TYPE_INTEGER) :
1174                     {
1175                        arrInteger[iCounter++] = new Integer JavaDoc(Integer.parseInt(strHelp));
1176                        break;
1177                     }
1178                     case (DataCondition.VALUE_TYPE_DOUBLE) :
1179                     {
1180                        arrDouble[iCounter++] = new Double JavaDoc(Double.parseDouble(strHelp));
1181                        break;
1182                     }
1183                     case (DataCondition.VALUE_TYPE_STRING) :
1184                     {
1185                        arrString[iCounter++] = strHelp;
1186                        break;
1187                     }
1188                     case (DataCondition.VALUE_TYPE_TIMESTAMP) :
1189                     {
1190                        arrTimestamp[iCounter++] = DateUtils.parseTimestamp(strHelp);
1191                        break;
1192                     }
1193                     default :
1194                     {
1195                        throw new IllegalArgumentException JavaDoc(
1196                                       "Not supported extra condition value type.");
1197                     }
1198                  }
1199               }
1200               // set array to value object
1201
switch (iExtraConditionValueType)
1202               {
1203                  case (DataCondition.VALUE_TYPE_ID) :
1204                  {
1205                     oExtraConditionValue = arrInteger;
1206                     break;
1207                  }
1208                  case (DataCondition.VALUE_TYPE_BOOLEAN) :
1209                  {
1210                     oExtraConditionValue = arrBoolean;
1211                     break;
1212                  }
1213                  case (DataCondition.VALUE_TYPE_INTEGER) :
1214                  {
1215                     oExtraConditionValue = arrInteger;
1216                     break;
1217                  }
1218                  case (DataCondition.VALUE_TYPE_DOUBLE) :
1219                  {
1220                     oExtraConditionValue = arrDouble;
1221                     break;
1222                  }
1223                  case (DataCondition.VALUE_TYPE_STRING) :
1224                  {
1225                     oExtraConditionValue = arrString;
1226                     break;
1227                  }
1228                  case (DataCondition.VALUE_TYPE_TIMESTAMP) :
1229                  {
1230                     oExtraConditionValue = arrTimestamp;
1231                     break;
1232                  }
1233                  default :
1234                  {
1235                     throw new IllegalArgumentException JavaDoc(
1236                              "Not supported extra condition value type.");
1237                  }
1238               }
1239            }
1240         }
1241      }
1242
1243      ListOptions options = new ListOptions(
1244            m_clsFactory,
1245            strFilterID,
1246            iPageSize,
1247            iActualListSize,
1248            arrOrderCodes,
1249            arrOrderTypes,
1250            iClientOrderCode,
1251            strClientOrderType,
1252            iBeginPosition,
1253            iEndPosition,
1254            iActualPage,
1255            iFirstVisibleItem,
1256            iParentDataType,
1257            iParentIdentifier,
1258            strSelectedItemIDs,
1259            strMarkedItemIDs,
1260            arrShowColumnCodes,
1261            strIgnoredItemIDs,
1262            false, // for now no way to specify distinct
1263
bKeepSelected,
1264            iDomainID
1265         );
1266
1267      // add extra conditions
1268
if (iExtraConditionAttribute != DataCondition.NO_ATTRIBUTE)
1269      {
1270         DataCondition dcDataCondition = new DataCondition(
1271            iExtraConditionAttribute,
1272            iExtraConditionOperand,
1273            oExtraConditionValue,
1274            iExtraConditionValueType
1275         );
1276         
1277         List JavaDoc lstExtraConditions = new ArrayList JavaDoc();
1278         lstExtraConditions.add(dcDataCondition);
1279         
1280         SimpleRule extraRule = new SimpleRule(SimpleRule.LOGICAL_AND,
1281                                               lstExtraConditions);
1282         
1283         options.setExtraFilter(extraRule, SimpleRule.LOGICAL_AND);
1284      }
1285
1286      return options;
1287   }
1288   
1289   /**
1290    * Populate request and response with result of the operation.
1291    *
1292    * @param listInfo - returned list info {ListOption, List}
1293    * @param hsrqRequest - HTTP request
1294    * @param hsrpResponse - HTTP respons
1295    * @param strUIID - unique ID of the configuration parameter used to specify
1296    * UI to display. This is the same ID previously passed into
1297    * cacheUIPath method.
1298    * @throws Exception - en error has accured
1299    */

1300   protected void completeAction(
1301      Object JavaDoc[] listInfo,
1302      HttpServletRequest JavaDoc hsrqRequest,
1303      HttpServletResponse JavaDoc hsrpResponse,
1304      String JavaDoc strUIID
1305   ) throws Exception JavaDoc
1306   {
1307      if (GlobalConstants.ERROR_CHECKING)
1308      {
1309         assert (listInfo[0] != null) : "ListOptions should be never null";
1310      }
1311            
1312      ListOptions options = (ListOptions)listInfo[0];
1313      List JavaDoc lstDataObjects = (List JavaDoc)listInfo[1];
1314      int iDataType = ((Integer JavaDoc)listInfo[2]).intValue();
1315      DataObject data;
1316      StringBuffer JavaDoc sbSelectedItemIDsTemp = new StringBuffer JavaDoc();
1317      int[] selectedIds;
1318      Iterator JavaDoc itData;
1319      int iCounter;
1320      StringBuffer JavaDoc strFinalSelected = new StringBuffer JavaDoc();
1321      
1322      if ((lstDataObjects != null) && (lstDataObjects.size() > 0))
1323      {
1324         // We have to parse selected IDs to only numbers because in
1325
// some cases we are useing special extention with ID to recognize
1326
// type of the object (Index object - IndexPage, Document)
1327
if (options.getSelectedItemIDs() != null)
1328         {
1329            StringTokenizer JavaDoc stSelectedIds = new StringTokenizer JavaDoc(
1330                                                   options.getSelectedItemIDs(), ",");
1331            String JavaDoc strHelp;
1332            int iTemp;
1333         
1334            while ((stSelectedIds != null) && (stSelectedIds.hasMoreTokens()))
1335            {
1336               strHelp = stSelectedIds.nextToken();
1337               iTemp = strHelp.indexOf(LISTBROWSER_ITEM_ID_EXTENTION_SEPARATOR);
1338               if (iTemp > -1)
1339               {
1340                  strHelp = strHelp.substring(0, iTemp);
1341               }
1342               if (sbSelectedItemIDsTemp.length() > 0)
1343               {
1344                  sbSelectedItemIDsTemp.append(",");
1345               }
1346               sbSelectedItemIDsTemp.append(strHelp);
1347            }
1348         }
1349
1350         selectedIds = StringUtils.parseStringToIntArray(
1351               sbSelectedItemIDsTemp.toString(),
1352               ",");
1353
1354         if (selectedIds != null)
1355         {
1356            itData = lstDataObjects.iterator();
1357            
1358            while (itData.hasNext())
1359            {
1360               data = (DataObject) itData.next();
1361               for (iCounter = 0; iCounter < selectedIds.length; iCounter++)
1362               {
1363                  if (data.getId() == selectedIds[iCounter])
1364                  {
1365                     if (strFinalSelected.length() > 0)
1366                     {
1367                        strFinalSelected.append(",");
1368                     }
1369                     strFinalSelected.append(selectedIds[iCounter]);
1370                  }
1371               }
1372            }
1373         }
1374      }
1375      options.setSelectedItemIDs(strFinalSelected.toString());
1376
1377      hsrqRequest.setAttribute(PARAMETER_LIST_OPTIONS_NAME, options);
1378      
1379      if (lstDataObjects != null)
1380      {
1381         hsrqRequest.setAttribute(PARAMETER_DATA_OBJECT_LIST_NAME, lstDataObjects);
1382      }
1383
1384      if ((options.getExtraFilter() != null)
1385         && (options.getExtraFilter().getConditions().size() == 1))
1386      {
1387         hsrqRequest.setAttribute(PARAMETER_EXTRA_CONDITION_NAME,
1388                        options.getExtraFilter().getConditions().get(0));
1389      }
1390      else
1391      {
1392         hsrqRequest.setAttribute(PARAMETER_EXTRA_CONDITION_NAME,
1393                                  new DataCondition());
1394      }
1395
1396      // get list of generic data (data will be used for filling up filter combo box)
1397
List JavaDoc lstGenericData = getListController().getDefinitionList(iDataType);
1398      if (lstGenericData == null)
1399      {
1400         lstGenericData = Collections.EMPTY_LIST;
1401      }
1402      hsrqRequest.setAttribute(PARAMETER_GENERIC_DATA_LIST_NAME, lstGenericData);
1403
1404      displayUI(strUIID, hsrqRequest, hsrpResponse);
1405   }
1406
1407   /**
1408    * Get list controller to use during this request. This is in separate method
1409    * so it can be overriden and derived list controller can be supplied
1410    * forexample implementing security ;-).
1411    *
1412    * @return ListController - instance of controller to use to process requests
1413    * @throws OSSException - an error has occured
1414    */

1415   protected ListController getListController(
1416   ) throws OSSException
1417   {
1418      ListController controller;
1419      
1420      controller = (ListController)ControllerManager.getInstance(
1421                                                        ListController.class);
1422      
1423      return controller;
1424   }
1425}
1426
Popular Tags