1 /*
2 * Copyright (c) 2002-2014, Mairie de 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.plugins.whatsnew.business;
35
36 import fr.paris.lutece.plugins.whatsnew.utils.constants.WhatsNewConstants;
37 import fr.paris.lutece.util.date.DateUtil;
38 import fr.paris.lutece.util.xml.XmlUtil;
39
40 import org.apache.commons.lang.StringUtils;
41
42 import java.sql.Timestamp;
43 import java.util.Locale;
44
45 import javax.servlet.http.HttpServletRequest;
46
47
48 /**
49 *
50 * WhatsNew
51 *
52 */
53 public abstract class WhatsNew implements IWhatsNew
54 {
55 public static final String RESOURCE_TYPE = "WHATSNEW";
56 private WhatsNewType _whatsNewType;
57
58 /** Title of the whatsnew object */
59 private String _strTitle;
60
61 /** Description of the whatsnew object */
62 private String _strDescription;
63
64 /** Date of the last update */
65 private Timestamp _dateUpdate;
66
67 /** ids that are used to build the url to the element */
68 private int _nPageId;
69 private int _nPortletId;
70 private int _nDocumentId;
71 private String _strType;
72
73 /**
74 * Creates a new WhatsNew object.
75 */
76 public WhatsNew( )
77 {
78 }
79
80 /**
81 * Returns the type of the whatsnew object
82 * @return the type of the whatsnew object
83 */
84 public WhatsNewType getWhatsNewType( )
85 {
86 return _whatsNewType;
87 }
88
89 /**
90 * Returns the title of the whatsnew object
91 * @return the title of the whatsnew object
92 */
93 public String getTitle( )
94 {
95 return _strTitle;
96 }
97
98 /**
99 * Returns the description of the whatsnew object
100 * @return the description of the whatsnew object
101 */
102 public String getDescription( )
103 {
104 return _strDescription;
105 }
106
107 /**
108 * Returns the date of the last update of the whatsnew object
109 * @return the date of the last update of the whatsnew object
110 */
111 public Timestamp getDateUpdate( )
112 {
113 return _dateUpdate;
114 }
115
116 /**
117 * Sets the type of the whatsnew object to the specified String
118 * @param whatsNewType the new type of the whatsnew object
119 */
120 public void setWhatsNewType( WhatsNewType whatsNewType )
121 {
122 _whatsNewType = whatsNewType;
123 }
124
125 /**
126 * Sets the title of the whatsnew object to the specified String
127 * @param strTitle the new title of the whatsnew object
128 */
129 public void setTitle( String strTitle )
130 {
131 _strTitle = strTitle;
132 }
133
134 /**
135 * Sets the description of the whatsnew object to the specified String
136 * @param strDescription the new description of the whatsnew object
137 */
138 public void setDescription( String strDescription )
139 {
140 _strDescription = strDescription;
141 }
142
143 /**
144 * Sets the date of the last update of the whatsnew object
145 * @param date the date update of the whatsnew object
146 */
147 public void setDateUpdate( Timestamp date )
148 {
149 _dateUpdate = date;
150 }
151
152 /**
153 * Get the document ID
154 * @return Returns the _nDocumentId.
155 */
156 public int getDocumentId( )
157 {
158 return _nDocumentId;
159 }
160
161 /**
162 * Set the document ID
163 * @param nDocumentId The _nDocumentId to set.
164 */
165 public void setDocumentId( int nDocumentId )
166 {
167 _nDocumentId = nDocumentId;
168 }
169
170 /**
171 * Get the page ID
172 * @return Returns the _nPageId.
173 */
174 public int getPageId( )
175 {
176 return _nPageId;
177 }
178
179 /**
180 * Set the page ID
181 * @param nPageId The _nPageId to set.
182 */
183 public void setPageId( int nPageId )
184 {
185 _nPageId = nPageId;
186 }
187
188 /**
189 * Get the portlet ID
190 * @return Returns the _nPortletId.
191 */
192 public int getPortletId( )
193 {
194 return _nPortletId;
195 }
196
197 /**
198 * Set the portlet ID
199 * @param nPortletId The _nPortletId to set.
200 */
201 public void setPortletId( int nPortletId )
202 {
203 _nPortletId = nPortletId;
204 }
205
206 /**
207 * Get the type
208 * @return the type
209 */
210 public String getType( )
211 {
212 return _strType;
213 }
214
215 /**
216 * Set the type
217 * @param strType the type
218 */
219 public void setType( String strType )
220 {
221 _strType = strType;
222 }
223
224 /////////////////////////////////////////////////////////////////////////////
225 // XML generation
226
227 /**
228 * Adds the XML header to the XML content of this whatsnew object and returns it
229 * @param request The HTTP Servlet request
230 * @return the Xml document with header
231 */
232 public String getXmlDocument( HttpServletRequest request )
233 {
234 return XmlUtil.getXmlHeader( ) + getXml( request );
235 }
236
237 /**
238 * Builds the XML content of this whatsnew object and returns it
239 * @param request The HTTP Servlet request
240 * @return the Xml content of this whatsnew object
241 */
242 public String getXml( HttpServletRequest request )
243 {
244 Locale locale;
245
246 if ( request != null )
247 {
248 locale = request.getLocale( );
249 }
250 else
251 {
252 locale = Locale.getDefault( );
253 }
254 StringBuffer strXml = new StringBuffer( );
255 XmlUtil.beginElement( strXml, WhatsNewConstants.TAG_WHATS_NEW_ELEMENT );
256
257 XmlUtil.addElementHtml( strXml, WhatsNewConstants.TAG_WHATS_NEW_TYPE, getWhatsNewType( ).getName( ) );
258 XmlUtil.addElementHtml( strXml, WhatsNewConstants.TAG_WHATS_NEW_TITLE, getTitle( ) );
259
260 if ( StringUtils.isNotBlank( getDescription( ) ) )
261 {
262 XmlUtil.addElementHtml( strXml, WhatsNewConstants.TAG_WHATS_NEW_DESCRIPTION, getDescription( ) );
263 }
264
265 XmlUtil.addElementHtml( strXml, WhatsNewConstants.TAG_WHATS_NEW_DATE_UPDATE,
266 DateUtil.getDateString( getDateUpdate( ), locale ) );
267
268 XmlUtil.addElementHtml( strXml, WhatsNewConstants.TAG_WHATS_NEW_URL, buildUrl( ) );
269
270 XmlUtil.endElement( strXml, WhatsNewConstants.TAG_WHATS_NEW_ELEMENT );
271
272 return strXml.toString( );
273 }
274 }