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.business.portlet;
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.service.NewsletterPlugin;
39 import fr.paris.lutece.plugins.newsletter.util.NewsletterUtils;
40 import fr.paris.lutece.portal.business.portlet.Portlet;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import fr.paris.lutece.portal.service.plugin.PluginService;
43 import fr.paris.lutece.util.date.DateUtil;
44 import fr.paris.lutece.util.xml.XmlUtil;
45
46 import javax.servlet.http.HttpServletRequest;
47 import java.util.ArrayList;
48
49
50
51
52 public class NewsLetterArchivePortlet extends Portlet
53 {
54
55 private static final String TAG_NEWSLETTER_SENDING_LIST = "newsletter-sending-list";
56 private static final String TAG_NEWSLETTER_SENDING = "newsletter-sending";
57 private static final String TAG_NEWSLETTER_SENDING_ID = "newsletter-sending-id";
58 private static final String TAG_NEWSLETTER_SENDING_DATE = "newsletter-sending-date";
59 private static final String TAG_NEWSLETTER_SENDING_SUBJECT = "newsletter-sending-subject";
60
61
62
63
64
65
66
67
68 public String getXmlDocument( HttpServletRequest request )
69 {
70 return XmlUtil.getXmlHeader( ) + getXml( request );
71 }
72
73
74
75
76
77
78
79
80 public String getXml( HttpServletRequest request )
81 {
82 StringBuffer sbXml = new StringBuffer( );
83 Plugin plugin = PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME );
84 XmlUtil.beginElement( sbXml, TAG_NEWSLETTER_SENDING_LIST );
85
86 ArrayList<Integer> listSendingIds = NewsLetterArchivePortletHome.findSendingsInPortlet( this.getId( ), plugin );
87 ArrayList<SendingNewsLetter> listSendings = SendingNewsLetterHome.findSendingsByIds( listSendingIds, plugin );
88
89 for ( SendingNewsLetter sending : listSendings )
90 {
91 XmlUtil.beginElement( sbXml, TAG_NEWSLETTER_SENDING );
92 XmlUtil.addElement( sbXml, TAG_NEWSLETTER_SENDING_ID, sending.getId( ) );
93 XmlUtil.addElement( sbXml, TAG_NEWSLETTER_SENDING_DATE, DateUtil.getDateString( sending.getDate( ), NewsletterUtils.getLocale( request ) ) );
94 XmlUtil.addElementHtml( sbXml, TAG_NEWSLETTER_SENDING_SUBJECT, sending.getEmailSubject( ) );
95 XmlUtil.endElement( sbXml, TAG_NEWSLETTER_SENDING );
96 }
97
98 XmlUtil.endElement( sbXml, TAG_NEWSLETTER_SENDING_LIST );
99
100 return addPortletTags( sbXml );
101 }
102
103
104
105
106 public void update( )
107 {
108 NewsLetterArchivePortletHome.getInstance( ).update( this );
109 }
110
111
112
113
114 public void remove( )
115 {
116 NewsLetterArchivePortletHome.getInstance( ).remove( this );
117 }
118 }