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