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.plugins.newsletter.service;
35
36 import fr.paris.lutece.plugins.newsletter.business.SendingNewsLetter;
37 import fr.paris.lutece.plugins.newsletter.business.SendingNewsLetterHome;
38 import fr.paris.lutece.plugins.newsletter.util.NewsLetterConstants;
39 import fr.paris.lutece.portal.service.message.SiteMessage;
40 import fr.paris.lutece.portal.service.message.SiteMessageException;
41 import fr.paris.lutece.portal.service.message.SiteMessageService;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.plugin.PluginService;
44 import fr.paris.lutece.portal.service.template.AppTemplateService;
45 import fr.paris.lutece.portal.service.util.AppPathService;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47
48 import java.util.HashMap;
49 import java.util.Map;
50
51 import javax.servlet.http.HttpServletRequest;
52
53 import org.apache.commons.lang3.StringUtils;
54
55 import static fr.paris.lutece.portal.service.admin.AdminUserService.getLocale;
56
57
58
59
60 public final class NewsLetterArchiveService
61 {
62 private static final String REGEX_ID = "^[\\d]+$";
63 private static final String TEMPLATE_VIEW_NEWSLETTER_ARCHIVE = "skin/plugins/newsletter/page_newsletter_archive.html";
64 private static NewsLetterArchiveServiceewsLetterArchiveService.html#NewsLetterArchiveService">NewsLetterArchiveService _singleton = new NewsLetterArchiveService( );
65
66
67
68
69 private NewsLetterArchiveService( )
70 {
71 if ( _singleton == null )
72 {
73 _singleton = this;
74 }
75 }
76
77
78
79
80
81
82 public static NewsLetterArchiveService getInstance( )
83 {
84 return _singleton;
85 }
86
87
88
89
90
91
92
93
94
95
96 public String getShowArchivePage( HttpServletRequest request ) throws SiteMessageException
97 {
98 Plugin plugin = PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME );
99 String strSendingId = request.getParameter( NewsLetterConstants.PARAMETER_SENDING_ID );
100 String strBaseUrl = AppPathService.getBaseUrl( request );
101
102 if ( ( strSendingId == null ) || !strSendingId.matches( REGEX_ID ) )
103 {
104 SiteMessageService.setMessage( request, NewsLetterConstants.PROPERTY_NO_NEWSLETTER_CHOSEN_TITLE_MESSAGE, SiteMessage.TYPE_ERROR );
105 return StringUtils.EMPTY;
106 }
107
108 int nSendingId = Integer.parseInt( strSendingId );
109 SendingNewsLetter sending = SendingNewsLetterHome.findByPrimaryKey( nSendingId, plugin );
110
111 if ( ( sending == null ) || StringUtils.isEmpty( sending.getHtml( ) ) )
112 {
113 SiteMessageService.setMessage( request, NewsLetterConstants.PROPERTY_NO_NEWSLETTER_CHOSEN_TITLE_MESSAGE, SiteMessage.TYPE_ERROR );
114 return StringUtils.EMPTY;
115 }
116
117 Map<String, Object> model = new HashMap<String, Object>( );
118 model.put( NewsLetterConstants.MARK_SENDING, sending );
119
120 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_VIEW_NEWSLETTER_ARCHIVE, getLocale( request ), model );
121 template.substitute( NewsLetterConstants.WEBAPP_PATH_FOR_LINKSERVICE, strBaseUrl );
122
123 return template.getHtml( );
124 }
125 }