001    /**
002     * Copyright (c) 2000-2012 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 HTML = "html";
046    
047            public static final String INTEGER = "integer";
048    
049            public static final String LABEL = "label";
050    
051            public static final String LONG = "long";
052    
053            public static final String NAME = "name";
054    
055            public static final String NUMBER = "number";
056    
057            public static final String PREDIFINED_VALUE = "predefinedValue";
058    
059            public static final String REQUIRED = "required";
060    
061            public static final String SHORT = "short";
062    
063            public static final String SHOW = "showLabel";
064    
065            public static final String SORTABLE = "sortable";
066    
067            public static final String STRING = "string";
068    
069            public static final String TYPE = "type";
070    
071            public static final String VALUE = "value";
072    
073            public static final Serializable getSerializable(
074                    String type, String value) {
075    
076                    if (type.equals(BOOLEAN)) {
077                            return GetterUtil.getBoolean(value);
078                    }
079                    else if (type.equals(DATE) && Validator.isNotNull(value)) {
080                            return new Date(GetterUtil.getLong(value));
081                    }
082                    else if (type.equals(DOUBLE)) {
083                            return GetterUtil.getDouble(value);
084                    }
085                    else if (type.equals(FLOAT)) {
086                            return GetterUtil.getFloat(value);
087                    }
088                    else if (type.equals(INTEGER)) {
089                            return GetterUtil.getInteger(value);
090                    }
091                    else if (type.equals(LONG)) {
092                            return GetterUtil.getLong(value);
093                    }
094                    else if (type.equals(NUMBER)) {
095                            return GetterUtil.getNumber(value);
096                    }
097                    else if (type.equals(SHORT)) {
098                            return GetterUtil.getShort(value);
099                    }
100                    else {
101                            return value;
102                    }
103            }
104    
105    }