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
54 import java.io.File;
55
56 import java.util.Collection;
57 import java.util.HashMap;
58
59 import javax.servlet.http.HttpServletRequest;
60
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 public String getName( )
85 {
86 return CONTENT_SERVICE_NAME;
87 }
88
89
90
91
92
93
94
95 public boolean isInvoked( HttpServletRequest request )
96 {
97 String strStandaloneApp = request.getParameter( PARAM_STANDALONE_APP );
98
99 if ( ( strStandaloneApp != null ) && ( strStandaloneApp.length( ) > 0 ) )
100 {
101 return true;
102 }
103
104 return false;
105 }
106
107
108
109
110
111
112 public void setCache( boolean bCache )
113 {
114 }
115
116
117
118
119
120
121 public boolean isCacheEnable( )
122 {
123 return false;
124 }
125
126
127
128
129 public void resetCache( )
130 {
131 }
132
133
134
135
136
137
138 public int getCacheSize( )
139 {
140 return 0;
141 }
142
143
144
145
146
147
148
149
150
151
152 public String getPage( HttpServletRequest request, int nMode )
153 throws UserNotSignedException, SiteMessageException
154 {
155
156 String strName = request.getParameter( PARAM_STANDALONE_APP );
157
158 if ( ( strName == null ) || ( strName.length( ) <= 0 ) )
159 {
160
161 return null;
162 }
163
164 PageData data = new PageData( );
165 XPageApplicationEntry entry = XPageAppService.getApplicationEntry( strName );
166
167 if ( ( entry != null ) && ( entry.isEnable( ) ) )
168 {
169 XPageApplication app = XPageAppService.getApplicationInstance( entry );
170 XPage page = app.getPage( request, nMode, entry.getPlugin( ) );
171 data.setContent( page.getContent( ) );
172 data.setName( page.getTitle( ) );
173 }
174 else
175 {
176 AppLogService.error( "The specified Xpage '" + strName +
177 "' cannot be retrieved. Check installation of your Xpage application." );
178 SiteMessageService.setMessage( request, MESSAGE_ERROR_APP_BODY, SiteMessage.TYPE_ERROR );
179 }
180
181 return buildPageContent( data, nMode, strName, request );
182 }
183
184
185
186
187
188
189
190
191
192
193 private static String buildPageContent( PageData data, int nMode, String strPluginName, HttpServletRequest request )
194 {
195 HtmlTemplate template;
196 String strFileName = strPluginName + "/" + TEMPLATE_PAGE_FRAMESET;
197 String strFilePath = AppPathService.getPath( PROPERTY_PATH_LUTECE_PLUGINS, strFileName );
198 File file = new File( strFilePath );
199 String strPluginPath = "skin/plugins/";
200
201
202 HashMap<String, Object> model = new HashMap<String, Object>( );
203 model.put( Markers.BASE_URL, AppPathService.getBaseUrl( request ) );
204 model.put( Markers.PAGE_NAME, data.getName( ) );
205 model.put( Markers.PAGE_CONTENT, data.getContent( ) );
206
207 Collection<PageInclude> colIncludes = PageIncludeService.getIncludes( );
208
209 for ( PageInclude pic : colIncludes )
210 {
211 pic.fillTemplate( model, data, nMode, request );
212 }
213
214 if ( file.exists( ) )
215 {
216 template = AppTemplateService.getTemplate( strPluginPath + strFileName, request.getLocale( ), model );
217 }
218 else
219 {
220 template = AppTemplateService.getTemplate( TEMPLATE_STANDALONE_PAGE_FRAMESET, request.getLocale( ), model );
221 }
222
223 return template.getHtml( );
224 }
225 }