001
014
015 package com.liferay.util;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.StringUtil;
020
021 import java.util.HashMap;
022 import java.util.Map;
023
024
027 public class PKParser {
028
029 public PKParser(String pk) {
030 if (pk.startsWith(StringPool.OPEN_CURLY_BRACE)) {
031 pk = pk.substring(1, pk.length());
032 }
033
034 if (pk.endsWith(StringPool.CLOSE_CURLY_BRACE)) {
035 pk = pk.substring(0, pk.length() - 1);
036 }
037
038 String[] array = StringUtil.split(pk);
039
040 for (int i = 0; i < array.length; i++) {
041 String[] kvp = StringUtil.split(array[i], StringPool.EQUAL);
042
043 String key = kvp[0].trim();
044 String value = kvp[1].trim();
045
046 _fields.put(key, value);
047 }
048 }
049
050 public boolean getBoolean(String key) {
051 return GetterUtil.getBoolean(getString(key));
052 }
053
054 public double getDouble(String key) {
055 return GetterUtil.getDouble(getString(key));
056 }
057
058 public int getInteger(String key) {
059 return GetterUtil.getInteger(getString(key));
060 }
061
062 public long getLong(String key) {
063 return GetterUtil.getLong(getString(key));
064 }
065
066 public short getShort(String key) {
067 return GetterUtil.getShort(getString(key));
068 }
069
070 public String getString(String key) {
071 String value = _fields.get(key);
072
073 if (value == null) {
074 return StringPool.BLANK;
075 }
076 else {
077 return value;
078 }
079 }
080
081 private Map<String, String> _fields = new HashMap<String, String>();
082
083 }