1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.myportal.web;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.lang.StringUtils;
44
45 import fr.paris.lutece.plugins.myportal.business.Category;
46 import fr.paris.lutece.plugins.myportal.business.Widget;
47 import fr.paris.lutece.plugins.myportal.business.page.TabConfig;
48 import fr.paris.lutece.plugins.myportal.service.CategoryService;
49 import fr.paris.lutece.plugins.myportal.service.DefaultPageBuilderService;
50 import fr.paris.lutece.plugins.myportal.service.MyPortalPageService;
51 import fr.paris.lutece.plugins.myportal.service.MyPortalPlugin;
52 import fr.paris.lutece.plugins.myportal.service.WidgetService;
53 import fr.paris.lutece.plugins.myportal.util.auth.MyPortalUser;
54 import fr.paris.lutece.portal.service.i18n.I18nService;
55 import fr.paris.lutece.portal.service.message.SiteMessageException;
56 import fr.paris.lutece.portal.service.plugin.Plugin;
57 import fr.paris.lutece.portal.service.security.LuteceUser;
58 import fr.paris.lutece.portal.service.security.SecurityService;
59 import fr.paris.lutece.portal.service.security.UserNotSignedException;
60 import fr.paris.lutece.portal.service.spring.SpringContextService;
61 import fr.paris.lutece.portal.service.template.AppTemplateService;
62 import fr.paris.lutece.portal.service.util.AppLogService;
63 import fr.paris.lutece.portal.service.util.AppPathService;
64 import fr.paris.lutece.portal.service.util.AppPropertiesService;
65 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
66 import fr.paris.lutece.portal.web.xpages.XPage;
67 import fr.paris.lutece.portal.web.xpages.XPageApplication;
68 import fr.paris.lutece.util.html.HtmlTemplate;
69 import fr.paris.lutece.util.html.Paginator;
70 import fr.paris.lutece.util.url.UrlItem;
71
72
73
74
75 public class MyPortalApp implements XPageApplication
76 {
77
78 private static final String LINE = "-";
79 private static final String BEAN_MYPORTAL_WIDGETSERVICE = "myportal.widgetService";
80
81
82 private static final String TEMPLATE_MYPORTAL_PAGE = "skin/plugins/myportal/myportal.html";
83 private static final String TEMPLATE_BROWSE_CATEGORIES = "skin/plugins/myportal/browse_categories.html";
84 private static final String TEMPLATE_BROWSE_CATEGORIES_WIDGETS = "skin/plugins/myportal/browse_categories_widgets.html";
85 private static final String TEMPLATE_MYPORTAL_NAVIGATION = "skin/plugins/myportal/myportal_navigation.html";
86 private static final String TEMPLATE_MYPORTAL_ADD_TAB = "skin/plugins/myportal/myportal_add_tab.html";
87 private static final String TEMPLATE_MYPORTAL_EDIT_TAB = "skin/plugins/myportal/myportal_edit_tab.html";
88 private static final String TEMPLATE_MYPORTAL_EDIT_WIDGET = "skin/plugins/myportal/myportal_edit_widget.html";
89 private static final String TEMPLATE_BROWSE_ESSENTIAL_WIDGETS = "skin/plugins/myportal/browse_essential_widgets.html";
90 private static final String TEMPLATE_BROWSE_NEW_WIDGETS = "skin/plugins/myportal/browse_new_widgets.html";
91 private static final String TEMPLATE_SEARCH_WIDGETS = "skin/plugins/myportal/search_widgets.html";
92
93
94 private static final String PARAMETER_ID_WIDGET = "id_widget";
95 private static final String PARAMETER_TAB_NAME = "tab_name";
96 private static final String PARAMETER_WIDGET = "widget";
97 private static final String PARAMETER_COLUMN = "column";
98 private static final String PARAMETER_PORTAL_STATE = "portalState";
99 private static final String PARAMETER_CATEGORY_ID_CATEGORY = "category_id_category";
100 private static final String PARAMETER_ACTION = "action";
101 private static final String PARAMETER_SEARCH_WIDGETS_NAME = "search_widgets_name";
102 private static final String PARAMETER_TAB_INDEX = "tab_index";
103 private static final String PARAMETER_PAGE = "page";
104
105
106 private static final String MARK_WIDGETS = "widgets";
107 private static final String MARK_WIDGETS_LIST = "widgets_list";
108 private static final String MARK_LIST_TAB = "tabs_list";
109 private static final String MARK_BASE_URL = "base_url";
110 private static final String MARK_TAB_NAME = "tab_name";
111 private static final String MARK_CATEGORIES_LIST = "categories_list";
112 private static final String MARK_CATEGORY_ID_CATEGORY = "category_id_category";
113 private static final String MARK_PAGINATOR = "paginator";
114 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
115 private static final String MARK_WIDGETS_LIST_HTML = "widgets_list_html";
116 private static final String MARK_MYPORTAL_NAVIGATION_CONTENT = "myportal_navigation_content";
117 private static final String MARK_ACTION = "action";
118 private static final String MARK_PAGINATOR_URL_FOR_JS = "paginator_url_for_js";
119 private static final String MARK_SEARCH_WIDGETS_NAME = "search_widgets_name";
120 private static final String MARK_TAB_INDEX = "tab_index";
121 private static final String MARK_USER_WIDGET_IDS = "user_widget_ids";
122 private static final String MARK_WIDGET = "widget";
123 private static final String MARK_NB_COLUMNS = "nb_columns";
124
125
126 private static final String PROPERTY_PAGE_PATH = "myportal.myportal.pagePathLabel";
127 private static final String PROPERTY_PAGE_TITLE = "myportal.myportal.pageTitle";
128 private static final String PROPERTY_DEFAULT_LIST_WIDGET_PER_PAGE_IN_FO = "myportal.listWidgets.itemsPerPageInFO";
129 private static final String PROPERTY_URL_RETURN = "myportal.urlReturn";
130 private static final String PROPERTY_DEFAULT_COLUMN = "myportal.defaultColumn";
131
132
133 private static final String ACTION_BROWSE_CATEGORIES = "browse_categories";
134 private static final String ACTION_BROWSE_ESSENTIAL_WIDGETS = "browse_essential_widgets";
135 private static final String ACTION_BROWSE_NEW_WIDGETS = "browse_new_widgets";
136 private static final String ACTION_SEARCH_WIDGETS = "search_widgets";
137 private static final String ACTION_ADD_TAB = "add_tab";
138 private static final String ACTION_EDIT_TAB = "edit_tab";
139 private static final String ACTION_EDIT_WIDGET = "edit_widget";
140
141
142 private static final String JSP_URL_BROWSE_CATEGORIES_WIDGETS = "jsp/site/plugins/myportal/BrowseCategoriesWidgets.jsp";
143 private static final String JSP_URL_BROWSE_ESSENTIAL_WIDGETS = "jsp/site/plugins/myportal/BrowseEssentialWidgets.jsp";
144 private static final String JSP_URL_BROWSE_NEW_WIDGETS = "jsp/site/plugins/myportal/BrowseNewWidgets.jsp";
145 private static final String JSP_URL_SEARCH_WIDGETS = "jsp/site/plugins/myportal/SearchWidgets.jsp";
146
147
148 private MyPortalPageService _pageService = MyPortalPageService.getInstance( );
149 private WidgetService _widgetService = SpringContextService.getBean( BEAN_MYPORTAL_WIDGETSERVICE );
150
151 private CategoryService _categoryService = SpringContextService.getBean( CategoryService.BEAN_NAME );
152 private DefaultPageBuilderService _defaultPageBuilderService = SpringContextService.getBean( DefaultPageBuilderService.BEAN_NAME );
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin ) throws SiteMessageException
168 {
169 XPage page = new XPage( );
170
171 page.setTitle( I18nService.getLocalizedString( PROPERTY_PAGE_TITLE, request.getLocale( ) ) );
172 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_PAGE_PATH, request.getLocale( ) ) );
173
174 String strAction = request.getParameter( PARAMETER_ACTION );
175
176 if ( StringUtils.isNotBlank( strAction ) )
177 {
178 if ( ACTION_ADD_TAB.equals( strAction ) )
179 {
180 page.setContent( getMyPortalAddTab( request ) );
181 }
182 else
183 if ( ACTION_EDIT_TAB.equals( strAction ) )
184 {
185 page.setContent( getMyPortalEditTab( request ) );
186 }
187 else
188 if ( ACTION_EDIT_WIDGET.equals( strAction ) )
189 {
190 page.setContent( getMyPortalEditWidget( request ) );
191 }
192 else
193 {
194 page.setContent( getMyPortalNavigation( request ) );
195 }
196 }
197 else
198 {
199 String strWidgets = _pageService.getUserPage( getUser( request ), request );
200 Map<String, Object> model = new HashMap<String, Object>( );
201 model.put( MARK_WIDGETS, strWidgets );
202
203 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MYPORTAL_PAGE, request.getLocale( ), model );
204 page.setContent( template.getHtml( ) );
205 }
206
207 return page;
208 }
209
210
211
212
213
214
215
216
217 public String getMyPortalNavigation( HttpServletRequest request )
218 {
219 String strHtml = StringUtils.EMPTY;
220 String strAction = request.getParameter( PARAMETER_ACTION );
221
222 if ( StringUtils.isNotBlank( strAction ) )
223 {
224 String strNavigationContentHtml = StringUtils.EMPTY;
225 String strName = request.getParameter( PARAMETER_SEARCH_WIDGETS_NAME );
226 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
227
228 if ( strName == null )
229 {
230 strName = StringUtils.EMPTY;
231 }
232
233 Map<String, Object> model = new HashMap<String, Object>( );
234
235 if ( ACTION_BROWSE_CATEGORIES.equals( strAction ) )
236 {
237 strNavigationContentHtml = getBrowseCategories( request );
238 }
239 else
240 if ( ACTION_BROWSE_ESSENTIAL_WIDGETS.equals( strAction ) )
241 {
242 strNavigationContentHtml = getBrowseEssentialWidgets( request );
243 }
244 else
245 if ( ACTION_BROWSE_NEW_WIDGETS.equals( strAction ) )
246 {
247 strNavigationContentHtml = getBrowseNewWidgets( request );
248 }
249 else
250 if ( ACTION_SEARCH_WIDGETS.equals( strAction ) )
251 {
252 strNavigationContentHtml = getSearchWidgets( request );
253 }
254
255 String strBaseUrl = AppPathService.getBaseUrl( request );
256 model.put( MARK_BASE_URL, strBaseUrl );
257 model.put( MARK_ACTION, strAction );
258 model.put( MARK_MYPORTAL_NAVIGATION_CONTENT, strNavigationContentHtml );
259 model.put( MARK_SEARCH_WIDGETS_NAME, strName );
260 model.put( MARK_TAB_INDEX, strTabIndex );
261
262 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MYPORTAL_NAVIGATION, request.getLocale( ), model );
263 strHtml = template.getHtml( );
264 }
265
266 return strHtml;
267 }
268
269
270
271
272
273
274
275
276 public String getBrowseCategories( HttpServletRequest request )
277 {
278 String strCategoryId = request.getParameter( PARAMETER_CATEGORY_ID_CATEGORY );
279
280 if ( StringUtils.isBlank( strCategoryId ) )
281 {
282 Category category = _categoryService.findFirstCategory( );
283 strCategoryId = Integer.toString( category.getIdCategory( ) );
284 }
285
286 String strBaseUrl = AppPathService.getBaseUrl( request );
287 String strWidgetsListHtml = getBrowseCategoriesWidgets( request );
288 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
289
290 Map<String, Object> model = new HashMap<String, Object>( );
291 model.put( MARK_BASE_URL, strBaseUrl );
292 model.put( MARK_CATEGORIES_LIST, _categoryService.getCategoriesList( ) );
293 model.put( MARK_CATEGORY_ID_CATEGORY, strCategoryId );
294 model.put( MARK_WIDGETS_LIST_HTML, strWidgetsListHtml );
295 model.put( MARK_TAB_INDEX, strTabIndex );
296
297 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_BROWSE_CATEGORIES, request.getLocale( ), model );
298
299 return template.getHtml( );
300 }
301
302
303
304
305
306
307
308
309 public String getBrowseCategoriesWidgets( HttpServletRequest request )
310 {
311 String strHtml = StringUtils.EMPTY;
312 String strCategoryId = request.getParameter( PARAMETER_CATEGORY_ID_CATEGORY );
313 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
314 List<Widget> listWidgets;
315 Category category = null;
316
317 if ( StringUtils.isNotBlank( strCategoryId ) && StringUtils.isNumeric( strCategoryId ) )
318 {
319 int nCategoryId = Integer.parseInt( strCategoryId );
320 category = _categoryService.findByPrimaryKey( nCategoryId );
321 }
322 else
323 {
324 category = _categoryService.findFirstCategory( );
325 strCategoryId = Integer.toString( category.getIdCategory( ) );
326 }
327
328 if ( category != null )
329 {
330 listWidgets = _widgetService.getWidgetsByCategoryId( category.getIdCategory( ) );
331 }
332 else
333 {
334 listWidgets = new ArrayList<Widget>( );
335 }
336
337 List<TabConfig> listTabs = _pageService.getTabList( getUser( request ) );
338
339 UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) );
340 url.addParameter( PARAMETER_PAGE, MyPortalPlugin.PLUGIN_NAME );
341 url.addParameter( PARAMETER_ACTION, ACTION_BROWSE_CATEGORIES );
342 url.addParameter( PARAMETER_CATEGORY_ID_CATEGORY, strCategoryId );
343 url.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
344
345 UrlItem urlForJs = new UrlItem( JSP_URL_BROWSE_CATEGORIES_WIDGETS );
346 urlForJs.addParameter( PARAMETER_CATEGORY_ID_CATEGORY, strCategoryId );
347 urlForJs.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
348
349
350 String strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, "1" );
351 int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_WIDGET_PER_PAGE_IN_FO, 50 );
352 LocalizedPaginator paginator = new LocalizedPaginator( listWidgets, nDefaultItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX,
353 strCurrentPageIndex, request.getLocale( ) );
354 String strBaseUrl = AppPathService.getBaseUrl( request );
355
356 Map<String, Object> model = new HashMap<String, Object>( );
357 model.put( MARK_BASE_URL, strBaseUrl );
358 model.put( MARK_WIDGETS_LIST, paginator.getPageItems( ) );
359 model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( nDefaultItemsPerPage ) );
360 model.put( MARK_PAGINATOR, paginator );
361 model.put( MARK_LIST_TAB, listTabs );
362 model.put( MARK_PAGINATOR_URL_FOR_JS, urlForJs.getUrl( ) );
363 model.put( MARK_TAB_INDEX, strTabIndex );
364 model.put( MARK_USER_WIDGET_IDS, _widgetService.getUserWidgetIds( getUser( request ) ) );
365
366 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_BROWSE_CATEGORIES_WIDGETS, request.getLocale( ), model );
367
368 strHtml = template.getHtml( );
369
370 return strHtml;
371 }
372
373
374
375
376
377
378
379
380 public String doAddWidget( HttpServletRequest request )
381 {
382 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
383 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
384
385 if ( StringUtils.isNotBlank( strIdWidget ) && StringUtils.isNumeric( strIdWidget ) && StringUtils.isNotBlank( strTabIndex )
386 && StringUtils.isNumeric( strTabIndex ) )
387 {
388 int nIdWidget = Integer.parseInt( strIdWidget );
389 int nColumn = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_COLUMN, 1 );
390 int nTabIndex = Integer.parseInt( strTabIndex );
391
392 _pageService.addWidget( getUser( request ), nIdWidget, nTabIndex, nColumn );
393 }
394
395 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
396 }
397
398
399
400
401
402
403
404
405 public String doEditWidget( HttpServletRequest request )
406 {
407 String strIdTab = request.getParameter( PARAMETER_TAB_INDEX );
408 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
409 String strColumn = request.getParameter( PARAMETER_COLUMN );
410
411 if ( StringUtils.isNotBlank( strIdTab ) && StringUtils.isNumeric( strIdTab ) && StringUtils.isNotBlank( strIdWidget )
412 && StringUtils.isNumeric( strIdWidget ) && StringUtils.isNotBlank( strColumn ) && StringUtils.isNumeric( strColumn ) )
413 {
414 int nIdTab = Integer.parseInt( strIdTab );
415 int nIdWidget = Integer.parseInt( strIdWidget );
416 int nColumn = Integer.parseInt( strColumn );
417 _pageService.editWidget( getUser( request ), nIdTab, nIdWidget, nColumn );
418 }
419
420 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
421 }
422
423
424
425
426
427
428
429
430 public String doRemoveWidget( HttpServletRequest request )
431 {
432 String strWidget = request.getParameter( PARAMETER_WIDGET );
433 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
434
435 if ( StringUtils.isNotBlank( strWidget ) )
436 {
437 String strWidgetCssId = PARAMETER_WIDGET + LINE;
438 int nIdWidget = Integer.parseInt( strWidget.substring( strWidgetCssId.length( ) ) );
439
440 _pageService.removeWidget( getUser( request ), nIdWidget );
441 }
442 else
443 if ( StringUtils.isNotBlank( strIdWidget ) && StringUtils.isNumeric( strIdWidget ) )
444 {
445 int nIdWidget = Integer.parseInt( strIdWidget );
446
447 _pageService.removeWidget( getUser( request ), nIdWidget );
448 }
449
450 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
451 }
452
453
454
455
456
457
458
459
460 public String doSavePortalState( HttpServletRequest request )
461 {
462 String strJson = request.getParameter( PARAMETER_PORTAL_STATE );
463
464 _pageService.setPageConfigUser( getUser( request ), strJson );
465
466 return "portal state saved!";
467 }
468
469
470
471
472
473
474
475
476 public String getBrowseEssentialWidgets( HttpServletRequest request )
477 {
478 List<Widget> listWidgets = _widgetService.getEssentialWidgets( );
479 List<TabConfig> listTabs = _pageService.getTabList( getUser( request ) );
480 String strBaseUrl = AppPathService.getBaseUrl( request );
481 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
482
483 UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) );
484 url.addParameter( PARAMETER_PAGE, MyPortalPlugin.PLUGIN_NAME );
485 url.addParameter( PARAMETER_ACTION, ACTION_BROWSE_ESSENTIAL_WIDGETS );
486 url.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
487
488 UrlItem urlForJs = new UrlItem( JSP_URL_BROWSE_ESSENTIAL_WIDGETS );
489 urlForJs.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
490
491
492 String strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, "1" );
493 int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_WIDGET_PER_PAGE_IN_FO, 50 );
494 LocalizedPaginator paginator = new LocalizedPaginator( listWidgets, nDefaultItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX,
495 strCurrentPageIndex, request.getLocale( ) );
496
497 Map<String, Object> model = new HashMap<String, Object>( );
498 model.put( MARK_BASE_URL, strBaseUrl );
499 model.put( MARK_WIDGETS_LIST, paginator.getPageItems( ) );
500 model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( nDefaultItemsPerPage ) );
501 model.put( MARK_PAGINATOR, paginator );
502 model.put( MARK_LIST_TAB, listTabs );
503 model.put( MARK_PAGINATOR_URL_FOR_JS, urlForJs.getUrl( ) );
504 model.put( MARK_TAB_INDEX, strTabIndex );
505 model.put( MARK_USER_WIDGET_IDS, _widgetService.getUserWidgetIds( getUser( request ) ) );
506
507 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_BROWSE_ESSENTIAL_WIDGETS, request.getLocale( ), model );
508
509 return template.getHtml( );
510 }
511
512
513
514
515
516
517
518
519 public String getBrowseNewWidgets( HttpServletRequest request )
520 {
521 List<Widget> listWidgets = _widgetService.getNewWidgets( );
522 List<TabConfig> listTabs = _pageService.getTabList( getUser( request ) );
523 String strBaseUrl = AppPathService.getBaseUrl( request );
524 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
525
526 UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) );
527 url.addParameter( PARAMETER_PAGE, MyPortalPlugin.PLUGIN_NAME );
528 url.addParameter( PARAMETER_ACTION, ACTION_BROWSE_NEW_WIDGETS );
529 url.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
530
531 UrlItem urlForJs = new UrlItem( JSP_URL_BROWSE_NEW_WIDGETS );
532 urlForJs.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
533
534
535 String strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, "1" );
536 int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_WIDGET_PER_PAGE_IN_FO, 50 );
537 LocalizedPaginator paginator = new LocalizedPaginator( listWidgets, nDefaultItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX,
538 strCurrentPageIndex, request.getLocale( ) );
539
540 Map<String, Object> model = new HashMap<String, Object>( );
541 model.put( MARK_BASE_URL, strBaseUrl );
542 model.put( MARK_WIDGETS_LIST, paginator.getPageItems( ) );
543 model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( nDefaultItemsPerPage ) );
544 model.put( MARK_PAGINATOR, paginator );
545 model.put( MARK_LIST_TAB, listTabs );
546 model.put( MARK_PAGINATOR_URL_FOR_JS, urlForJs.getUrl( ) );
547 model.put( MARK_TAB_INDEX, strTabIndex );
548 model.put( MARK_USER_WIDGET_IDS, _widgetService.getUserWidgetIds( getUser( request ) ) );
549
550 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_BROWSE_NEW_WIDGETS, request.getLocale( ), model );
551
552 return template.getHtml( );
553 }
554
555
556
557
558
559
560
561
562 public String getSearchWidgets( HttpServletRequest request )
563 {
564 String strName = request.getParameter( PARAMETER_SEARCH_WIDGETS_NAME );
565 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
566
567 if ( strName == null )
568 {
569 strName = StringUtils.EMPTY;
570 }
571
572 List<Widget> listWidgets = _widgetService.getWidgetsByName( strName );
573 List<TabConfig> listTabs = _pageService.getTabList( getUser( request ) );
574 String strBaseUrl = AppPathService.getBaseUrl( request );
575
576 UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) );
577 url.addParameter( PARAMETER_PAGE, MyPortalPlugin.PLUGIN_NAME );
578 url.addParameter( PARAMETER_ACTION, ACTION_SEARCH_WIDGETS );
579 url.addParameter( PARAMETER_SEARCH_WIDGETS_NAME, strName );
580 url.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
581
582 UrlItem urlForJs = new UrlItem( JSP_URL_SEARCH_WIDGETS );
583 urlForJs.addParameter( PARAMETER_SEARCH_WIDGETS_NAME, strName );
584 urlForJs.addParameter( PARAMETER_TAB_INDEX, strTabIndex );
585
586
587 String strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, "1" );
588 int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_WIDGET_PER_PAGE_IN_FO, 50 );
589 LocalizedPaginator paginator = new LocalizedPaginator( listWidgets, nDefaultItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX,
590 strCurrentPageIndex, request.getLocale( ) );
591
592 Map<String, Object> model = new HashMap<String, Object>( );
593 model.put( MARK_BASE_URL, strBaseUrl );
594 model.put( MARK_WIDGETS_LIST, paginator.getPageItems( ) );
595 model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( nDefaultItemsPerPage ) );
596 model.put( MARK_PAGINATOR, paginator );
597 model.put( MARK_LIST_TAB, listTabs );
598 model.put( MARK_PAGINATOR_URL_FOR_JS, urlForJs.getUrl( ) );
599 model.put( MARK_TAB_INDEX, strTabIndex );
600 model.put( MARK_USER_WIDGET_IDS, _widgetService.getUserWidgetIds( getUser( request ) ) );
601
602 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SEARCH_WIDGETS, request.getLocale( ), model );
603
604 return template.getHtml( );
605 }
606
607
608
609
610
611
612
613
614 private LuteceUser getUser( HttpServletRequest request )
615 {
616 LuteceUser user = null;
617
618 if ( SecurityService.isAuthenticationEnable( ) )
619 {
620 try
621 {
622 user = SecurityService.getInstance( ).getRemoteUser( request );
623 }
624 catch ( UserNotSignedException ue )
625 {
626 AppLogService.debug( ue.getMessage( ) );
627 }
628 }
629
630 if ( user == null )
631 {
632 user = new MyPortalUser( "Anonymous" );
633 }
634
635 return user;
636 }
637
638
639
640
641
642
643
644
645 public String getMyPortalAddTab( HttpServletRequest request )
646 {
647 Map<String, Object> model = new HashMap<String, Object>( );
648
649 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MYPORTAL_ADD_TAB, request.getLocale( ), model );
650
651 return template.getHtml( );
652 }
653
654
655
656
657
658
659
660
661 public String doAddTab( HttpServletRequest request )
662 {
663 String strTabName = request.getParameter( PARAMETER_TAB_NAME );
664 _pageService.addTab( getUser( request ), strTabName );
665
666 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
667 }
668
669
670
671
672
673
674
675
676 public String getMyPortalEditTab( HttpServletRequest request )
677 {
678 String strHtml = StringUtils.EMPTY;
679 String strTabId = request.getParameter( PARAMETER_TAB_INDEX );
680
681 if ( StringUtils.isNotBlank( strTabId ) && StringUtils.isNumeric( strTabId ) )
682 {
683 int nIdTab = Integer.parseInt( strTabId );
684
685 List<TabConfig> listTabs = _pageService.getTabList( getUser( request ) );
686 TabConfig tabConfig = listTabs.get( nIdTab - 1 );
687
688 Map<String, Object> model = new HashMap<String, Object>( );
689
690 model.put( MARK_TAB_INDEX, nIdTab );
691 model.put( MARK_TAB_NAME, tabConfig.getName( ) );
692
693 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MYPORTAL_EDIT_TAB, request.getLocale( ), model );
694
695 strHtml = template.getHtml( );
696 }
697
698 return strHtml;
699 }
700
701
702
703
704
705
706
707
708 public String doEditTab( HttpServletRequest request )
709 {
710 String strTabNewName = request.getParameter( PARAMETER_TAB_NAME );
711 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
712
713 if ( StringUtils.isNotBlank( strTabIndex ) && StringUtils.isNumeric( strTabIndex ) )
714 {
715 int nIdTab = Integer.parseInt( strTabIndex );
716
717 _pageService.editTab( getUser( request ), strTabNewName, nIdTab );
718 }
719
720 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
721 }
722
723
724
725
726
727
728
729
730 public String doDelTab( HttpServletRequest request )
731 {
732 String strTabIndex = request.getParameter( PARAMETER_TAB_INDEX );
733
734 if ( StringUtils.isNotBlank( strTabIndex ) && StringUtils.isNumeric( strTabIndex ) )
735 {
736 int nIdTab = Integer.parseInt( strTabIndex );
737
738
739 if ( nIdTab != 1 )
740 {
741 _pageService.delTab( getUser( request ), nIdTab );
742 }
743 }
744
745 return AppPropertiesService.getProperty( PROPERTY_URL_RETURN );
746 }
747
748
749
750
751
752
753
754
755 public String getMyPortalEditWidget( HttpServletRequest request )
756 {
757 String strHtml = StringUtils.EMPTY;
758 String strIdTab = request.getParameter( PARAMETER_TAB_INDEX );
759 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
760
761 if ( StringUtils.isNotBlank( strIdTab ) && StringUtils.isNumeric( strIdTab ) && StringUtils.isNotBlank( strIdWidget )
762 && StringUtils.isNumeric( strIdWidget ) )
763 {
764 int nIdTab = Integer.parseInt( strIdTab );
765 int nIdWidget = Integer.parseInt( strIdWidget );
766 int nNbColumns = _defaultPageBuilderService.getColumnCount( );
767
768 Widget widget = _widgetService.getWidget( nIdWidget );
769
770 if ( widget != null )
771 {
772 Map<String, Object> model = new HashMap<String, Object>( );
773
774 model.put( MARK_TAB_INDEX, nIdTab );
775 model.put( MARK_WIDGET, widget );
776 model.put( MARK_NB_COLUMNS, nNbColumns );
777
778 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MYPORTAL_EDIT_WIDGET, request.getLocale( ), model );
779
780 strHtml = template.getHtml( );
781 }
782 }
783
784 return strHtml;
785 }
786
787
788
789
790
791
792
793
794 public String getTabs( HttpServletRequest request )
795 {
796 return _pageService.getUserPage( getUser( request ), request );
797 }
798 }