1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.util;
24  
25  import java.util.Properties;
26  
27  import javax.servlet.http.HttpServletRequest;
28  
29  /**
30   * <a href="PropertiesParamUtil.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class PropertiesParamUtil {
36  
37      public static boolean getBoolean(
38          Properties props, HttpServletRequest request, String param) {
39  
40          return getBoolean(props, request, param, GetterUtil.DEFAULT_BOOLEAN);
41      }
42  
43      public static boolean getBoolean(
44          Properties props, HttpServletRequest request, String param,
45          boolean defaultValue) {
46  
47          String propsValue = props.getProperty(param, null);
48  
49          boolean getterUtilValue = GetterUtil.getBoolean(
50              propsValue, defaultValue);
51  
52          return ParamUtil.get(request, param, getterUtilValue);
53      }
54  
55      public static boolean getBoolean(
56          UnicodeProperties props, HttpServletRequest request, String param) {
57  
58          return getBoolean(props, request, param, GetterUtil.DEFAULT_BOOLEAN);
59      }
60  
61      public static boolean getBoolean(
62          UnicodeProperties props, HttpServletRequest request, String param,
63          boolean defaultValue) {
64  
65          String propsValue = props.getProperty(param, null);
66  
67          boolean getterUtilValue = GetterUtil.getBoolean(
68              propsValue, defaultValue);
69  
70          return ParamUtil.get(request, param, getterUtilValue);
71      }
72  
73      public static double getDouble(
74          Properties props, HttpServletRequest request, String param) {
75  
76          return getDouble(props, request, param, GetterUtil.DEFAULT_DOUBLE);
77      }
78  
79      public static double getDouble(
80          Properties props, HttpServletRequest request, String param,
81          double defaultValue) {
82  
83          String propsValue = props.getProperty(param, null);
84  
85          double getterUtilValue = GetterUtil.getDouble(
86              propsValue, defaultValue);
87  
88          return ParamUtil.get(request, param, getterUtilValue);
89      }
90  
91      public static double getDouble(
92          UnicodeProperties props, HttpServletRequest request, String param) {
93  
94          return getDouble(props, request, param, GetterUtil.DEFAULT_DOUBLE);
95      }
96  
97      public static double getDouble(
98          UnicodeProperties props, HttpServletRequest request, String param,
99          double defaultValue) {
100 
101         String propsValue = props.getProperty(param, null);
102 
103         double getterUtilValue = GetterUtil.getDouble(
104             propsValue, defaultValue);
105 
106         return ParamUtil.get(request, param, getterUtilValue);
107     }
108 
109     public static int getInteger(
110         Properties props, HttpServletRequest request, String param) {
111 
112         return getInteger(props, request, param, GetterUtil.DEFAULT_INTEGER);
113     }
114 
115     public static int getInteger(
116         Properties props, HttpServletRequest request, String param,
117         int defaultValue) {
118 
119         String propsValue = props.getProperty(param, null);
120 
121         int getterUtilValue = GetterUtil.getInteger(
122             propsValue, defaultValue);
123 
124         return ParamUtil.get(request, param, getterUtilValue);
125     }
126 
127     public static int getInteger(
128         UnicodeProperties props, HttpServletRequest request, String param) {
129 
130         return getInteger(props, request, param, GetterUtil.DEFAULT_INTEGER);
131     }
132 
133     public static int getInteger(
134         UnicodeProperties props, HttpServletRequest request, String param,
135         int defaultValue) {
136 
137         String propsValue = props.getProperty(param, null);
138 
139         int getterUtilValue = GetterUtil.getInteger(
140             propsValue, defaultValue);
141 
142         return ParamUtil.get(request, param, getterUtilValue);
143     }
144 
145     public static long getLong(
146         Properties props, HttpServletRequest request, String param) {
147 
148         return getLong(props, request, param, GetterUtil.DEFAULT_LONG);
149     }
150 
151     public static long getLong(
152         Properties props, HttpServletRequest request, String param,
153         long defaultValue) {
154 
155         String propsValue = props.getProperty(param, null);
156 
157         long getterUtilValue = GetterUtil.getLong(
158             propsValue, defaultValue);
159 
160         return ParamUtil.get(request, param, getterUtilValue);
161     }
162 
163     public static long getLong(
164         UnicodeProperties props, HttpServletRequest request, String param) {
165 
166         return getLong(props, request, param, GetterUtil.DEFAULT_LONG);
167     }
168 
169     public static long getLong(
170         UnicodeProperties props, HttpServletRequest request, String param,
171         long defaultValue) {
172 
173         String propsValue = props.getProperty(param, null);
174 
175         long getterUtilValue = GetterUtil.getLong(
176             propsValue, defaultValue);
177 
178         return ParamUtil.get(request, param, getterUtilValue);
179     }
180 
181     public static String getString(
182         Properties props, HttpServletRequest request, String param) {
183 
184         return getString(props, request, param, GetterUtil.DEFAULT_STRING);
185     }
186 
187     public static String getString(
188         Properties props, HttpServletRequest request, String param,
189         String defaultValue) {
190 
191         String propsValue = props.getProperty(param, null);
192 
193         String getterUtilValue = GetterUtil.getString(
194             propsValue, defaultValue);
195 
196         return ParamUtil.get(request, param, getterUtilValue);
197     }
198 
199     public static String getString(
200         UnicodeProperties props, HttpServletRequest request, String param) {
201 
202         return getString(props, request, param, GetterUtil.DEFAULT_STRING);
203     }
204 
205     public static String getString(
206         UnicodeProperties props, HttpServletRequest request, String param,
207         String defaultValue) {
208 
209         String propsValue = props.getProperty(param, null);
210 
211         String getterUtilValue = GetterUtil.getString(
212             propsValue, defaultValue);
213 
214         return ParamUtil.get(request, param, getterUtilValue);
215     }
216 
217 }