View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.web;
35  
36  import fr.paris.lutece.portal.service.admin.AdminUserService;
37  import fr.paris.lutece.portal.service.content.ContentPostProcessorService;
38  import fr.paris.lutece.portal.service.content.ContentService;
39  import fr.paris.lutece.portal.service.datastore.DatastoreService;
40  import fr.paris.lutece.portal.service.editor.EditorBbcodeService;
41  import fr.paris.lutece.portal.service.i18n.I18nService;
42  import fr.paris.lutece.portal.service.init.AppInfo;
43  import fr.paris.lutece.portal.service.init.AppInit;
44  import fr.paris.lutece.portal.service.mail.MailService;
45  import fr.paris.lutece.portal.service.message.ISiteMessageHandler;
46  import fr.paris.lutece.portal.service.message.SiteMessage;
47  import fr.paris.lutece.portal.service.message.SiteMessageException;
48  import fr.paris.lutece.portal.service.message.SiteMessageService;
49  import fr.paris.lutece.portal.service.portal.PortalService;
50  import fr.paris.lutece.portal.service.portal.ThemesService;
51  import fr.paris.lutece.portal.service.resource.IExtendableResource;
52  import fr.paris.lutece.portal.service.resource.IExtendableResourceService;
53  import fr.paris.lutece.portal.service.security.LuteceUser;
54  import fr.paris.lutece.portal.service.security.SecurityService;
55  import fr.paris.lutece.portal.service.security.UserNotSignedException;
56  import fr.paris.lutece.portal.service.spring.SpringContextService;
57  import fr.paris.lutece.portal.service.template.AppTemplateService;
58  import fr.paris.lutece.portal.service.util.AppException;
59  import fr.paris.lutece.portal.service.util.AppLogService;
60  import fr.paris.lutece.portal.service.util.AppPathService;
61  import fr.paris.lutece.portal.service.util.AppPropertiesService;
62  import fr.paris.lutece.portal.web.constants.Markers;
63  import fr.paris.lutece.portal.web.constants.Parameters;
64  import fr.paris.lutece.util.html.HtmlTemplate;
65  import fr.paris.lutece.util.url.UrlItem;
66  
67  import org.apache.commons.lang3.StringUtils;
68  import org.apache.commons.lang3.BooleanUtils;
69  
70  import java.io.UnsupportedEncodingException;
71  
72  import java.net.URLEncoder;
73  
74  import java.util.Enumeration;
75  import java.util.HashMap;
76  import java.util.List;
77  import java.util.Locale;
78  import java.util.Map;
79  
80  import javax.servlet.http.HttpServletRequest;
81  import javax.servlet.http.HttpSession;
82  
83  /**
84   * This class provides the methods to display the page of the site
85   */
86  public class PortalJspBean
87  {
88      public static final int MODE_HTML = 0;
89      public static final int MODE_ADMIN = 1;
90      private static final String TEMPLATE_PAGE_ERROR404 = "skin/site/page_error404.html";
91      private static final String TEMPLATE_PAGE_ERROR500 = "skin/site/page_error500.html";
92      private static final String TEMPLATE_POPUP_CREDITS = "skin/site/popup_credits.html";
93      private static final String TEMPLATE_POPUP_LEGAL_INFO = "skin/site/popup_legal_info.html";
94      private static final String TEMPLATE_STARTUP_FAILURE = "skin/site/startup_failure.html";
95      private static final String TEMPLATE_SEND_RESOURCE = "skin/site/popup_send_resource.html";
96      private static final String TEMPLATE_EMAIL_SEND_RESOURCE = "skin/site/mail_send_resource.html";
97      private static final String PROPERTY_INFOS_CNIL = "lutece.legal.infos";
98      private static final String ATTRIBUTE_LOGIN_NEXT_URL = "luteceLoginNextUrl";
99      private static final String ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL = "uploadFilterSiteNextUrl";
100     private static final String MARK_PORTAL_DOMAIN = "portal_domain";
101     private static final String MARK_ADDRESS_INFOS_CNIL = "confidentiality_info";
102     private static final String MARK_APP_VERSION = "app_version";
103     private static final String MARK_FAILURE_MESSAGE = "failure_message";
104     private static final String MARK_FAILURE_DETAILS = "failure_details";
105     private static final String MARK_RESOURCE_URL = "resource_url";
106     private static final String MARK_RESOURCE = "resource";
107     private static final String MARK_ERROR = "error";
108     private static final String MARK_SUCCESS = "success";
109     private static final String MARK_ERROR_CAUSE = "error_cause";
110     private static final String MARK_PLUGIN_THEME = "plugin_theme";
111     private static final String MARK_THEME = "theme";
112     private static final String BEAN_SITE_MESSAGE_HANDLER = "siteMessageHandler";
113     private static final String PARAMETER_EXTENDABLE_RESOURCE_TYPE = "extendableResourceType";
114     private static final String PARAMETER_ID_EXTENDABLE_RESOURCE = "idExtendableResource";
115     private static final String PARAMETER_SENDER_NAME = "senderName";
116     private static final String PARAMETER_SENDER_FIRST_NAME = "senderFirstname";
117     private static final String PARAMETER_SENDER_EMAIL = "senderEmail";
118     private static final String PARAMETER_CONTENT = "content";
119     private static final String PARAMETER_SEND = "send";
120     private static final String MESSAGE_ERROR_WRONG_SENDER_EMAIL = "portal.site.error.wrongEmailFormat";
121     private static final String MESSAGE_ERROR_MANDATORY_FIELDS = "portal.util.message.mandatoryFields";
122     private static final String MESSAGE_NO_RESOURCE_FOUND = "portal.site.error.noResourceFound";
123     private static final String PROPERTY_PAGE_TITLE_ERROR404 = "portal.util.error404.title";
124     private static final String PROPERTY_PAGE_TITLE_CREDITS = "portal.site.popup_credits.pageTitle";
125     private static final String PROPERTY_PAGE_TITLE_LEGAL_INFO = "portal.site.popup_legal_info.pageTitle";
126     private static final String PROPERTY_PAGE_TITLE_STARTUP_FAILURE = "portal.util.startup.failure.title";
127     private static final String PROPERTY_PAGE_TITLE_ERROR500 = "portal.util.error500.title";
128     private static final String PROPERTY_DEBUG = "error.page.debug";
129     private static final String PROPERTY_DEBUG_DEFAULT = "true";
130     private static final String CONSTANT_SPACE = " ";
131     private static final String KEY_WEBMASTER_EMAIL = "portal.site.site_property.noreply_email";
132 
133     /**
134      * Returns the content of a page according to the parameters found in the http request. One distinguishes article, page and xpage and the mode.
135      *
136      * @param request
137      *            The http request
138      * @return the html code for the display of a page of a site
139      * @throws UserNotSignedException
140      *             The UserNotSignedException
141      * @throws SiteMessageException
142      *             occurs when a site message need to be displayed
143      */
144     public String getContent( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
145     {
146         return getContent( request, MODE_HTML );
147     }
148 
149     /**
150      * Returns the content of a page according to the parameters found in the http request. One distinguishes article, page and xpage and the mode.
151      *
152      * @param request
153      *            The http request
154      * @param nMode
155      *            The mode (normal or administration)
156      * @return the html code for the display of a page of a site
157      * @throws UserNotSignedException
158      *             The UserNotSignedException
159      * @throws SiteMessageException
160      *             occurs when a site message need to be displayed
161      */
162     public String getContent( HttpServletRequest request, int nMode ) throws UserNotSignedException, SiteMessageException
163     {
164         if ( !AppInit.isWebappSuccessfullyLoaded( ) )
165         {
166             return getStartUpFailurePage( request );
167         }
168 
169         // Try to register the user in case of external authentication
170         if ( SecurityService.isAuthenticationEnable( ) )
171         {
172             try
173             {
174                 if ( SecurityService.getInstance( ).isExternalAuthentication( ) && !SecurityService.getInstance( ).isMultiAuthenticationSupported( ) )
175                 {
176                     SecurityService.getInstance( ).getRemoteUser( request );
177                 }
178                 else
179                 {
180                     LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
181 
182                     // no checks are needed if the user is already registered
183                     // if multiauthentication is supported, then when have to check remote user
184                     // before other check
185                     if ( user == null && SecurityService.getInstance( ).isMultiAuthenticationSupported( ) )
186                     {
187 
188                         // getRemoteUser needs to be checked before any check so the user is registered
189                         // getRemoteUser throws an exception if no user found, but here we have to
190                         // bypass this exception to display login page.
191                         SecurityService.getInstance( ).getRemoteUser( request );
192                     }
193                 }
194             }
195             catch( UserNotSignedException unse )
196             {
197                 // nothing to do,Leave LuteceAuthenticationFilter testing if the access to the
198                 // content requires authentication
199             }
200         }
201 
202         // Search the content service invoked and call its getPage method
203         ContentService cs = PortalService.getInvokedContentService( request );
204 
205         String strContent = ( cs != null ) ? cs.getPage( request, nMode ) : PortalService.getDefaultPage( request, nMode );
206 
207         if ( ContentPostProcessorService.hasProcessor( ) )
208         {
209             strContent = ContentPostProcessorService.process( request, strContent );
210         }
211 
212         return strContent;
213     }
214 
215     /**
216      * Returns the content of a page according to the parameters found in the http request. One distinguishes article, page and xpage and the mode.
217      *
218      * @param request
219      *            The http request
220      * @return the html code for the display of a page of a site
221      *
222      */
223     public String getSiteMessageContent( HttpServletRequest request )
224     {
225         return getSiteMessageContent( request, MODE_HTML );
226     }
227 
228     /**
229      * Returns the content of a page according to the parameters found in the http request. One distinguishes article, page and xpage and the mode.
230      *
231      * @param request
232      *            The http request
233      * @param nMode
234      *            The mode (normal or administration)
235      * @return the html code for the display of a page of a site
236      *
237      */
238     public String getSiteMessageContent( HttpServletRequest request, int nMode )
239     {
240         String strContent = null;
241 
242         if ( !AppInit.isWebappSuccessfullyLoaded( ) )
243         {
244             return getStartUpFailurePage( request );
245         }
246 
247         ISiteMessageHandler handler = SpringContextService.getBean( BEAN_SITE_MESSAGE_HANDLER );
248 
249         if ( handler.hasMessage( request ) )
250         {
251             strContent = handler.getPage( request, nMode );
252         }
253 
254         return strContent;
255     }
256 
257     /**
258      * Returns the code for the popup of the credits
259      * 
260      * @param request
261      *            The HTTP request
262      * @return the html code for the popup credits
263      */
264     public String getStartUpFailurePage( HttpServletRequest request )
265     {
266         HashMap<String, Object> model = new HashMap<>( );
267         fillPageModel( request, model );
268         model.put( MARK_FAILURE_MESSAGE, AppInit.getLoadingFailureCause( ) );
269         model.put( MARK_FAILURE_DETAILS, AppInit.getLoadingFailureDetails( ) );
270         model.put( Markers.PAGE_TITLE, I18nService.getLocalizedString( PROPERTY_PAGE_TITLE_STARTUP_FAILURE, request.getLocale( ) ) );
271 
272         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_STARTUP_FAILURE, request.getLocale( ), model );
273 
274         return template.getHtml( );
275     }
276 
277     /**
278      * Returns the code for the popup of the credits
279      *
280      * @param request
281      *            The Http Request
282      * @return the html code for the popup credits
283      */
284     public String getCredits( HttpServletRequest request )
285     {
286         HashMap<String, Object> model = new HashMap<>( );
287         fillPageModel( request, model );
288         model.put( MARK_APP_VERSION, AppInfo.getVersion( ) );
289         model.put( MARK_PORTAL_DOMAIN, PortalService.getSiteName( ) );
290         model.put( Markers.PAGE_TITLE, I18nService.getLocalizedString( PROPERTY_PAGE_TITLE_CREDITS, request.getLocale( ) ) );
291 
292         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_POPUP_CREDITS, request.getLocale( ), model );
293 
294         return template.getHtml( );
295     }
296 
297     /**
298      * Returns the code for the popup of the legal infos
299      *
300      * @param request
301      *            The Http Request
302      * @return the html code for the legal infos
303      */
304     public String getLegalInfos( HttpServletRequest request )
305     {
306         HashMap<String, Object> model = new HashMap<>( );
307         fillPageModel( request, model );
308         model.put( MARK_ADDRESS_INFOS_CNIL, AppPropertiesService.getProperty( PROPERTY_INFOS_CNIL ) );
309         model.put( MARK_PORTAL_DOMAIN, PortalService.getSiteName( ) );
310         model.put( Markers.PAGE_TITLE, I18nService.getLocalizedString( PROPERTY_PAGE_TITLE_LEGAL_INFO, request.getLocale( ) ) );
311 
312         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_POPUP_LEGAL_INFO, request.getLocale( ), model );
313 
314         return template.getHtml( );
315     }
316 
317     /**
318      * Returns the 404 Error page
319      * 
320      * @param request
321      *            The HTTP request
322      * @return The page
323      */
324     public String getError404Page( HttpServletRequest request )
325     {
326         HashMap<String, Object> model = new HashMap<>( );
327         fillPageModel( request, model );
328         model.put( Markers.PAGE_TITLE, I18nService.getLocalizedString( PROPERTY_PAGE_TITLE_ERROR404, request.getLocale( ) ) );
329 
330         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PAGE_ERROR404, request.getLocale( ), model );
331 
332         return template.getHtml( );
333     }
334 
335     /**
336      * Returns the 500 Error page
337      * 
338      * @param request
339      *            The HTTP request
340      * @param exception
341      *            The Exception
342      * @return The page
343      */
344     public String getError500Page( HttpServletRequest request, Throwable exception )
345     {
346         if ( exception instanceof AppException )
347         {
348             // AppException calls AppLogService.error( message, this ) in the
349             // constructor, so don't call it here again Call toString to have
350             // the Class and the message to be able to indentify the correct
351             // stacktrace in the preceding logs.
352             AppLogService.error( "Error 500 : Caused by previous Critical AppException" );
353         }
354         else
355         {
356             AppLogService.error( "Error 500 : {}", exception.getMessage( ), exception );
357         }
358 
359         String strCause = null;
360 
361         if ( AppPropertiesService.getProperty( PROPERTY_DEBUG, PROPERTY_DEBUG_DEFAULT ).equalsIgnoreCase( "true" ) )
362         {
363             strCause = exception.getMessage( );
364 
365             if ( exception.getCause( ) != null )
366             {
367                 strCause += exception.getCause( ).getMessage( );
368             }
369         }
370 
371         return getError500Page( request, strCause );
372     }
373 
374     /**
375      * Returns the 500 Error page
376      * 
377      * @param request
378      *            The HTTP request
379      * @param strCause
380      *            The message
381      * @return The page
382      */
383     public String getError500Page( HttpServletRequest request, String strCause )
384     {
385         HashMap<String, Object> model = new HashMap<>( );
386         fillPageModel( request, model );
387         model.put( Markers.PAGE_TITLE, I18nService.getLocalizedString( PROPERTY_PAGE_TITLE_ERROR500, request.getLocale( ) ) );
388         model.put( MARK_ERROR_CAUSE, strCause );
389 
390         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PAGE_ERROR500, request.getLocale( ), model );
391 
392         return template.getHtml( );
393     }
394 
395     /**
396      * Fill the model'map with commons values
397      * 
398      * @param request
399      *            The HTTP request
400      * @param model
401      *            The map containing the model
402      */
403     private static void fillPageModel( HttpServletRequest request, HashMap<String, Object> model )
404     {
405         model.put( Markers.BASE_URL, AppPathService.getBaseUrl( request ) );
406         model.put( MARK_PLUGIN_THEME, null );
407         model.put( MARK_THEME, ThemesService.getGlobalThemeObject( ) );
408     }
409 
410     /**
411      * This method is called by Portal.jsp when it caught an UserNotSignedException. It gives the login url and stores in the session the url asked
412      * 
413      * @param request
414      *            The HTTP request
415      * @return The login page URL
416      * @since v1.1
417      */
418     public static String redirectLogin( HttpServletRequest request )
419     {
420         String strNextUrl = request.getRequestURI( );
421         UrlIteml/UrlItem.html#UrlItem">UrlItem url = new UrlItem( strNextUrl );
422         Enumeration<String> enumParams = request.getParameterNames( );
423 
424         while ( enumParams.hasMoreElements( ) )
425         {
426             String strParamName = enumParams.nextElement( );
427 
428             try
429             {
430                 url.addParameter( strParamName, URLEncoder.encode( request.getParameter( strParamName ), "UTF-8" ) );
431             }
432             catch( UnsupportedEncodingException ex )
433             {
434                 AppLogService.error( "Redirection error while encoding URL : {}", ex.getMessage( ), ex );
435             }
436         }
437 
438         HttpSession session = request.getSession( true );
439         session.setAttribute( ATTRIBUTE_LOGIN_NEXT_URL, url.getUrl( ) );
440 
441         String strRedirect = SecurityService.getInstance( ).getLoginPageUrl( );
442 
443         return AppPathService.getAbsoluteUrl( request, strRedirect );
444     }
445 
446     /**
447      * Returns the url (asked before login) to redirect after login
448      * 
449      * @param request
450      *            The Http request
451      * @return The url asked before login
452      * @since v1.1
453      */
454     public static String getLoginNextUrl( HttpServletRequest request )
455     {
456         HttpSession session = request.getSession( );
457         return (String) session.getAttribute( ATTRIBUTE_LOGIN_NEXT_URL );
458     }
459 
460     /**
461      * Set the upload filter site next url
462      * 
463      * @param request
464      *            the HTTP request
465      */
466     public static void setUploadFilterSiteNextUrl( HttpServletRequest request )
467     {
468         String strNextUrl = request.getRequestURI( );
469         UrlIteml/UrlItem.html#UrlItem">UrlItem url = new UrlItem( strNextUrl );
470         Enumeration<String> enumParams = request.getParameterNames( );
471 
472         while ( enumParams.hasMoreElements( ) )
473         {
474             String strParamName = enumParams.nextElement( );
475             url.addParameter( strParamName, request.getParameter( strParamName ) );
476         }
477 
478         HttpSession session = request.getSession( true );
479         session.setAttribute( ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL, url.getUrl( ) );
480     }
481 
482     /**
483      * Get the upload filter site next url
484      * 
485      * @param request
486      *            the HTTP request
487      * @return the next url
488      */
489     public static String getUploadFilterSiteNextUrl( HttpServletRequest request )
490     {
491         HttpSession session = request.getSession( );
492         return (String) session.getAttribute( ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL );
493     }
494 
495     /**
496      * Remove the upload filter next url from the session
497      * 
498      * @param request
499      *            the HTTP request
500      */
501     public static void removeUploadFilterSiteNextUrl( HttpServletRequest request )
502     {
503         HttpSession session = request.getSession( );
504         session.removeAttribute( ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL );
505     }
506 
507     /**
508      * Do send a resource
509      * 
510      * @param request
511      *            The request
512      * @return The HTML content to display
513      * @throws SiteMessageException
514      *             If the resource or its associated service is not found
515      */
516     public static String sendResource( HttpServletRequest request ) throws SiteMessageException
517     {
518         String strSenderEmail = DatastoreService.getDataValue( KEY_WEBMASTER_EMAIL, "no-reply@mydomain.com" );
519         String strSenderName = request.getParameter( PARAMETER_SENDER_NAME );
520         String strSenderFirstName = request.getParameter( PARAMETER_SENDER_FIRST_NAME );
521         String strReceipientEmail = request.getParameter( Parameters.EMAIL );
522         String strContent = request.getParameter( PARAMETER_CONTENT );
523         String strExtendableResourceType = request.getParameter( PARAMETER_EXTENDABLE_RESOURCE_TYPE );
524         String strIdExtendableResource = request.getParameter( PARAMETER_ID_EXTENDABLE_RESOURCE );
525         String strSend = request.getParameter( PARAMETER_SEND );
526         IExtendableResource resource = null;
527 
528         String strError = checkSendParams( strSend, strSenderEmail, strSenderName, strSenderFirstName, strReceipientEmail, strContent, request.getLocale( ) );
529 
530         // We get the resource from its resource service
531         IExtendableResourceService resourceService = null;
532         List<IExtendableResourceService> listExtendableResourceService = SpringContextService.getBeansOfType( IExtendableResourceService.class );
533 
534         for ( IExtendableResourceService extendableResourceService : listExtendableResourceService )
535         {
536             if ( extendableResourceService.isInvoked( strExtendableResourceType ) )
537             {
538                 resourceService = extendableResourceService;
539                 resource = extendableResourceService.getResource( strIdExtendableResource, strExtendableResourceType );
540             }
541         }
542 
543         if ( ( resourceService == null ) || ( resource == null ) )
544         {
545             SiteMessageService.setMessage( request, MESSAGE_NO_RESOURCE_FOUND, SiteMessage.TYPE_ERROR );
546             throw new SiteMessageException( );
547         }
548 
549         String strResourceUrl = resourceService.getResourceUrl( strIdExtendableResource, strExtendableResourceType );
550         Map<String, Object> model = new HashMap<>( );
551         model.put( MARK_RESOURCE, resource );
552         model.put( MARK_RESOURCE_URL, strResourceUrl );
553         model.put( Markers.BASE_URL, AppPathService.getBaseUrl( request ) );
554 
555         if ( ( strSend != null ) && ( strError == null ) )
556         {
557             Map<String, Object> mailModel = new HashMap<>( );
558             mailModel.put( Markers.BASE_URL, AppPathService.getBaseUrl( request ) );
559             mailModel.put( MARK_RESOURCE, resource );
560             mailModel.put( PARAMETER_SENDER_EMAIL, strSenderEmail );
561             mailModel.put( PARAMETER_SENDER_NAME, strSenderName );
562             mailModel.put( PARAMETER_SENDER_FIRST_NAME, strSenderFirstName );
563             mailModel.put( Parameters.EMAIL, strReceipientEmail );
564             mailModel.put( PARAMETER_CONTENT, EditorBbcodeService.getInstance( ).parse( strContent ) );
565             mailModel.put( MARK_RESOURCE_URL, resourceService.getResourceUrl( strIdExtendableResource, strExtendableResourceType ) );
566 
567             HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_EMAIL_SEND_RESOURCE, request.getLocale( ), mailModel );
568             MailService.sendMailHtml( strReceipientEmail, strSenderFirstName + CONSTANT_SPACE + strSenderName, strSenderEmail,
569                     resource.getExtendableResourceName( ), template.getHtml( ) );
570             model.put( MARK_SUCCESS, MARK_SUCCESS );
571         }
572         else
573         {
574             model.put( PARAMETER_SENDER_NAME, strSenderName );
575             model.put( PARAMETER_SENDER_FIRST_NAME, strSenderFirstName );
576             model.put( Parameters.EMAIL, strReceipientEmail );
577             model.put( PARAMETER_CONTENT, strContent );
578             model.put( MARK_ERROR, strError );
579         }
580 
581         model.put( Markers.PAGE_MAIN_MENU, StringUtils.EMPTY );
582 
583         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SEND_RESOURCE, request.getLocale( ), model );
584 
585         return template.getHtml( );
586     }
587 
588     private static String checkSendParams( String strSend, String strSenderEmail, String strSenderName, String strSenderFirstName, String strReceipientEmail,
589             String strContent, Locale locale )
590     {
591         String strError = null;
592         // If the form was submited, we check data
593         if ( strSend != null )
594         {
595             boolean [ ] conditions = new boolean [ ] {
596                     StringUtils.isBlank( strSenderEmail ), StringUtils.isBlank( strSenderName ), StringUtils.isBlank( strSenderFirstName ),
597                     StringUtils.isBlank( strReceipientEmail ), StringUtils.isBlank( strContent )
598             };
599 
600             if ( BooleanUtils.or( conditions ) )
601             {
602                 strError = I18nService.getLocalizedString( MESSAGE_ERROR_MANDATORY_FIELDS, locale );
603             }
604 
605             if ( ( strError != null ) && ( !AdminUserService.checkEmail( strSenderEmail ) || !AdminUserService.checkEmail( strReceipientEmail ) ) )
606             {
607                 strError = I18nService.getLocalizedString( MESSAGE_ERROR_WRONG_SENDER_EMAIL, locale );
608             }
609         }
610         return strError;
611     }
612 }