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