1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.util;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.StringUtil;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * <a href="PKParser.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class PKParser {
30  
31      public PKParser(String pk) {
32          if (pk.startsWith(StringPool.OPEN_CURLY_BRACE)) {
33              pk = pk.substring(1, pk.length());
34          }
35  
36          if (pk.endsWith(StringPool.CLOSE_CURLY_BRACE)) {
37              pk = pk.substring(0, pk.length() - 1);
38          }
39  
40          String[] array = StringUtil.split(pk);
41  
42          for (int i = 0; i < array.length; i++) {
43              String[] kvp = StringUtil.split(array[i], StringPool.EQUAL);
44  
45              String key = kvp[0].trim();
46              String value = kvp[1].trim();
47  
48              _fields.put(key, value);
49          }
50      }
51  
52      public boolean getBoolean(String key) {
53          return GetterUtil.getBoolean(getString(key));
54      }
55  
56      public double getDouble(String key) {
57          return GetterUtil.getDouble(getString(key));
58      }
59  
60      public int getInteger(String key) {
61          return GetterUtil.getInteger(getString(key));
62      }
63  
64      public long getLong(String key) {
65          return GetterUtil.getLong(getString(key));
66      }
67  
68      public short getShort(String key) {
69          return GetterUtil.getShort(getString(key));
70      }
71  
72      public String getString(String key) {
73          String value = _fields.get(key);
74  
75          if (value == null) {
76              return StringPool.BLANK;
77          }
78          else {
79              return value;
80          }
81      }
82  
83      private Map<String, String> _fields = new HashMap<String, String>();
84  
85  }