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.blog.business.portlet;
35
36 import java.sql.Date;
37 import java.util.GregorianCalendar;
38 import java.util.HashMap;
39 import java.util.Locale;
40
41 import fr.paris.lutece.portal.business.portlet.PortletHtmlContent;
42 import fr.paris.lutece.portal.service.template.AppTemplateService;
43 import fr.paris.lutece.plugins.blog.business.BlogPageTemplate;
44 import fr.paris.lutece.plugins.blog.business.BlogPageTemplateHome;
45 import fr.paris.lutece.plugins.blog.service.BlogService;
46 import fr.paris.lutece.plugins.blog.service.PublishingService;
47 import fr.paris.lutece.plugins.blog.business.Blog;
48 import fr.paris.lutece.util.html.HtmlTemplate;
49
50 import javax.servlet.http.HttpServletRequest;
51
52
53
54
55 public class BlogPortlet extends PortletHtmlContent
56 {
57 public static final String RESOURCE_ID = "BLOG_PORTLET";
58 public static final String MARK_BLOG = "blog";
59 public static final String MARK_PORTLET_NAME = "portlet_name";
60 public static final String MARK_PORTLET_ID = "portlet_id";
61
62 private int _nPageTemplateDocument;
63
64
65
66
67 public BlogPortlet( )
68 {
69 setPortletTypeId( BlogPortletHome.getInstance( ).getPortletTypeId( ) );
70 }
71
72 private int _nContentId;
73
74 private String _strName;
75
76 private BlogPublication _blogPublication;
77
78
79
80
81
82
83
84
85 @Override
86 public String getHtmlContent( HttpServletRequest request )
87 {
88 GregorianCalendar calendar = new java.util.GregorianCalendar( );
89 Blog blog = BlogService.getInstance( ).loadBlog( this.getContentId( ) );
90 BlogPublication docPub = PublishingService.getInstance( ).getBlogPublication( this.getId( ), this.getContentId( ) );
91
92 HashMap<String, Object> model = new HashMap<>( );
93 BlogPageTemplate pageTemplate = BlogPageTemplateHome.findByPrimaryKey( this.getPageTemplateDocument( ) );
94
95 if ( docPub != null && docPub.getIdBlog( ) != 0 && docPub.getDateBeginPublishing( ).before( new Date( calendar.getTimeInMillis( ) ) )
96 && docPub.getDateEndPublishing( ).after( new Date( calendar.getTimeInMillis( ) ) ) )
97 {
98 if ( this.getDisplayPortletTitle( ) == 0 )
99 {
100
101 model.put( MARK_PORTLET_NAME, this.getName( ) );
102
103 }
104 model.put( MARK_BLOG, blog );
105 }
106 model.put( MARK_PORTLET_ID, this.getId( ) );
107 Locale locale = null;
108 if ( request != null )
109 {
110 locale = request.getLocale( );
111 }
112
113 HtmlTemplate template = AppTemplateService.getTemplate( pageTemplate.getFile( ), locale, model );
114
115 return template.getHtml( );
116
117 }
118
119
120
121
122 public void update( )
123 {
124 BlogPortletHome.getInstance( ).update( this );
125 }
126
127
128
129
130 @Override
131 public void remove( )
132 {
133 BlogPublicationHome.removeByIdPortlet( this.getId( ) );
134 BlogPortletHome.getInstance( ).remove( this );
135 }
136
137
138
139
140
141
142
143 public void setContentId( int nContentId )
144 {
145 _nContentId = nContentId;
146 }
147
148
149
150
151
152
153 public int getContentId( )
154 {
155 return _nContentId;
156 }
157
158
159
160
161
162
163
164 public void setBlogPublication( BlogPublication blogPublication )
165 {
166 _blogPublication = blogPublication;
167 }
168
169
170
171
172
173
174 public BlogPublication getBlogPublication( )
175 {
176 return _blogPublication;
177 }
178
179
180
181
182
183
184
185 public void setPortletName( String strName )
186 {
187 _strName = strName;
188 }
189
190
191
192
193
194
195 public String getPortletName( )
196 {
197 return _strName;
198 }
199
200
201
202
203
204
205
206 public void setPageTemplateDocument( int nPageTemplateDocument )
207 {
208 _nPageTemplateDocument = nPageTemplateDocument;
209 }
210
211
212
213
214
215
216 public int getPageTemplateDocument( )
217 {
218 return _nPageTemplateDocument;
219 }
220 }