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.portal.web.admin;
35
36 import fr.paris.lutece.portal.business.page.Page;
37 import fr.paris.lutece.portal.business.page.PageHome;
38 import fr.paris.lutece.portal.business.portlet.PortletType;
39 import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
40 import fr.paris.lutece.portal.business.role.RoleHome;
41 import fr.paris.lutece.portal.business.style.PageTemplate;
42 import fr.paris.lutece.portal.business.style.PageTemplateHome;
43 import fr.paris.lutece.portal.business.user.AdminUser;
44 import fr.paris.lutece.portal.service.content.ContentPostProcessorService;
45 import fr.paris.lutece.portal.service.content.ContentService;
46 import fr.paris.lutece.portal.service.fileupload.FileUploadService;
47 import fr.paris.lutece.portal.service.i18n.I18nService;
48 import fr.paris.lutece.portal.service.message.AdminMessage;
49 import fr.paris.lutece.portal.service.message.AdminMessageService;
50 import fr.paris.lutece.portal.service.message.SiteMessageException;
51 import fr.paris.lutece.portal.service.page.IPageService;
52 import fr.paris.lutece.portal.service.page.PageResourceIdService;
53 import fr.paris.lutece.portal.service.page.PageService;
54 import fr.paris.lutece.portal.service.portal.PortalService;
55 import fr.paris.lutece.portal.service.portal.ThemesService;
56 import fr.paris.lutece.portal.service.portlet.PortletResourceIdService;
57 import fr.paris.lutece.portal.service.rbac.RBACService;
58 import fr.paris.lutece.portal.service.security.UserNotSignedException;
59 import fr.paris.lutece.portal.service.spring.SpringContextService;
60 import fr.paris.lutece.portal.service.template.AppTemplateService;
61 import fr.paris.lutece.portal.service.util.AppPropertiesService;
62 import fr.paris.lutece.portal.web.constants.Markers;
63 import fr.paris.lutece.portal.web.constants.Messages;
64 import fr.paris.lutece.portal.web.constants.Parameters;
65 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
66 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
67 import fr.paris.lutece.util.ReferenceList;
68 import fr.paris.lutece.util.html.HtmlTemplate;
69 import fr.paris.lutece.util.string.StringUtil;
70 import fr.paris.lutece.util.url.UrlItem;
71
72 import org.apache.commons.fileupload.FileItem;
73 import org.apache.commons.lang.StringUtils;
74
75 import java.util.Collection;
76 import java.util.HashMap;
77 import java.util.List;
78 import java.util.Map;
79
80 import javax.servlet.http.HttpServletRequest;
81
82
83
84
85
86 public class AdminPageJspBean extends AdminFeaturesPageJspBean
87 {
88
89
90
91
92 public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
93
94
95 public static final String PROPERTY_PAGE_TITLE_ADMIN_SITE = "portal.site.admin_page.pageTitle";
96
97
98 private static final String MARK_PAGE = "page";
99 private static final String MARK_PAGE_INIT_ID = "page_init_id";
100 private static final String MARK_PAGE_MESSAGE = "page_message";
101 private static final String MARK_PORTLET_TYPES_LIST = "portlet_types_list";
102 private static final String MARK_PAGE_ORDER_LIST = "page_order_list";
103 private static final String MARK_PAGE_ROLES_LIST = "page_roles_list";
104 private static final String MARK_PAGE_THEMES_LIST = "page_themes_list";
105 private static final String MARK_IMAGE_URL = "image_url";
106 private static final String MARK_PAGE_TEMPLATES_LIST = "page_templates_list";
107 private static final String MARK_PAGE_TEMPLATE = "page_template";
108 private static final String MARK_INDEX_ROW = "index_row";
109 private static final String MARK_AUTORIZATION = "authorization";
110 private static final String MARK_PAGE_BLOCK = "page_block";
111
112
113 private static final String PARAMETER_IMAGE_CONTENT = "image_content";
114 private static final String PARAMETER_NODE_STATUS = "node_status";
115 private static final String PARAMETER_BLOCK = "param_block";
116 private static final String PARAMETER_PORTLET_TYPE = "portlet_type";
117 private static final String PARAMETER_PAGE_TEMPLATE_UPDATE_IMAGE = "update_image";
118 private static final int BLOCK_SEARCH = 1;
119 private static final int BLOCK_PROPERTY = 2;
120 private static final int BLOCK_CHILDPAGE = 5;
121
122
123 private static final String TEMPLATE_PAGE_TEMPLATE_ROW = "admin/site/page_template_list_row.html";
124 private static final String TEMPLATE_ADMIN_PAGE = "admin/site/admin_page.html";
125 private static final String TEMPLATE_ADMIN_PAGE_BLOCK_SEARCH = "admin/site/admin_page_block_search.html";
126 private static final String TEMPLATE_ADMIN_PAGE_BLOCK_PROPERTY = "admin/site/admin_page_block_property.html";
127 private static final String TEMPLATE_ADMIN_PAGE_BLOCK_CHILDPAGE = "admin/site/admin_page_block_childpage.html";
128
129
130 private static final String PROPERTY_MESSAGE_PAGE_INEXISTENT = "portal.site.admin_page.messagePageInexistent";
131 private static final String PROPERTY_MESSAGE_PAGE_FORMAT = "portal.site.admin_page.messagePageFormat";
132 private static final String PROPERTY_MESSAGE_CONFIRM_REMOVE_PAGE = "portal.site.message.confirmRemovePage";
133 private static final String PROPERTY_LIST_ORDER_MAX = "list.order.max";
134
135
136 private static final String JSP_ADMIN_SITE = "AdminSite.jsp";
137 private static final String JSP_PATH = "jsp/admin/site/";
138 private static final String JSP_REMOVE_PAGE = JSP_PATH + "DoRemovePage.jsp";
139
140
141 private static final String MESSAGE_TITLE_INVALID_CHARACTERS = "portal.site.message.invalidCharactersInTitleName";
142 private static final String MESSAGE_DESCRIPTION_INVALID_CHARACTERS = "portal.site.message.invalidCharactersInDescription";
143 private static final String MESSAGE_CANNOT_REMOVE_CHILDPAGE_EXISTS = "portal.site.message.cannotRemoveChildPageExists";
144 private static final String MESSAGE_LENGTH_DESCRIPTION = "portal.site.message.pageLengthDescription";
145 private static final String MESSAGE_ROOT_PAGE_FORBIDDEN = "portal.site.message.rootPageForbidden";
146 private static final String MESSAGE_INVALID_PAGE_ID = "portal.site.message.pageIdInvalid";
147 private static final String MESSAGE_PAGE_ID_CHILDPAGE = "portal.site.message.pageIdChildPage";
148 private static final String MESSAGE_SAME_PAGE_ID = "portal.site.message.pageSameId";
149 private static IPageService _pageService = (IPageService) SpringContextService.getBean( "pageService" );
150
151
152
153
154
155
156
157 public String getAdminPage( HttpServletRequest request )
158 {
159 String strPageId = request.getParameter( Parameters.PAGE_ID );
160
161 if ( ( strPageId == null ) || strPageId.equals( "" ) )
162 {
163 strPageId = String.valueOf( PortalService.getRootPageId( ) );
164 }
165
166 String strParamBlock = request.getParameter( PARAMETER_BLOCK );
167 String strPortletType = request.getParameter( PARAMETER_PORTLET_TYPE );
168
169 return getAdminPageBlock( strPageId, strParamBlock, strPortletType, request );
170 }
171
172
173
174
175
176
177
178
179
180
181 public String getAdminPagePreview( HttpServletRequest request )
182 throws UserNotSignedException, SiteMessageException
183 {
184 ContentService cs = PortalService.getInvokedContentService( request );
185 int nMode = 1;
186
187 String strContent = StringUtils.EMPTY;
188
189 if ( cs != null )
190 {
191 strContent = cs.getPage( request, nMode );
192 }
193 else
194 {
195 strContent = PortalService.getDefaultPage( request, nMode );
196 }
197
198 if ( ContentPostProcessorService.hasProcessor( ) )
199 {
200 strContent = ContentPostProcessorService.process( request, strContent );
201 }
202
203 return strContent;
204 }
205
206
207
208
209
210
211
212 public String doModifyPage( HttpServletRequest request )
213 {
214 MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
215 int nPageId = Integer.parseInt( mRequest.getParameter( Parameters.PAGE_ID ) );
216
217 Page page = PageHome.getPage( nPageId );
218 Integer nOldAutorisationNode = page.getIdAuthorizationNode( );
219
220 String strErrorUrl = getPageData( mRequest, page );
221
222 if ( strErrorUrl != null )
223 {
224 return strErrorUrl;
225 }
226
227 int nParentPageId = Integer.parseInt( mRequest.getParameter( Parameters.PARENT_ID ) );
228
229 if ( nParentPageId != page.getParentPageId( ) )
230 {
231 strErrorUrl = getNewParentPageId( mRequest, page, nParentPageId );
232
233 if ( strErrorUrl != null )
234 {
235 return strErrorUrl;
236 }
237 }
238
239
240 if ( page.getNodeStatus( ) != 0 )
241 {
242 Page parentPage = PageHome.getPage( page.getParentPageId( ) );
243 page.setIdAuthorizationNode( parentPage.getIdAuthorizationNode( ) );
244 }
245 else
246 {
247 page.setIdAuthorizationNode( page.getId( ) );
248 }
249
250 if ( ( page.getIdAuthorizationNode( ) == null ) ||
251 !page.getIdAuthorizationNode( ).equals( nOldAutorisationNode ) )
252 {
253 PageService.updateChildrenAuthorizationNode( page.getId( ), page.getIdAuthorizationNode( ) );
254 }
255
256 String strUpdatePicture = mRequest.getParameter( PARAMETER_PAGE_TEMPLATE_UPDATE_IMAGE );
257 FileItem item = mRequest.getFile( PARAMETER_IMAGE_CONTENT );
258
259 boolean bUpdatePicture = false;
260 String strPictureName = FileUploadService.getFileNameOnly( item );
261
262 if ( strUpdatePicture != null )
263 {
264 if ( strPictureName.equals( "" ) )
265 {
266 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FILE, AdminMessage.TYPE_STOP );
267 }
268 else
269 {
270 bUpdatePicture = true;
271 }
272 }
273
274 if ( bUpdatePicture )
275 {
276 byte[] bytes = item.get( );
277 String strMimeType = item.getContentType( );
278 page.setImageContent( bytes );
279 page.setMimeType( strMimeType );
280 }
281
282
283 _pageService.updatePage( page );
284
285
286 return getUrlPage( nPageId );
287 }
288
289
290
291
292
293
294
295 public String getRemovePage( HttpServletRequest request )
296 {
297 String strPageId = request.getParameter( Parameters.PAGE_ID );
298 if ( !StringUtils.isNumeric( strPageId ) )
299 {
300 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID,
301 AdminMessage.TYPE_ERROR );
302 }
303 int nPageId = Integer.parseInt( strPageId );
304 Page page = PageHome.getPage( nPageId );
305 if ( page == null || page.getId( ) == 0 || page.getId( ) != nPageId )
306 {
307 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID,
308 AdminMessage.TYPE_ERROR );
309 }
310 UrlItem url = new UrlItem( JSP_REMOVE_PAGE );
311 url.addParameter( Parameters.PAGE_ID, strPageId );
312
313 return AdminMessageService.getMessageUrl( request, PROPERTY_MESSAGE_CONFIRM_REMOVE_PAGE,
314 new Object[] { page.getName( ) }, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
315 }
316
317
318
319
320
321
322
323 public String doRemovePage( HttpServletRequest request )
324 {
325 String strPageId = request.getParameter( Parameters.PAGE_ID );
326 if ( !StringUtils.isNumeric( strPageId ) )
327 {
328 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID,
329 AdminMessage.TYPE_ERROR );
330 }
331 int nPageId = Integer.parseInt( strPageId );
332 Page page = PageHome.getPage( nPageId );
333 if ( page == null || page.getId( ) == 0 || page.getId( ) != nPageId )
334 {
335 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID,
336 AdminMessage.TYPE_ERROR );
337 }
338
339 Collection<Page> list = PageHome.getChildPagesMinimalData( nPageId );
340
341 if ( list.size( ) > 0 )
342 {
343 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_REMOVE_CHILDPAGE_EXISTS,
344 new Object[] { page.getName( ), list.size( ) }, JSP_PATH + getUrlPage( nPageId ), AdminMessage.TYPE_STOP );
345 }
346
347 int nParentPageId = page.getParentPageId( );
348
349
350 _pageService.removePage( nPageId );
351
352 return getUrlPage( nParentPageId );
353 }
354
355
356
357
358
359
360
361 public String doCreateChildPage( HttpServletRequest request )
362 {
363 MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
364
365 String strParentPageId = mRequest.getParameter( Parameters.PAGE_ID );
366 int nParentPageId = Integer.parseInt( strParentPageId );
367
368 Page page = new Page( );
369 page.setParentPageId( nParentPageId );
370
371 String strErrorUrl = getPageData( mRequest, page );
372
373 if ( strErrorUrl != null )
374 {
375 return strErrorUrl;
376 }
377
378
379 _pageService.createPage( page );
380
381
382 if ( page.getNodeStatus( ) != 0 )
383 {
384 Page parentPage = PageHome.getPage( page.getParentPageId( ) );
385 page.setIdAuthorizationNode( parentPage.getIdAuthorizationNode( ) );
386 }
387 else
388 {
389 page.setIdAuthorizationNode( page.getId( ) );
390 }
391
392 FileItem item = mRequest.getFile( PARAMETER_IMAGE_CONTENT );
393
394 byte[] bytes = item.get( );
395 String strMimeType = item.getContentType( );
396
397 page.setImageContent( bytes );
398 page.setMimeType( strMimeType );
399
400 _pageService.updatePage( page );
401
402
403 return getUrlPage( page.getId( ) );
404 }
405
406
407
408
409
410
411
412 public String getResourceImagePage( Page page, String strPageId )
413 {
414 String strResourceType = _pageService.getResourceTypeId( );
415 UrlItem url = new UrlItem( Parameters.IMAGE_SERVLET );
416 url.addParameter( Parameters.RESOURCE_TYPE, strResourceType );
417 url.addParameter( Parameters.RESOURCE_ID, strPageId );
418
419 return url.getUrlWithEntity( );
420 }
421
422
423
424
425
426
427
428
429
430
431
432
433
434 private String getAdminPageBlock( String strPageId, String strParamBlock, String strPortletType,
435 HttpServletRequest request )
436 {
437 Map<String, Object> model = new HashMap<String, Object>( );
438
439 Page page = null;
440 int nPageId = 1;
441 int nPageIdInit = 1;
442 int nParamBlock = 0;
443
444 try
445 {
446 nPageId = Integer.parseInt( strPageId );
447 nPageIdInit = nPageId;
448 nParamBlock = ( strParamBlock != null ) ? Integer.parseInt( strParamBlock ) : 0;
449
450 boolean bPageExist = PageHome.checkPageExist( nPageId );
451
452 if ( bPageExist )
453 {
454 page = PageHome.getPage( nPageId );
455 model.put( MARK_PAGE_MESSAGE, "" );
456 }
457 else
458 {
459 nPageId = PortalService.getRootPageId( );
460 page = PageHome.getPage( nPageId );
461 model.put( MARK_PAGE_MESSAGE,
462 I18nService.getLocalizedString( PROPERTY_MESSAGE_PAGE_INEXISTENT, getLocale( ) ) );
463 }
464 }
465 catch ( NumberFormatException nfe )
466 {
467 nPageId = PortalService.getRootPageId( );
468 page = PageHome.getPage( nPageId );
469 model.put( MARK_PAGE_MESSAGE, I18nService.getLocalizedString( PROPERTY_MESSAGE_PAGE_FORMAT, getLocale( ) ) );
470 }
471
472 switch ( nParamBlock )
473 {
474 case BLOCK_SEARCH:
475 model.put( MARK_PAGE_BLOCK, getAdminPageBlockSearch( nPageIdInit, model ) );
476
477 break;
478
479 case BLOCK_PROPERTY:
480 case BLOCK_CHILDPAGE:
481 model.put( MARK_PAGE_BLOCK, getAdminPageBlockProperty( page, nParamBlock, model ) );
482
483 break;
484
485 default:
486 model.put( MARK_PAGE_BLOCK, "" );
487
488 break;
489 }
490
491 model.put( MARK_PORTLET_TYPES_LIST, getPortletTypeList( getUser( ) ) );
492 model.put( MARK_PAGE, page );
493 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, strPageId, Page.RESOURCE_TYPE );
494
495 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_PAGE, getLocale( ), model );
496
497 return getAdminPage( template.getHtml( ) );
498 }
499
500
501
502
503
504
505
506
507
508 private String getAdminPageBlockProperty( Page page, int nParamBlock, Map model )
509 {
510 model.put( MARK_PAGE, page );
511 model.put( MARK_PAGE_INIT_ID, page.getId( ) );
512 model.put( MARK_PAGE_ORDER_LIST, getOrdersList( ) );
513 model.put( MARK_PAGE_ROLES_LIST, RoleHome.getRolesList( getUser( ) ) );
514 model.put( MARK_PAGE_THEMES_LIST, ThemesService.getPageThemes( getLocale( ) ) );
515 model.put( MARK_IMAGE_URL, getResourceImagePage( page, Integer.toString( page.getId( ) ) ) );
516
517 int nIndexRow = 1;
518 StringBuffer strPageTemplatesRow = new StringBuffer( );
519
520
521 for ( PageTemplate pageTemplate : PageTemplateHome.getPageTemplatesList( ) )
522 {
523 strPageTemplatesRow.append( getTemplatesPageList( pageTemplate.getId( ), page.getPageTemplateId( ),
524 Integer.toString( nIndexRow ) ) );
525 nIndexRow++;
526 }
527
528 model.put( MARK_PAGE_TEMPLATES_LIST, strPageTemplatesRow );
529
530
531 int nManageAuthorization = 1;
532
533 if ( _pageService.isAuthorizedAdminPage( page.getId( ), PageResourceIdService.PERMISSION_MANAGE, getUser( ) ) )
534 {
535 nManageAuthorization = 0;
536 }
537
538 model.put( MARK_AUTORIZATION, Integer.toString( nManageAuthorization ) );
539
540 String strTemplate = TEMPLATE_ADMIN_PAGE_BLOCK_PROPERTY;
541
542 if ( nParamBlock == BLOCK_CHILDPAGE )
543 {
544 strTemplate = TEMPLATE_ADMIN_PAGE_BLOCK_CHILDPAGE;
545 }
546
547 HtmlTemplate template = AppTemplateService.getTemplate( strTemplate, getLocale( ), model );
548
549 return template.getHtml( );
550 }
551
552
553
554
555
556
557
558
559 private String getAdminPageBlockSearch( int nPageIdInit, Map model )
560 {
561 model.put( MARK_PAGE_INIT_ID, Integer.toString( nPageIdInit ) );
562
563 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_PAGE_BLOCK_SEARCH, getLocale( ), model );
564
565 return template.getHtml( );
566 }
567
568
569
570
571
572
573
574 private String getPageData( HttpServletRequest request, Page page )
575 {
576 String strErrorUrl = null;
577
578 String strPageId = request.getParameter( Parameters.PAGE_ID );
579 int nPageId = Integer.parseInt( strPageId );
580 String strName = request.getParameter( Parameters.PAGE_NAME );
581 String strDescription = request.getParameter( Parameters.PAGE_DESCRIPTION );
582 String strTemplatePageId = request.getParameter( Parameters.PAGE_TEMPLATE_ID );
583 int nTemplatePageId = Integer.parseInt( strTemplatePageId );
584 String strOrder = request.getParameter( Parameters.ORDER );
585 String strRole = request.getParameter( Parameters.ROLE );
586 String strTheme = request.getParameter( Parameters.THEME );
587 String strMetaKeywords = request.getParameter( Parameters.META_KEYWORDS ).trim( );
588 String strMetaDescription = request.getParameter( Parameters.META_DESCRIPTION ).trim( );
589
590
591 String strNodeStatus = request.getParameter( PARAMETER_NODE_STATUS );
592 int nNodeStatus = Integer.parseInt( strNodeStatus );
593
594
595 if ( strDescription.length( ) > 150 )
596 {
597 return AdminMessageService.getMessageUrl( request, MESSAGE_LENGTH_DESCRIPTION, AdminMessage.TYPE_STOP );
598 }
599
600
601 if ( strName.trim( ).equals( "" ) )
602 {
603 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
604 }
605
606
607 else if ( StringUtil.containsHtmlSpecialCharacters( strName ) )
608 {
609 return AdminMessageService.getMessageUrl( request, MESSAGE_TITLE_INVALID_CHARACTERS, AdminMessage.TYPE_STOP );
610 }
611
612
613 else if ( StringUtil.containsHtmlSpecialCharacters( strDescription ) )
614 {
615 return AdminMessageService.getMessageUrl( request, MESSAGE_DESCRIPTION_INVALID_CHARACTERS,
616 AdminMessage.TYPE_STOP );
617 }
618
619
620 else if ( StringUtil.containsHtmlSpecialCharacters( strMetaKeywords ) )
621 {
622 return AdminMessageService.getMessageUrl( request, MESSAGE_DESCRIPTION_INVALID_CHARACTERS,
623 AdminMessage.TYPE_STOP );
624 }
625
626
627 else if ( StringUtil.containsHtmlSpecialCharacters( strMetaDescription ) )
628 {
629 return AdminMessageService.getMessageUrl( request, MESSAGE_DESCRIPTION_INVALID_CHARACTERS,
630 AdminMessage.TYPE_STOP );
631 }
632 else
633 {
634 page.setName( strName );
635 }
636
637 int nOrder = ( strOrder != null ) ? Integer.parseInt( strOrder ) : PageHome.getNewChildPageOrder( nPageId );
638
639 page.setPageTemplateId( nTemplatePageId );
640 page.setDescription( strDescription );
641 page.setOrder( nOrder );
642 page.setRole( strRole );
643 page.setCodeTheme( strTheme );
644 page.setNodeStatus( nNodeStatus );
645 page.setMetaKeywords( strMetaKeywords );
646 page.setMetaDescription( strMetaDescription );
647
648 return strErrorUrl;
649 }
650
651
652
653
654
655
656 private ReferenceList getOrdersList( )
657 {
658 ReferenceList list = new ReferenceList( );
659 int nOrderMax = AppPropertiesService.getPropertyInt( PROPERTY_LIST_ORDER_MAX, 15 );
660
661 for ( int i = 1; i <= nOrderMax; i++ )
662 {
663 list.addItem( i, String.valueOf( i ) );
664 }
665
666 return list;
667 }
668
669
670
671
672
673
674 private Collection<PortletType> getPortletTypeList( AdminUser user )
675 {
676 List<PortletType> listPortletType = PortletTypeHome.getPortletTypesList( getLocale( ) );
677
678 return RBACService.getAuthorizedCollection( listPortletType, PortletResourceIdService.PERMISSION_CREATE, user );
679 }
680
681
682
683
684
685
686
687
688
689 private String getTemplatesPageList( int nTemplatePageId, int nPageTemplatePageId, String nIndexRow )
690 {
691 Map<String, Object> model = new HashMap<String, Object>( );
692
693 PageTemplate pageTemplate = PageTemplateHome.findByPrimaryKey( nTemplatePageId );
694 model.put( MARK_PAGE_TEMPLATE, pageTemplate );
695 model.put( MARK_INDEX_ROW, nIndexRow );
696
697 String strChecked = ( pageTemplate.getId( ) == nPageTemplatePageId ) ? "checked=\"checked\"" : "";
698 model.put( Markers.PAGE_TEMPLATE_CHECKED, strChecked );
699
700 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PAGE_TEMPLATE_ROW, getLocale( ), model );
701
702 return template.getHtml( );
703 }
704
705
706
707
708
709
710 private String getUrlPage( int nId )
711 {
712 UrlItem url = new UrlItem( JSP_ADMIN_SITE );
713 url.addParameter( Parameters.PAGE_ID, nId );
714
715 return url.getUrl( );
716 }
717
718
719
720
721
722
723
724
725 private String getNewParentPageId( HttpServletRequest request, Page page, int nParentPageId )
726 {
727 String strErrorUrl = null;
728
729 if ( nParentPageId != 0 )
730 {
731 int nChildPagePageId = nParentPageId;
732 boolean bPageExist = PageHome.checkPageExist( nChildPagePageId );
733
734 if ( bPageExist )
735 {
736 if ( nChildPagePageId >= PortalService.getRootPageId( ) )
737 {
738 Page childPage = PageHome.getPage( nChildPagePageId );
739 int nParentChildPageId = childPage.getParentPageId( );
740
741 while ( ( nChildPagePageId != page.getId( ) ) && ( nChildPagePageId != 0 ) )
742 {
743 if ( nParentChildPageId != page.getId( ) )
744 {
745 childPage = PageHome.getPage( nParentChildPageId );
746 nChildPagePageId = childPage.getId( );
747 nParentChildPageId = childPage.getParentPageId( );
748 }
749 else
750 {
751 return AdminMessageService.getMessageUrl( request, MESSAGE_PAGE_ID_CHILDPAGE,
752 AdminMessage.TYPE_STOP );
753 }
754 }
755
756 if ( nParentPageId != page.getId( ) )
757 {
758 String strParentPageId = Integer.toString( nParentPageId );
759 page.setParentPageId( Integer.parseInt( strParentPageId ) );
760 }
761 else
762 {
763 return AdminMessageService.getMessageUrl( request, MESSAGE_SAME_PAGE_ID, AdminMessage.TYPE_STOP );
764 }
765 }
766 else
767 {
768 return AdminMessageService.getMessageUrl( request, MESSAGE_ROOT_PAGE_FORBIDDEN,
769 AdminMessage.TYPE_STOP );
770 }
771 }
772 else
773 {
774 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID, AdminMessage.TYPE_STOP );
775 }
776 }
777 else
778 {
779 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_PAGE_ID, AdminMessage.TYPE_STOP );
780 }
781
782 return strErrorUrl;
783 }
784 }