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 public class AdminMapJspBean extends AdminFeaturesPageJspBean
63 {
64
65 public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
66 private static final long serialVersionUID = 2871979154306491511L;
67
68
69 private static final String MARKER_MAP_SITE = "map_site";
70 private static final String MARK_PAGE = "page";
71
72
73 private static final String TEMPLATE_MAP_SITE = "admin/site/site_map.html";
74
75
76 private static final String PARAMETER_SITE_PATH = "site-path";
77 private static final String PARAMETER_PAGE_ID = "page_id";
78
79
80 private static final String PROPERTY_ADMIN_PATH = "lutece.admin.path";
81
82
83 private static final String TAG_CSS_ID = "css-id";
84 private static final String TAG_PAGE_ROLE = "page-role";
85 private static final int PORTAL_COMPONENT_SITE_MAP_ID = 8;
86 private static final int MODE_ADMIN = 1;
87
88
89
90
91
92
93
94
95 public String getMap( HttpServletRequest request )
96 {
97 StringBuffer strArborescenceXml = new StringBuffer( );
98
99 StringBuilder strCssId = new StringBuilder( );
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<>( );
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<>( );
116 XmlTransformerServicervice.html#XmlTransformerService">XmlTransformerService xmlTransformerService = new XmlTransformerService( );
117 String map = xmlTransformerService.transformBySourceWithXslCache( strArborescenceXml.toString( ), xslSource, mapParamRequest, outputProperties );
118
119 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
120 int nPageId = ( strPageId != null ) ? Integer.parseInt( strPageId ) : 1;
121 Page page = PageHome.getPage( nPageId );
122
123 model.put( MARK_PAGE, page );
124 model.put( MARKER_MAP_SITE, map );
125
126 HtmlTemplate t = AppTemplateService.getTemplate( TEMPLATE_MAP_SITE, getLocale( ), model );
127
128 return t.getHtml();
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 private void findPages( HttpServletRequest request, StringBuffer strXmlArborescence, int nPageId, int nLevel, String strCurrentPageId,
148 StringBuilder strCssId )
149 {
150 Page page = PageHome.getPage( nPageId );
151
152 AdminUser user = AdminUserService.getAdminUser( request );
153 String strPageId = Integer.toString( nPageId );
154
155 boolean bAuthorizationPage;
156
157 if ( nPageId == PortalService.getRootPageId( ) )
158 {
159 bAuthorizationPage = true;
160 }
161 else
162 {
163
164 if ( page.getNodeStatus( ) != 0 )
165 {
166 Page parentPage = PageHome.getPage( page.getParentPageId( ) );
167 int nParentPageNodeStatus = parentPage.getNodeStatus( );
168 int nParentPageId = parentPage.getId( );
169
170
171
172
173 while ( nParentPageNodeStatus != 0 )
174 {
175 parentPage = PageHome.getPage( nParentPageId );
176 nParentPageNodeStatus = parentPage.getNodeStatus( );
177 nParentPageId = parentPage.getParentPageId( );
178 }
179
180 strPageId = Integer.toString( parentPage.getId( ) );
181 }
182
183 bAuthorizationPage = RBACService.isAuthorized( Page.RESOURCE_TYPE, strPageId, PageResourceIdService.PERMISSION_VIEW, user );
184 }
185
186 XmlUtil.beginElement( strXmlArborescence, XmlContent.TAG_PAGE );
187
188 if ( bAuthorizationPage )
189 {
190 XmlUtil.addElementHtml( strXmlArborescence, XmlContent.TAG_CURRENT_PAGE_ID, strCurrentPageId );
191 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_ID, page.getId( ) );
192 XmlUtil.addElementHtml( strXmlArborescence, XmlContent.TAG_PAGE_NAME, page.getName( ) );
193 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_DESCRIPTION, page.getDescription( ) );
194 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_LEVEL, nLevel );
195 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PARENT_PAGE_ID, page.getParentPageId( ) );
196 XmlUtil.addElement( strXmlArborescence, TAG_PAGE_ROLE, page.getRole( ) );
197
198 AdminPageJspBeanminPageJspBean.html#AdminPageJspBean">AdminPageJspBean adminPage = new AdminPageJspBean( );
199
200 if ( page.getImageContent( ) != null )
201 {
202 int nImageLength = page.getImageContent( ).length;
203
204 if ( nImageLength >= 1 )
205 {
206 XmlUtil.addElement( strXmlArborescence, XmlContent.TAG_PAGE_IMAGE, adminPage.getResourceImagePage( page, strPageId ) );
207 }
208 }
209 }
210
211 XmlUtil.beginElement( strXmlArborescence, XmlContent.TAG_CHILD_PAGES_LIST );
212
213 for ( Page pageChild : PageHome.getChildPagesMinimalData( nPageId ) )
214 {
215 findPages( request, strXmlArborescence, pageChild.getId( ), nLevel + 1, strCurrentPageId, strCssId );
216 strCssId.append( "initializeMenu('menu" + pageChild.getId( ) + "' , 'actuator" + pageChild.getId( ) + "');\n" );
217 }
218
219 XmlUtil.endElement( strXmlArborescence, XmlContent.TAG_CHILD_PAGES_LIST );
220
221 if ( bAuthorizationPage )
222 {
223 XmlUtil.addElementHtml( strXmlArborescence, TAG_CSS_ID, strCssId.toString( ) );
224 }
225
226 XmlUtil.endElement( strXmlArborescence, XmlContent.TAG_PAGE );
227 }
228 }