001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
026     * @author Brian Wing Shun Chan
027     * @deprecated As of 7.0.0, with no direct replacement
028     */
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    }