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.service.portal;
35
36 import fr.paris.lutece.portal.service.content.ContentService;
37 import fr.paris.lutece.portal.service.content.PageData;
38 import fr.paris.lutece.portal.service.content.XPageAppService;
39 import fr.paris.lutece.portal.service.includes.PageInclude;
40 import fr.paris.lutece.portal.service.includes.PageIncludeService;
41 import fr.paris.lutece.portal.service.message.SiteMessage;
42 import fr.paris.lutece.portal.service.message.SiteMessageException;
43 import fr.paris.lutece.portal.service.message.SiteMessageService;
44 import fr.paris.lutece.portal.service.security.UserNotSignedException;
45 import fr.paris.lutece.portal.service.template.AppTemplateService;
46 import fr.paris.lutece.portal.service.util.AppLogService;
47 import fr.paris.lutece.portal.service.util.AppPathService;
48 import fr.paris.lutece.portal.web.constants.Markers;
49 import fr.paris.lutece.portal.web.xpages.XPage;
50 import fr.paris.lutece.portal.web.xpages.XPageApplication;
51 import fr.paris.lutece.portal.web.xpages.XPageApplicationEntry;
52 import fr.paris.lutece.util.html.HtmlTemplate;
53 import fr.paris.lutece.util.http.SecurityUtil;
54
55 import java.io.File;
56
57 import java.util.Collection;
58 import java.util.HashMap;
59
60 import javax.servlet.http.HttpServletRequest;
61
62
63
64
65
66
67
68
69
70 public class StandaloneAppService extends ContentService
71 {
72 public static final String PARAM_STANDALONE_APP = "page";
73 private static final String PROPERTY_PATH_LUTECE_PLUGINS = "path.lutece.plugins";
74 private static final String TEMPLATE_PAGE_FRAMESET = "page_frameset.html";
75 private static final String TEMPLATE_STANDALONE_PAGE_FRAMESET = "skin/site/standalone_app_frameset.html";
76 private static final String CONTENT_SERVICE_NAME = "StandaloneAppService";
77 private static final String MESSAGE_ERROR_APP_BODY = "portal.util.message.errorXpageApp";
78
79
80
81
82
83
84 @Override
85 public String getName( )
86 {
87 return CONTENT_SERVICE_NAME;
88 }
89
90
91
92
93
94
95
96
97 @Override
98 public boolean isInvoked( HttpServletRequest request )
99 {
100 String strStandaloneApp = request.getParameter( PARAM_STANDALONE_APP );
101
102 return ( strStandaloneApp != null ) && ( strStandaloneApp.length( ) > 0 );
103 }
104
105
106
107
108
109
110
111 public void setCache( boolean bCache )
112 {
113
114 }
115
116
117
118
119
120
121 @Override
122 public boolean isCacheEnable( )
123 {
124 return false;
125 }
126
127
128
129
130 @Override
131 public void resetCache( )
132 {
133
134 }
135
136
137
138
139
140
141 @Override
142 public int getCacheSize( )
143 {
144 return 0;
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 @Override
161 public String getPage( HttpServletRequest request, int nMode ) throws UserNotSignedException, SiteMessageException
162 {
163
164 String strName = request.getParameter( PARAM_STANDALONE_APP );
165
166 if ( ( strName == null ) || ( strName.length( ) <= 0 ) )
167 {
168
169 return null;
170 }
171
172 PageData/service/content/PageData.html#PageData">PageData data = new PageData( );
173 XPageApplicationEntry entry = XPageAppService.getApplicationEntry( strName );
174
175 if ( ( entry != null ) && ( entry.isEnable( ) ) )
176 {
177 XPageApplication app = XPageAppService.getApplicationInstance( entry );
178 XPage page = app.getPage( request, nMode, entry.getPlugin( ) );
179 data.setContent( page.getContent( ) );
180 data.setName( page.getTitle( ) );
181 }
182 else
183 {
184 AppLogService.error( "The specified Xpage '{}' cannot be retrieved. Check installation of your Xpage application.",
185 ( ) -> SecurityUtil.logForgingProtect( strName ) );
186 SiteMessageService.setMessage( request, MESSAGE_ERROR_APP_BODY, SiteMessage.TYPE_ERROR );
187 }
188
189 return buildPageContent( data, nMode, strName, request );
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 private static String buildPageContent( PageData data, int nMode, String strPluginName, HttpServletRequest request )
206 {
207 HtmlTemplate template;
208 String strFileName = strPluginName + "/" + TEMPLATE_PAGE_FRAMESET;
209 String strFilePath = AppPathService.getPath( PROPERTY_PATH_LUTECE_PLUGINS, strFileName );
210 File file = new File( strFilePath );
211 String strPluginPath = "skin/plugins/";
212
213
214 HashMap<String, Object> model = new HashMap<>( );
215 model.put( Markers.BASE_URL, AppPathService.getBaseUrl( request ) );
216 model.put( Markers.PAGE_NAME, data.getName( ) );
217 model.put( Markers.PAGE_CONTENT, data.getContent( ) );
218
219 Collection<PageInclude> colIncludes = PageIncludeService.getIncludes( );
220
221 for ( PageInclude pic : colIncludes )
222 {
223 pic.fillTemplate( model, data, nMode, request );
224 }
225
226 if ( file.exists( ) )
227 {
228 template = AppTemplateService.getTemplate( strPluginPath + strFileName, request.getLocale( ), model );
229 }
230 else
231 {
232 template = AppTemplateService.getTemplate( TEMPLATE_STANDALONE_PAGE_FRAMESET, request.getLocale( ), model );
233 }
234
235 return template.getHtml( );
236 }
237 }