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