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.portal.service.message;
35
36 import fr.paris.lutece.portal.service.i18n.I18nService;
37
38 import java.io.Serializable;
39
40 import java.text.MessageFormat;
41
42 import java.util.HashMap;
43 import java.util.Locale;
44 import java.util.Map;
45 import java.util.Map.Entry;
46
47
48
49
50
51 public class SiteMessage implements Serializable
52 {
53 public static final int TYPE_INFO = 0;
54 public static final int TYPE_QUESTION = 1;
55 public static final int TYPE_ERROR = 2;
56 public static final int TYPE_WARNING = 3;
57 public static final int TYPE_CONFIRMATION = 4;
58 public static final int TYPE_STOP = 5;
59 public static final int TYPE_BUTTON_HIDDEN = 0;
60 public static final int TYPE_BUTTON_BACK = 1;
61 public static final int TYPE_BUTTON_CANCEL = 2;
62 private static final long serialVersionUID = -34775038853250525L;
63 private String _strTextKey;
64 private String _strTitleKey;
65 private String _strUrl;
66 private String _strTarget;
67 private int _nTypeButton;
68 private int _nType;
69 private String[] _messageArgs;
70 private Map<String, String> _requestParameters;
71 private String _strBackUrl;
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public SiteMessage( String strTextKey, Object[] messageArgs, String strTitleKey, String strUrl, String strTarget,
86 int nType, int nTypeButton, Map<String, Object> requestParameters, String strBackUrl )
87 {
88 _strTextKey = strTextKey;
89 _strTitleKey = strTitleKey;
90 _strUrl = strUrl;
91 _strTarget = strTarget;
92 _nType = nType;
93 _nTypeButton = nTypeButton;
94 _strBackUrl = strBackUrl;
95
96
97 if ( messageArgs != null )
98 {
99 _messageArgs = new String[messageArgs.length];
100
101 for ( int i = 0; i < messageArgs.length; i++ )
102 {
103 _messageArgs[i] = ( messageArgs[i] == null ) ? null : messageArgs[i].toString( );
104 }
105 }
106
107
108 if ( requestParameters != null )
109 {
110 _requestParameters = new HashMap<String, String>( );
111
112 for ( Entry<String, Object> entry : requestParameters.entrySet( ) )
113 {
114 _requestParameters.put( entry.getKey( ),
115 ( entry.getValue( ) == null ) ? null : entry.getValue( ).toString( ) );
116 }
117 }
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 public SiteMessage( String strTextKey, Object[] messageArgs, String strTitleKey, String strUrl, String strTarget,
132 int nType, boolean bCancelButton )
133 {
134 this( strTextKey, messageArgs, strTitleKey, strUrl, strTarget, nType, ( bCancelButton ) ? 1 : 0, null, null );
135 }
136
137
138
139
140
141
142 public int getType( )
143 {
144 return _nType;
145 }
146
147
148
149
150
151
152 public boolean isCancel( )
153 {
154 return ( getTypeButton( ) == TYPE_BUTTON_HIDDEN ) ? false : true;
155 }
156
157
158
159
160
161
162
163 public void setCancel( boolean bCancel )
164 {
165 if ( !bCancel )
166 {
167 setTypeButton( TYPE_BUTTON_HIDDEN );
168 }
169 else
170 {
171 setTypeButton( TYPE_BUTTON_BACK );
172 }
173 }
174
175
176
177
178
179
180 public String getText( Locale locale )
181 {
182 String strText = I18nService.getLocalizedString( _strTextKey, locale );
183
184 if ( _messageArgs != null )
185 {
186 strText = MessageFormat.format( strText, (Object[]) _messageArgs );
187 }
188
189 return strText;
190 }
191
192
193
194
195
196
197 public String getTitle( Locale locale )
198 {
199 return I18nService.getLocalizedString( _strTitleKey, locale );
200 }
201
202
203
204
205
206 public String getUrl( )
207 {
208 return _strUrl;
209 }
210
211
212
213
214
215 public String getTarget( )
216 {
217 return _strTarget;
218 }
219
220
221
222
223
224 public int getTypeButton( )
225 {
226 return _nTypeButton;
227 }
228
229
230
231
232
233 public void setTypeButton( int nTypeButton )
234 {
235 _nTypeButton = nTypeButton;
236 }
237
238
239
240
241
242 public Map<String, String> getRequestParameters( )
243 {
244 return _requestParameters;
245 }
246
247
248
249
250
251 public void setBackUrl( String strBackUrl )
252 {
253 this._strBackUrl = strBackUrl;
254 }
255
256
257
258
259
260 public String getBackUrl( )
261 {
262 return _strBackUrl;
263 }
264 }