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