001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    
019    import java.util.Properties;
020    
021    import javax.portlet.PortletPreferences;
022    
023    /**
024     * @author Mika Koivisto
025     */
026    public class SilentPrefsPropsUtil {
027    
028            public static boolean getBoolean(long companyId, String name) {
029                    try {
030                            return PrefsPropsUtil.getBoolean(companyId, name);
031                    }
032                    catch (SystemException se) {
033                    }
034    
035                    return GetterUtil.getBoolean(PropsUtil.get(name));
036            }
037    
038            public static boolean getBoolean(
039                    long companyId, String name, boolean defaultValue) {
040    
041                    try {
042                            return PrefsPropsUtil.getBoolean(companyId, name, defaultValue);
043                    }
044                    catch (SystemException se) {
045                    }
046    
047                    return GetterUtil.getBoolean(PropsUtil.get(name), defaultValue);
048            }
049    
050            public static boolean getBoolean(
051                    PortletPreferences preferences, long companyId, String name) {
052    
053                    return PrefsPropsUtil.getBoolean(preferences, companyId, name);
054            }
055    
056            public static boolean getBoolean(
057                    PortletPreferences preferences, long companyId, String name,
058                    boolean defaultValue) {
059    
060                    return PrefsPropsUtil.getBoolean(
061                            preferences, companyId, name, defaultValue);
062            }
063    
064            public static boolean getBoolean(String name) {
065                    try {
066                            return PrefsPropsUtil.getBoolean(name);
067                    }
068                    catch (SystemException se) {
069                    }
070    
071                    return GetterUtil.getBoolean(PropsUtil.get(name));
072            }
073    
074            public static boolean getBoolean(String name, boolean defaultValue) {
075                    try {
076                            return PrefsPropsUtil.getBoolean(name, defaultValue);
077                    }
078                    catch (SystemException se) {
079                    }
080    
081                    return GetterUtil.getBoolean(PropsUtil.get(name), defaultValue);
082            }
083    
084            public static String getContent(long companyId, String name) {
085                    try {
086                            return PrefsPropsUtil.getContent(companyId, name);
087                    }
088                    catch (SystemException se) {
089                    }
090    
091                    return PropsUtil.get(name);
092            }
093    
094            public static String getContent(
095                    PortletPreferences preferences, long companyId, String name) {
096    
097                    return PrefsPropsUtil.getContent(preferences, companyId, name);
098            }
099    
100            public static String getContent(String name) {
101                    try {
102                            return PrefsPropsUtil.getContent(name);
103                    }
104                    catch (SystemException se) {
105                    }
106    
107                    return PropsUtil.get(name);
108            }
109    
110            public static double getDouble(long companyId, String name) {
111                    try {
112                            return PrefsPropsUtil.getDouble(companyId, name);
113                    }
114                    catch (SystemException se) {
115                    }
116    
117                    return GetterUtil.getDouble(PropsUtil.get(name));
118            }
119    
120            public static double getDouble(
121                    long companyId, String name, double defaultValue) {
122    
123                    try {
124                            return PrefsPropsUtil.getDouble(companyId, name, defaultValue);
125                    }
126                    catch (SystemException se) {
127                    }
128    
129                    return GetterUtil.getDouble(PropsUtil.get(name), defaultValue);
130            }
131    
132            public static double getDouble(
133                    PortletPreferences preferences, long companyId, String name) {
134    
135                    return PrefsPropsUtil.getDouble(preferences, companyId, name);
136            }
137    
138            public static double getDouble(
139                    PortletPreferences preferences, long companyId, String name,
140                    double defaultValue) {
141    
142                    return PrefsPropsUtil.getDouble(
143                            preferences, companyId, name, defaultValue);
144            }
145    
146            public static double getDouble(String name) {
147                    try {
148                            return PrefsPropsUtil.getDouble(name);
149                    }
150                    catch (SystemException se) {
151                    }
152    
153                    return GetterUtil.getDouble(PropsUtil.get(name));
154            }
155    
156            public static double getDouble(String name, double defaultValue) {
157                    try {
158                            return PrefsPropsUtil.getDouble(name, defaultValue);
159                    }
160                    catch (SystemException se) {
161                    }
162    
163                    return GetterUtil.getDouble(PropsUtil.get(name), defaultValue);
164            }
165    
166            public static int getInteger(long companyId, String name) {
167                    try {
168                            return PrefsPropsUtil.getInteger(companyId, name);
169                    }
170                    catch (SystemException se) {
171                    }
172    
173                    return GetterUtil.getInteger(PropsUtil.get(name));
174            }
175    
176            public static int getInteger(
177                    long companyId, String name, int defaultValue) {
178    
179                    try {
180                            return PrefsPropsUtil.getInteger(companyId, name, defaultValue);
181                    }
182                    catch (SystemException se) {
183                    }
184    
185                    return GetterUtil.getInteger(PropsUtil.get(name));
186            }
187    
188            public static int getInteger(
189                    PortletPreferences preferences, long companyId, String name) {
190    
191                    return PrefsPropsUtil.getInteger(preferences, companyId, name);
192            }
193    
194            public static int getInteger(
195                    PortletPreferences preferences, long companyId, String name,
196                    int defaultValue) {
197    
198                    return PrefsPropsUtil.getInteger(
199                            preferences, companyId, name, defaultValue);
200            }
201    
202            public static int getInteger(String name) {
203                    try {
204                            return PrefsPropsUtil.getInteger(name);
205                    }
206                    catch (SystemException se) {
207                    }
208    
209                    return GetterUtil.getInteger(PropsUtil.get(name));
210            }
211    
212            public static int getInteger(String name, int defaultValue) {
213                    try {
214                            return PrefsPropsUtil.getInteger(name, defaultValue);
215                    }
216                    catch (SystemException se) {
217                    }
218    
219                    return GetterUtil.getInteger(PropsUtil.get(name), defaultValue);
220            }
221    
222            public static long getLong(long companyId, String name) {
223                    try {
224                            return PrefsPropsUtil.getLong(companyId, name);
225                    }
226                    catch (SystemException se) {
227                    }
228    
229                    return GetterUtil.getLong(PropsUtil.get(name));
230            }
231    
232            public static long getLong(long companyId, String name, long defaultValue) {
233                    try {
234                            return PrefsPropsUtil.getLong(companyId, name, defaultValue);
235                    }
236                    catch (SystemException se) {
237                    }
238    
239                    return GetterUtil.getLong(PropsUtil.get(name), defaultValue);
240            }
241    
242            public static long getLong(
243                    PortletPreferences preferences, long companyId, String name) {
244    
245                    return PrefsPropsUtil.getLong(preferences, companyId, name);
246            }
247    
248            public static long getLong(
249                    PortletPreferences preferences, long companyId, String name,
250                    long defaultValue) {
251    
252                    return PrefsPropsUtil.getLong(
253                            preferences, companyId, name, defaultValue);
254            }
255    
256            public static long getLong(String name) {
257                    try {
258                            return PrefsPropsUtil.getLong(name);
259                    }
260                    catch (SystemException se) {
261                    }
262    
263                    return GetterUtil.getLong(PropsUtil.get(name));
264            }
265    
266            public static long getLong(String name, long defaultValue) {
267                    try {
268                            return PrefsPropsUtil.getLong(name, defaultValue);
269                    }
270                    catch (SystemException se) {
271                    }
272    
273                    return GetterUtil.getLong(PropsUtil.get(name), defaultValue);
274            }
275    
276            public static Properties getProperties(
277                    PortletPreferences preferences, long companyId, String prefix,
278                    boolean removePrefix) {
279    
280                    return PrefsPropsUtil.getProperties(
281                            preferences, companyId, prefix, removePrefix);
282            }
283    
284            public static Properties getProperties(
285                    String prefix, boolean removePrefix) {
286    
287                    try {
288                            return PrefsPropsUtil.getProperties(prefix, removePrefix);
289                    }
290                    catch (SystemException se) {
291                    }
292    
293                    return PropsUtil.getProperties(prefix, removePrefix);
294            }
295    
296            public static short getShort(long companyId, String name) {
297                    try {
298                            return PrefsPropsUtil.getShort(companyId, name);
299                    }
300                    catch (SystemException se) {
301                    }
302    
303                    return GetterUtil.getShort(PropsUtil.get(name));
304            }
305    
306            public static short getShort(
307                    long companyId, String name, short defaultValue) {
308    
309                    try {
310                            return PrefsPropsUtil.getShort(companyId, name, defaultValue);
311                    }
312                    catch (SystemException se) {
313                    }
314    
315                    return GetterUtil.getShort(PropsUtil.get(name), defaultValue);
316            }
317    
318            public static short getShort(
319                    PortletPreferences preferences, long companyId, String name) {
320    
321                    return PrefsPropsUtil.getShort(preferences, companyId, name);
322            }
323    
324            public static short getShort(
325                    PortletPreferences preferences, long companyId, String name,
326                    short defaultValue) {
327    
328                    return PrefsPropsUtil.getShort(
329                            preferences, companyId, name, defaultValue);
330            }
331    
332            public static short getShort(String name) {
333                    try {
334                            return PrefsPropsUtil.getShort(name);
335                    }
336                    catch (SystemException se) {
337                    }
338    
339                    return GetterUtil.getShort(PropsUtil.get(name));
340            }
341    
342            public static short getShort(String name, short defaultValue) {
343                    try {
344                            return PrefsPropsUtil.getShort(name, defaultValue);
345                    }
346                    catch (SystemException se) {
347                    }
348    
349                    return GetterUtil.getShort(PropsUtil.get(name), defaultValue);
350            }
351    
352            public static String getString(long companyId, String name) {
353                    try {
354                            return PrefsPropsUtil.getString(companyId, name);
355                    }
356                    catch (SystemException se) {
357                    }
358    
359                    return PropsUtil.get(name);
360            }
361    
362            public static String getString(
363                    long companyId, String name, String defaultValue) {
364    
365                    try {
366                            return PrefsPropsUtil.getString(companyId, name, defaultValue);
367                    }
368                    catch (SystemException se) {
369                    }
370    
371                    return GetterUtil.get(PropsUtil.get(name), defaultValue);
372            }
373    
374            public static String getString(
375                    PortletPreferences preferences, long companyId, String name) {
376    
377                    return PrefsPropsUtil.getString(preferences, companyId, name);
378            }
379    
380            public static String getString(
381                    PortletPreferences preferences, long companyId, String name,
382                    boolean defaultValue) {
383    
384                    return PrefsPropsUtil.getString(
385                            preferences, companyId, name, defaultValue);
386            }
387    
388            public static String getString(
389                    PortletPreferences preferences, long companyId, String name,
390                    double defaultValue) {
391    
392                    return PrefsPropsUtil.getString(
393                            preferences, companyId, name, defaultValue);
394            }
395    
396            public static String getString(
397                    PortletPreferences preferences, long companyId, String name,
398                    int defaultValue) {
399    
400                    return PrefsPropsUtil.getString(
401                            preferences, companyId, name, defaultValue);
402            }
403    
404            public static String getString(
405                    PortletPreferences preferences, long companyId, String name,
406                    long defaultValue) {
407    
408                    return PrefsPropsUtil.getString(
409                            preferences, companyId, name, defaultValue);
410            }
411    
412            public static String getString(
413                    PortletPreferences preferences, long companyId, String name,
414                    short defaultValue) {
415    
416                    return PrefsPropsUtil.getString(
417                            preferences, companyId, name, defaultValue);
418            }
419    
420            public static String getString(
421                    PortletPreferences preferences, long companyId, String name,
422                    String defaultValue) {
423    
424                    return PrefsPropsUtil.getString(
425                            preferences, companyId, name, defaultValue);
426            }
427    
428            public static String getString(String name) {
429                    try {
430                            return PrefsPropsUtil.getString(name);
431                    }
432                    catch (SystemException se) {
433                    }
434    
435                    return PropsUtil.get(name);
436            }
437    
438            public static String getString(String name, String defaultValue) {
439                    try {
440                            return PrefsPropsUtil.getString(name, defaultValue);
441                    }
442                    catch (SystemException se) {
443                    }
444    
445                    return GetterUtil.get(PropsUtil.get(name), defaultValue);
446            }
447    
448            public static String[] getStringArray(
449                    long companyId, String name, String delimiter) {
450    
451                    try {
452                            return PrefsPropsUtil.getStringArray(companyId, name, delimiter);
453                    }
454                    catch (SystemException se) {
455                    }
456    
457                    return StringUtil.split(PropsUtil.get(name), delimiter);
458            }
459    
460            public static String[] getStringArray(
461                    long companyId, String name, String delimiter, String[] defaultValue) {
462    
463                    try {
464                            return PrefsPropsUtil.getStringArray(
465                                    companyId, name, delimiter, defaultValue);
466                    }
467                    catch (SystemException se) {
468                    }
469    
470                    String value = PropsUtil.get(name);
471    
472                    if (Validator.isNull(value)) {
473                            return defaultValue;
474                    }
475    
476                    return StringUtil.split(value, delimiter);
477            }
478    
479            public static String[] getStringArray(
480                    PortletPreferences preferences, long companyId, String name,
481                    String delimiter) {
482    
483                    return PrefsPropsUtil.getStringArray(
484                            preferences, companyId, name, delimiter);
485            }
486    
487            public static String[] getStringArray(
488                    PortletPreferences preferences, long companyId, String name,
489                    String delimiter, String[] defaultValue) {
490    
491                    return PrefsPropsUtil.getStringArray(
492                            preferences, companyId, name, delimiter, defaultValue);
493            }
494    
495            public static String[] getStringArray(String name, String delimiter) {
496                    try {
497                            return PrefsPropsUtil.getStringArray(name, delimiter);
498                    }
499                    catch (SystemException se) {
500                    }
501    
502                    return StringUtil.split(PropsUtil.get(name), delimiter);
503            }
504    
505            public static String[] getStringArray(
506                    String name, String delimiter, String[] defaultValue) {
507    
508                    try {
509                            return PrefsPropsUtil.getStringArray(name, delimiter, defaultValue);
510                    }
511                    catch (SystemException se) {
512                    }
513    
514                    String value = PropsUtil.get(name);
515    
516                    if (Validator.isNull(value)) {
517                            return defaultValue;
518                    }
519    
520                    return StringUtil.split(value, delimiter);
521            }
522    
523            public static String getStringFromNames(long companyId, String... names) {
524                    try {
525                            PrefsPropsUtil.getStringFromNames(companyId, names);
526                    }
527                    catch (SystemException se) {
528                    }
529    
530                    return null;
531            }
532    
533    }