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;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Locale;
42
43 import javax.servlet.http.HttpServletRequest;
44
45 import fr.paris.lutece.portal.service.content.ContentService;
46 import fr.paris.lutece.portal.service.content.XPageAppService;
47 import fr.paris.lutece.portal.service.message.ISiteMessageHandler;
48 import fr.paris.lutece.portal.service.message.SiteMessageException;
49 import fr.paris.lutece.portal.service.plugin.Plugin;
50 import fr.paris.lutece.portal.service.plugin.PluginService;
51 import fr.paris.lutece.portal.service.portal.StandaloneAppService;
52 import fr.paris.lutece.portal.service.security.UserNotSignedException;
53 import fr.paris.lutece.portal.service.spring.SpringContextService;
54 import fr.paris.lutece.portal.service.template.AppTemplateService;
55 import fr.paris.lutece.portal.service.util.AppPathService;
56 import fr.paris.lutece.portal.web.xpages.XPageApplicationEntry;
57 import fr.paris.lutece.util.html.HtmlTemplate;
58
59
60
61
62 public class StandaloneAppJspBean
63 {
64
65
66 private static final int MODE_HTML = 0;
67 private static final String TEMPLATE_STANDALONE = "skin/site/standalone_app.html";
68 private static final String MARK_ENTRY_LIST = "entry_list";
69 private static final String MARK_BASE_URL = "base_url";
70 private static final String MARK_CORE_PLUGIN = "core_plugin";
71 private static final String BEAN_SITE_MESSAGE_HANDLER = "siteMessageHandler";
72
73
74
75
76
77
78
79
80
81
82
83
84 public String getContent( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
85 {
86 return getContent( request, MODE_HTML );
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public String getContent( HttpServletRequest request, int nMode ) throws UserNotSignedException, SiteMessageException
103 {
104
105 ISiteMessageHandler handlerSiteMessage = SpringContextService.getBean( BEAN_SITE_MESSAGE_HANDLER );
106
107 if ( handlerSiteMessage.hasMessage( request ) )
108 {
109 return handlerSiteMessage.getPage( request, nMode );
110 }
111
112 ContentService csStandalone = new StandaloneAppService( );
113 String htmlPage = csStandalone.getPage( request, nMode );
114
115 if ( htmlPage == null )
116 {
117
118 return getPluginList( request );
119 }
120
121 return htmlPage;
122 }
123
124
125
126
127
128
129
130
131 public String getPluginList( HttpServletRequest request )
132 {
133 HashMap<String, Object> modelList = new HashMap<>( );
134 Collection<XPageApplicationEntry> entryList = new ArrayList<>( );
135 Locale locale = ( request == null ) ? null : request.getLocale( );
136
137 Collection<XPageApplicationEntry> applications = XPageAppService.getXPageApplicationsList( );
138 List<XPageApplicationEntry> applicationsSorted = new ArrayList<>( applications );
139
140 Collections.sort( applicationsSorted, ( XPageApplicationEntry../../fr/paris/lutece/portal/web/xpages/XPageApplicationEntry.html#XPageApplicationEntry">XPageApplicationEntry c1, XPageApplicationEntry c2 ) -> {
141 Plugin p1 = ( c1.getPlugin( ) == null ) ? PluginService.getCore( ) : c1.getPlugin( );
142 Plugin p2 = ( c2.getPlugin( ) == null ) ? PluginService.getCore( ) : c2.getPlugin( );
143
144 return p1.getName( ).compareTo( p2.getName( ) );
145 } );
146
147
148 for ( XPageApplicationEntry entry : applicationsSorted )
149 {
150 if ( entry.isEnable( ) )
151 {
152 entryList.add( entry );
153 }
154 }
155
156
157 modelList.put( MARK_ENTRY_LIST, entryList );
158 modelList.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
159 modelList.put( MARK_CORE_PLUGIN, PluginService.getCore( ) );
160
161 HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_STANDALONE, locale, modelList );
162
163 return templateList.getHtml( );
164 }
165 }