001    /**
002     * Copyright (c) 2000-2013 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    
076                    try {
077                            return PrefsPropsUtil.getBoolean(name, defaultValue);
078                    }
079                    catch (SystemException se) {
080                    }
081    
082                    return GetterUtil.getBoolean(PropsUtil.get(name), defaultValue);
083            }
084    
085            public static String getContent(long companyId, String name) {
086    
087                    try {
088                            return PrefsPropsUtil.getContent(companyId, name);
089                    }
090                    catch (SystemException se) {
091                    }
092    
093                    return PropsUtil.get(name);
094            }
095    
096            public static String getContent(
097                    PortletPreferences preferences, long companyId, String name) {
098    
099                    return PrefsPropsUtil.getContent(preferences, companyId, name);
100            }
101    
102            public static String getContent(String name) {
103                    try {
104                            return PrefsPropsUtil.getContent(name);
105                    }
106                    catch (SystemException se) {
107                    }
108    
109                    return PropsUtil.get(name);
110            }
111    
112            public static double getDouble(long companyId, String name) {
113    
114                    try {
115                            return PrefsPropsUtil.getDouble(companyId, name);
116                    }
117                    catch (SystemException se) {
118                    }
119    
120                    return GetterUtil.getDouble(PropsUtil.get(name));
121            }
122    
123            public static double getDouble(
124                    long companyId, String name, double defaultValue) {
125    
126                    try {
127                            return PrefsPropsUtil.getDouble(companyId, name, defaultValue);
128                    }
129                    catch (SystemException se) {
130                    }
131    
132                    return GetterUtil.getDouble(PropsUtil.get(name), defaultValue);
133            }
134    
135            public static double getDouble(
136                    PortletPreferences preferences, long companyId, String name) {
137    
138                    return PrefsPropsUtil.getDouble(preferences, companyId, name);
139            }
140    
141            public static double getDouble(
142                    PortletPreferences preferences, long companyId, String name,
143                    double defaultValue) {
144    
145                    return PrefsPropsUtil.getDouble(
146                            preferences, companyId, name, defaultValue);
147            }
148    
149            public static double getDouble(String name) {
150                    try {
151                            return PrefsPropsUtil.getDouble(name);
152                    }
153                    catch (SystemException se) {
154                    }
155    
156                    return GetterUtil.getDouble(PropsUtil.get(name));
157            }
158    
159            public static double getDouble(String name, double defaultValue) {
160    
161                    try {
162                            return PrefsPropsUtil.getDouble(name, defaultValue);
163                    }
164                    catch (SystemException se) {
165                    }
166    
167                    return GetterUtil.getDouble(PropsUtil.get(name), defaultValue);
168            }
169    
170            public static int getInteger(long companyId, String name) {
171    
172                    try {
173                            return PrefsPropsUtil.getInteger(companyId, name);
174                    }
175                    catch (SystemException se) {
176                    }
177    
178                    return GetterUtil.getInteger(PropsUtil.get(name));
179            }
180    
181            public static int getInteger(
182                    long companyId, String name, int defaultValue) {
183    
184                    try {
185                            return PrefsPropsUtil.getInteger(companyId, name, defaultValue);
186                    }
187                    catch (SystemException se) {
188                    }
189    
190                    return GetterUtil.getInteger(PropsUtil.get(name));
191            }
192    
193            public static int getInteger(
194                    PortletPreferences preferences, long companyId, String name) {
195    
196                    return PrefsPropsUtil.getInteger(preferences, companyId, name);
197            }
198    
199            public static int getInteger(
200                    PortletPreferences preferences, long companyId, String name,
201                    int defaultValue) {
202    
203                    return PrefsPropsUtil.getInteger(
204                            preferences, companyId, name, defaultValue);
205            }
206    
207            public static int getInteger(String name) {
208                    try {
209                            return PrefsPropsUtil.getInteger(name);
210                    }
211                    catch (SystemException se) {
212                    }
213    
214                    return GetterUtil.getInteger(PropsUtil.get(name));
215            }
216    
217            public static int getInteger(String name, int defaultValue) {
218                    try {
219                            return PrefsPropsUtil.getInteger(name, defaultValue);
220                    }
221                    catch (SystemException se) {
222                    }
223    
224                    return GetterUtil.getInteger(PropsUtil.get(name), defaultValue);
225            }
226    
227            public static long getLong(long companyId, String name) {
228    
229                    try {
230                            return PrefsPropsUtil.getLong(companyId, name);
231                    }
232                    catch (SystemException se) {
233                    }
234    
235                    return GetterUtil.getLong(PropsUtil.get(name));
236            }
237    
238            public static long getLong(long companyId, String name, long defaultValue) {
239                    try {
240                            return PrefsPropsUtil.getLong(companyId, name, defaultValue);
241                    }
242                    catch (SystemException se) {
243                    }
244    
245                    return GetterUtil.getLong(PropsUtil.get(name), defaultValue);
246            }
247    
248            public static long getLong(
249                    PortletPreferences preferences, long companyId, String name) {
250    
251                    return PrefsPropsUtil.getLong(preferences, companyId, name);
252            }
253    
254            public static long getLong(
255                    PortletPreferences preferences, long companyId, String name,
256                    long defaultValue) {
257    
258                    return PrefsPropsUtil.getLong(
259                            preferences, companyId, name, defaultValue);
260            }
261    
262            public static long getLong(String name) {
263                    try {
264                            return PrefsPropsUtil.getLong(name);
265                    }
266                    catch (SystemException se) {
267                    }
268    
269                    return GetterUtil.getLong(PropsUtil.get(name));
270            }
271    
272            public static long getLong(String name, long defaultValue) {
273                    try {
274                            return PrefsPropsUtil.getLong(name, defaultValue);
275                    }
276                    catch (SystemException se) {
277                    }
278    
279                    return GetterUtil.getLong(PropsUtil.get(name), defaultValue);
280            }
281    
282            public static Properties getProperties(
283                    PortletPreferences preferences, long companyId, String prefix,
284                    boolean removePrefix) {
285    
286                    return PrefsPropsUtil.getProperties(
287                            preferences, companyId, prefix, removePrefix);
288            }
289    
290            public static Properties getProperties(
291                    String prefix, boolean removePrefix) {
292    
293                    try {
294                            return PrefsPropsUtil.getProperties(prefix, removePrefix);
295                    }
296                    catch (SystemException se) {
297                    }
298    
299                    return PropsUtil.getProperties(prefix, removePrefix);
300            }
301    
302            public static short getShort(long companyId, String name) {
303                    try {
304                            return PrefsPropsUtil.getShort(companyId, name);
305                    }
306                    catch (SystemException se) {
307                    }
308    
309                    return GetterUtil.getShort(PropsUtil.get(name));
310            }
311    
312            public static short getShort(
313                    long companyId, String name, short defaultValue) {
314    
315                    try {
316                            return PrefsPropsUtil.getShort(companyId, name, defaultValue);
317                    }
318                    catch (SystemException se) {
319                    }
320    
321                    return GetterUtil.getShort(PropsUtil.get(name), defaultValue);
322            }
323    
324            public static short getShort(
325                    PortletPreferences preferences, long companyId, String name) {
326    
327                    return PrefsPropsUtil.getShort(preferences, companyId, name);
328            }
329    
330            public static short getShort(
331                    PortletPreferences preferences, long companyId, String name,
332                    short defaultValue) {
333    
334                    return PrefsPropsUtil.getShort(
335                            preferences, companyId, name, defaultValue);
336            }
337    
338            public static short getShort(String name) {
339                    try {
340                            return PrefsPropsUtil.getShort(name);
341                    }
342                    catch (SystemException se) {
343                    }
344    
345                    return GetterUtil.getShort(PropsUtil.get(name));
346            }
347    
348            public static short getShort(String name, short defaultValue) {
349    
350                    try {
351                            return PrefsPropsUtil.getShort(name, defaultValue);
352                    }
353                    catch (SystemException se) {
354                    }
355    
356                    return GetterUtil.getShort(PropsUtil.get(name), defaultValue);
357            }
358    
359            public static String getString(long companyId, String name) {
360                    try {
361                            return PrefsPropsUtil.getString(companyId, name);
362                    }
363                    catch (SystemException se) {
364                    }
365    
366                    return PropsUtil.get(name);
367            }
368    
369            public static String getString(
370                    long companyId, String name, String defaultValue) {
371    
372                    try {
373                            return PrefsPropsUtil.getString(companyId, name, defaultValue);
374                    }
375                    catch (SystemException se) {
376                    }
377    
378                    return GetterUtil.get(PropsUtil.get(name), defaultValue);
379            }
380    
381            public static String getString(
382                    PortletPreferences preferences, long companyId, String name) {
383    
384                    return PrefsPropsUtil.getString(preferences, companyId, name);
385            }
386    
387            public static String getString(
388                    PortletPreferences preferences, long companyId, String name,
389                    boolean defaultValue) {
390    
391                    return PrefsPropsUtil.getString(
392                            preferences, companyId, name, defaultValue);
393            }
394    
395            public static String getString(
396                    PortletPreferences preferences, long companyId, String name,
397                    double defaultValue) {
398    
399                    return PrefsPropsUtil.getString(
400                            preferences, companyId, name, defaultValue);
401            }
402    
403            public static String getString(
404                    PortletPreferences preferences, long companyId, String name,
405                    int defaultValue) {
406    
407                    return PrefsPropsUtil.getString(
408                            preferences, companyId, name, defaultValue);
409            }
410    
411            public static String getString(
412                    PortletPreferences preferences, long companyId, String name,
413                    long defaultValue) {
414    
415                    return PrefsPropsUtil.getString(
416                            preferences, companyId, name, defaultValue);
417            }
418    
419            public static String getString(
420                    PortletPreferences preferences, long companyId, String name,
421                    short defaultValue) {
422    
423                    return PrefsPropsUtil.getString(
424                            preferences, companyId, name, defaultValue);
425            }
426    
427            public static String getString(
428                    PortletPreferences preferences, long companyId, String name,
429                    String defaultValue) {
430    
431                    return PrefsPropsUtil.getString(
432                            preferences, companyId, name, defaultValue);
433            }
434    
435            public static String getString(String name) {
436                    try {
437                            return PrefsPropsUtil.getString(name);
438                    }
439                    catch (SystemException se) {
440                    }
441    
442                    return PropsUtil.get(name);
443            }
444    
445            public static String getString(String name, String defaultValue) {
446                    try {
447                            return PrefsPropsUtil.getString(name, defaultValue);
448                    }
449                    catch (SystemException se) {
450                    }
451    
452                    return GetterUtil.get(PropsUtil.get(name), defaultValue);
453            }
454    
455            public static String[] getStringArray(
456                    long companyId, String name, String delimiter) {
457    
458                    try {
459                            return PrefsPropsUtil.getStringArray(companyId, name, delimiter);
460                    }
461                    catch (SystemException se) {
462                    }
463    
464                    return StringUtil.split(PropsUtil.get(name), delimiter);
465            }
466    
467            public static String[] getStringArray(
468                    long companyId, String name, String delimiter, String[] defaultValue) {
469    
470                    try {
471                            return PrefsPropsUtil.getStringArray(
472                                    companyId, name, delimiter, defaultValue);
473                    }
474                    catch (SystemException se) {
475                    }
476    
477                    String value = PropsUtil.get(name);
478    
479                    if (Validator.isNull(value)) {
480                            return defaultValue;
481                    }
482    
483                    return StringUtil.split(value, delimiter);
484            }
485    
486            public static String[] getStringArray(
487                    PortletPreferences preferences, long companyId, String name,
488                    String delimiter) {
489    
490                    return PrefsPropsUtil.getStringArray(
491                            preferences, companyId, name, delimiter);
492            }
493    
494            public static String[] getStringArray(
495                    PortletPreferences preferences, long companyId, String name,
496                    String delimiter, String[] defaultValue) {
497    
498                    return PrefsPropsUtil.getStringArray(
499                            preferences, companyId, name, delimiter, defaultValue);
500            }
501    
502            public static String[] getStringArray(String name, String delimiter) {
503                    try {
504                            return PrefsPropsUtil.getStringArray(name, delimiter);
505                    }
506                    catch (SystemException se) {
507                    }
508    
509                    return StringUtil.split(PropsUtil.get(name), delimiter);
510            }
511    
512            public static String[] getStringArray(
513                    String name, String delimiter, String[] defaultValue) {
514    
515                    try {
516                            return PrefsPropsUtil.getStringArray(name, delimiter, defaultValue);
517                    }
518                    catch (SystemException se) {
519                    }
520    
521                    String value = PropsUtil.get(name);
522    
523                    if (Validator.isNull(value)) {
524                            return defaultValue;
525                    }
526    
527                    return StringUtil.split(value, delimiter);
528            }
529    
530            public static String getStringFromNames(long companyId, String... names) {
531                    try {
532                            PrefsPropsUtil.getStringFromNames(companyId, names);
533                    }
534                    catch (SystemException se) {
535                    }
536    
537                    return null;
538            }
539    
540    }