KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > util > ParameterHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jun 20, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.util;
19
20 import java.math.BigDecimal JavaDoc;
21 import java.text.DateFormat JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import org.pentaho.messages.Messages;
25 import org.pentaho.util.logging.Logger;
26
27 /**
28  * @author James Dixon
29  *
30  * TODO To change the template for this generated type comment go to Window -
31  * Preferences - Java - Code Style - Code Templates
32  */

33 public class ParameterHelper {
34
35     public static String JavaDoc parameterToString(String JavaDoc value, String JavaDoc defaultValue) {
36         if (value == null) {
37             return defaultValue;
38         }
39         return value;
40     }
41
42     public static long parameterToLong(String JavaDoc value, long defaultValue) {
43         if (value == null) {
44             return defaultValue;
45         }
46         try {
47             long longValue = Long.valueOf(value).longValue();
48             return longValue;
49         } catch (Exception JavaDoc e) {
50             Logger.error(ParameterHelper.class.getName(), Messages.getErrorString("ParameterHelper.ERROR_0001_INVALID_NUMERIC"), e); //$NON-NLS-1$
51
}
52         return defaultValue;
53     }
54
55     public static Date JavaDoc parameterToDate(String JavaDoc value, Date JavaDoc defaultValue) {
56         try {
57             Date JavaDoc date = DateFormat.getInstance().parse(value);
58             if (date == null) {
59                 return defaultValue;
60             }
61             return date;
62         } catch (Exception JavaDoc e) {
63             return defaultValue;
64         }
65     }
66
67     public static BigDecimal JavaDoc parameterToDecimal(String JavaDoc value, BigDecimal JavaDoc defaultValue) {
68         if (value == null) {
69             return defaultValue;
70         }
71         try {
72             BigDecimal JavaDoc decimal = new BigDecimal JavaDoc(value);
73             return decimal;
74         } catch (Exception JavaDoc e) {
75             Logger.error(ParameterHelper.class.getName(), Messages.getErrorString("ParameterHelper.ERROR_0001_INVALID_NUMERIC"), e); //$NON-NLS-1$
76
}
77         return defaultValue;
78     }
79
80 }
81
Popular Tags