001    /**
002     * Copyright (c) 2000-2013 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.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.io.Serializable;
021    
022    import java.util.Date;
023    
024    /**
025     * @author Marcellus Tavares
026     */
027    public class FieldConstants {
028    
029            public static final String BOOLEAN = "boolean";
030    
031            public static final String DATA_TYPE = "dataType";
032    
033            public static final String DATE = "date";
034    
035            public static final String DOCUMENT_LIBRARY = "document-library";
036    
037            public static final String DOUBLE = "double";
038    
039            public static final String EDITABLE = "editable";
040    
041            public static final String FILE_UPLOAD = "file-upload";
042    
043            public static final String FLOAT = "float";
044    
045            public static final String INTEGER = "integer";
046    
047            public static final String LABEL = "label";
048    
049            public static final String LONG = "long";
050    
051            public static final String NAME = "name";
052    
053            public static final String NUMBER = "number";
054    
055            public static final String PREDIFINED_VALUE = "predefinedValue";
056    
057            public static final String REQUIRED = "required";
058    
059            public static final String SHORT = "short";
060    
061            public static final String SHOW = "showLabel";
062    
063            public static final String SORTABLE = "sortable";
064    
065            public static final String STRING = "string";
066    
067            public static final String TYPE = "type";
068    
069            public static final String VALUE = "value";
070    
071            public static final Serializable getSerializable(
072                    String type, String value) {
073    
074                    if (type.equals(BOOLEAN)) {
075                            return GetterUtil.getBoolean(value);
076                    }
077                    else if (type.equals(DATE) && Validator.isNotNull(value)) {
078                            return new Date(GetterUtil.getLong(value));
079                    }
080                    else if (type.equals(DOUBLE)) {
081                            return GetterUtil.getDouble(value);
082                    }
083                    else if (type.equals(FLOAT)) {
084                            return GetterUtil.getFloat(value);
085                    }
086                    else if (type.equals(INTEGER)) {
087                            return GetterUtil.getInteger(value);
088                    }
089                    else if (type.equals(LONG)) {
090                            return GetterUtil.getLong(value);
091                    }
092                    else if (type.equals(NUMBER)) {
093                            return GetterUtil.getNumber(value);
094                    }
095                    else if (type.equals(SHORT)) {
096                            return GetterUtil.getShort(value);
097                    }
098                    else {
099                            return value;
100                    }
101            }
102    
103    }