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.XmlContent;
37 import fr.paris.lutece.portal.business.page.Page;
38 import fr.paris.lutece.portal.business.page.PageHome;
39 import fr.paris.lutece.portal.business.portalcomponent.PortalComponentHome;
40 import fr.paris.lutece.portal.business.style.ModeHome;
41 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
42 import fr.paris.lutece.portal.business.user.AdminUser;
43 import fr.paris.lutece.portal.service.admin.AdminUserService;
44 import fr.paris.lutece.portal.service.html.XmlTransformerService;
45 import fr.paris.lutece.portal.service.page.PageResourceIdService;
46 import fr.paris.lutece.portal.service.portal.PortalService;
47 import fr.paris.lutece.portal.service.rbac.RBACService;
48 import fr.paris.lutece.portal.service.template.AppTemplateService;
49 import fr.paris.lutece.portal.service.util.AppPropertiesService;
50 import fr.paris.lutece.util.html.HtmlTemplate;
51 import fr.paris.lutece.util.xml.XmlUtil;
52
53 import java.util.HashMap;
54 import java.util.Map;
55 import java.util.Properties;
56
57 import javax.servlet.http.HttpServletRequest;
58
59
60
61
62
63 public class AdminMapJspBean extends AdminFeaturesPageJspBean
64 {
65
66 public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
67 private static final long serialVersionUID = 2871979154306491511L;
68
69
70 private static final String MARKER_MAP_SITE = "map_site";
71 private static final String MARK_PAGE = "page";
72
73
74 private static final String TEMPLATE_MAP_SITE = "admin/site/site_map.html";
75
76
77 private static final String PARAMETER_SITE_PATH = "site-path";
78 private static final String PARAMETER_PAGE_ID = "page_id";
79
80
81 private static final String PROPERTY_ADMIN_PATH = "lutece.admin.path";
82
83
84 private static final String TAG_CSS_ID = "css-id";
85 private static final String TAG_PAGE_ROLE = "page-role";
86 private static final int PORTAL_COMPONENT_SITE_MAP_ID = 8;
87 private static final int MODE_ADMIN = 1;
88
89
90
91
92
93
94
95 public String getMap( HttpServletRequest request )
96 {
97 StringBuffer strArborescenceXml = new StringBuffer( );
98
99 StringBuffer strCssId = new StringBuffer( );
100 int nLevel = 0;
101
102 String strCurrentPageId = request.getParameter( PARAMETER_PAGE_ID );
103
104 findPages( request, strArborescenceXml, PortalService.getRootPageId( ), nLevel, strCurrentPageId, strCssId );
105
106 StyleSheet xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_SITE_MAP_ID, MODE_ADMIN );
107
108
109
110 Map<String, String> mapParamRequest = new HashMap<String, String>( );
111 mapParamRequest.put( PARAMETER_SITE_PATH, AppPropertiesService.getProperty( PROPERTY_ADMIN_PATH ) );
112
113 Properties outputProperties = ModeHome.getOuputXslProperties( MODE_ADMIN );
114
115 Map<String, Object> model = new HashMap<String, Object>( );
116 XmlTransformerService xmlTransformerService = new XmlTransformerService( );
117 String map = xmlTransformerService.transformBySourceWithXslCache( strArborescenceXml.toString( ), xslSource,
118 mapParamRequest, outputProperties );
119
120 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
121 int nPageId = ( strPageId != null ) ? Integer.parseInt( strPageId ) : 1;
122 Page page = PageHome.getPage( nPageId );
123
124 model.put( MARK_PAGE, page );
125 model.put( MARKER_MAP_SITE, map );
126
127 HtmlTemplate t = AppTemplateService.getTemplate( TEMPLATE_MAP_SITE, getLocale( ), model );
128
129 return getAdminPage( t.getHtml( ) );
130 }
131
132
133
134
135
136
137
138
139
140
141 private void findPages( HttpServletRequest request, StringBuffer strXmlArborescence, int nPageId, int nLevel,
142 String strCurrentPageId, StringBuffer strCssId )
143 {
144 Page page = PageHome.getPage( nPageId );
145
146 AdminUser user = AdminUserService.getAdminUser( request );
147 String strPageId = Integer.toString( nPageId );
148
149 boolean bAuthorizationPage;
150
151 if ( nPageId == PortalService.getRootPageId( ) )
152 {
153 bAuthorizationPage = true;
154 }
155 else
156 {
157
158 if ( page.getNodeStatus( ) != 0 )
159 {
160 Page parentPage = PageHome.getPage( page.getParentPageId( ) );
161 int nParentPageNodeStatus = parentPage.getNodeStatus( );
162 int nParentPageId = parentPage.getId( );
163
164
165
166
167 while ( nParentPageNodeStatus != 0 )
168 {
169 parentPage = PageHome.getPage( nParentPageId );
170 nParentPageNodeStatus = parentPage.getNodeStatus( );
171 nParentPageId = parentPage.getParentPageId( );
172 }
173
174 strPageId = Integer.toString( parentPage.getId( ) );
175 }
176
177 bAuthorizationPage = RBACService.isAuthorized( Page.RESOURCE_TYPE, strPageId,
178 PageResourceIdService.PERMISSION_VIEW, user );
179 }
180
181 XmlUtil.beginElement( strXmlArborescence, XmlContent.TAG_PAGE );
182
183 if ( bAuthorizationPage )
184 {
185 XmlUtil.addElementHtml( strXmlArborescence, XmlContent.TAG_CURRENT_PAGE_ID, strCurrentPageId );
186 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_ID, page.getId( ) );
187 XmlUtil.addElementHtml( strXmlArborescence, XmlContent.TAG_PAGE_NAME, page.getName( ) );
188 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_DESCRIPTION, page.getDescription( ) );
189 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_LEVEL, nLevel );
190 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PARENT_PAGE_ID, page.getParentPageId( ) );
191 XmlUtil.addElement( strXmlArborescence, TAG_PAGE_ROLE, page.getRole( ) );
192
193 AdminPageJspBean adminPage = new AdminPageJspBean( );
194
195 if ( page.getImageContent( ) != null )
196 {
197 int nImageLength = page.getImageContent( ).length;
198
199 if ( nImageLength >= 1 )
200 {
201 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_IMAGE,
202 adminPage.getResourceImagePage( page, strPageId ) );
203 }
204 }
205 }
206
207 XmlUtil.beginElement( strXmlArborescence, XmlContent.TAG_CHILD_PAGES_LIST );
208
209 for ( Page pageChild : PageHome.getChildPagesMinimalData( nPageId ) )
210 {
211 findPages( request, strXmlArborescence, pageChild.getId( ), nLevel + 1, strCurrentPageId, strCssId );
212 strCssId.append( "initializeMenu('menu" + pageChild.getId( ) + "' , 'actuator" + pageChild.getId( ) +
213 "');\n" );
214 }
215
216 XmlUtil.endElement( strXmlArborescence, XmlContent.TAG_CHILD_PAGES_LIST );
217
218 if ( bAuthorizationPage )
219 {
220 XmlUtil.addElementHtml( strXmlArborescence, TAG_CSS_ID, strCssId.toString( ) );
221 }
222
223 XmlUtil.endElement( strXmlArborescence, XmlContent.TAG_PAGE );
224 }
225 }