1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class PropertiesParamUtil {
35  
36      public static boolean getBoolean(
37          Properties props, HttpServletRequest request, String param) {
38  
39          return getBoolean(props, request, param, GetterUtil.DEFAULT_BOOLEAN);
40      }
41  
42      public static boolean getBoolean(
43          Properties props, HttpServletRequest request, String param,
44          boolean defaultValue) {
45  
46          String propsValue = props.getProperty(param, null);
47  
48          boolean getterUtilValue = GetterUtil.getBoolean(
49              propsValue, defaultValue);
50  
51          return ParamUtil.get(request, param, getterUtilValue);
52      }
53  
54      public static boolean getBoolean(
55          UnicodeProperties props, HttpServletRequest request, String param) {
56  
57          return getBoolean(props, request, param, GetterUtil.DEFAULT_BOOLEAN);
58      }
59  
60      public static boolean getBoolean(
61          UnicodeProperties props, HttpServletRequest request, String param,
62          boolean defaultValue) {
63  
64          String propsValue = props.getProperty(param, null);
65  
66          boolean getterUtilValue = GetterUtil.getBoolean(
67              propsValue, defaultValue);
68  
69          return ParamUtil.get(request, param, getterUtilValue);
70      }
71  
72      public static double getDouble(
73          Properties props, HttpServletRequest request, String param) {
74  
75          return getDouble(props, request, param, GetterUtil.DEFAULT_DOUBLE);
76      }
77  
78      public static double getDouble(
79          Properties props, HttpServletRequest request, String param,
80          double defaultValue) {
81  
82          String propsValue = props.getProperty(param, null);
83  
84          double getterUtilValue = GetterUtil.getDouble(
85              propsValue, defaultValue);
86  
87          return ParamUtil.get(request, param, getterUtilValue);
88      }
89  
90      public static double getDouble(
91          UnicodeProperties props, HttpServletRequest request, String param) {
92  
93          return getDouble(props, request, param, GetterUtil.DEFAULT_DOUBLE);
94      }
95  
96      public static double getDouble(
97          UnicodeProperties props, HttpServletRequest request, String param,
98          double defaultValue) {
99  
100         String propsValue = props.getProperty(param, null);
101 
102         double getterUtilValue = GetterUtil.getDouble(
103             propsValue, defaultValue);
104 
105         return ParamUtil.get(request, param, getterUtilValue);
106     }
107 
108     public static int getInteger(
109         Properties props, HttpServletRequest request, String param) {
110 
111         return getInteger(props, request, param, GetterUtil.DEFAULT_INTEGER);
112     }
113 
114     public static int getInteger(
115         Properties props, HttpServletRequest request, String param,
116         int defaultValue) {
117 
118         String propsValue = props.getProperty(param, null);
119 
120         int getterUtilValue = GetterUtil.getInteger(
121             propsValue, defaultValue);
122 
123         return ParamUtil.get(request, param, getterUtilValue);
124     }
125 
126     public static int getInteger(
127         UnicodeProperties props, HttpServletRequest request, String param) {
128 
129         return getInteger(props, request, param, GetterUtil.DEFAULT_INTEGER);
130     }
131 
132     public static int getInteger(
133         UnicodeProperties props, HttpServletRequest request, String param,
134         int defaultValue) {
135 
136         String propsValue = props.getProperty(param, null);
137 
138         int getterUtilValue = GetterUtil.getInteger(
139             propsValue, defaultValue);
140 
141         return ParamUtil.get(request, param, getterUtilValue);
142     }
143 
144     public static long getLong(
145         Properties props, HttpServletRequest request, String param) {
146 
147         return getLong(props, request, param, GetterUtil.DEFAULT_LONG);
148     }
149 
150     public static long getLong(
151         Properties props, HttpServletRequest request, String param,
152         long defaultValue) {
153 
154         String propsValue = props.getProperty(param, null);
155 
156         long getterUtilValue = GetterUtil.getLong(
157             propsValue, defaultValue);
158 
159         return ParamUtil.get(request, param, getterUtilValue);
160     }
161 
162     public static long getLong(
163         UnicodeProperties props, HttpServletRequest request, String param) {
164 
165         return getLong(props, request, param, GetterUtil.DEFAULT_LONG);
166     }
167 
168     public static long getLong(
169         UnicodeProperties props, HttpServletRequest request, String param,
170         long defaultValue) {
171 
172         String propsValue = props.getProperty(param, null);
173 
174         long getterUtilValue = GetterUtil.getLong(
175             propsValue, defaultValue);
176 
177         return ParamUtil.get(request, param, getterUtilValue);
178     }
179 
180     public static String getString(
181         Properties props, HttpServletRequest request, String param) {
182 
183         return getString(props, request, param, GetterUtil.DEFAULT_STRING);
184     }
185 
186     public static String getString(
187         Properties props, HttpServletRequest request, String param,
188         String defaultValue) {
189 
190         String propsValue = props.getProperty(param, null);
191 
192         String getterUtilValue = GetterUtil.getString(
193             propsValue, defaultValue);
194 
195         return ParamUtil.get(request, param, getterUtilValue);
196     }
197 
198     public static String getString(
199         UnicodeProperties props, HttpServletRequest request, String param) {
200 
201         return getString(props, request, param, GetterUtil.DEFAULT_STRING);
202     }
203 
204     public static String getString(
205         UnicodeProperties props, HttpServletRequest request, String param,
206         String defaultValue) {
207 
208         String propsValue = props.getProperty(param, null);
209 
210         String getterUtilValue = GetterUtil.getString(
211             propsValue, defaultValue);
212 
213         return ParamUtil.get(request, param, getterUtilValue);
214     }
215 
216 }