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.portlet.expando.util;
016    
017    import com.liferay.portal.kernel.util.UnicodeProperties;
018    import com.liferay.portlet.expando.model.ExpandoBridge;
019    import com.liferay.portlet.expando.model.ExpandoColumnConstants;
020    
021    /**
022     * @author Raymond Aug??
023     * @author Drew Brokke
024     */
025    public class ExpandoPresetUtil {
026    
027            public static int addPresetExpando(
028                            ExpandoBridge expandoBridge, String preset, String name)
029                    throws Exception {
030    
031                    int type = 0;
032    
033                    UnicodeProperties properties = null;
034    
035                    try {
036                            properties = expandoBridge.getAttributeProperties(name);
037                    }
038                    catch (Exception e) {
039                            properties = new UnicodeProperties();
040                    }
041    
042                    if (preset.equals("PresetSelectionIntegerArray()")) {
043                            type = ExpandoColumnConstants.INTEGER_ARRAY;
044    
045                            properties.setProperty(
046                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE,
047                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_SELECTION_LIST);
048                    }
049                    else if (preset.equals("PresetSelectionDoubleArray()")) {
050                            type = ExpandoColumnConstants.DOUBLE_ARRAY;
051    
052                            properties.setProperty(
053                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE,
054                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_SELECTION_LIST);
055                    }
056                    else if (preset.equals("PresetSelectionStringArray()")) {
057                            type = ExpandoColumnConstants.STRING_ARRAY;
058    
059                            properties.setProperty(
060                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE,
061                                    ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_SELECTION_LIST);
062                    }
063                    else if (preset.equals("PresetTextBox()")) {
064                            type = ExpandoColumnConstants.STRING;
065    
066                            properties.setProperty(
067                                    ExpandoColumnConstants.PROPERTY_HEIGHT, "105");
068                            properties.setProperty(
069                                    ExpandoColumnConstants.PROPERTY_WIDTH, "450");
070                    }
071                    else if (preset.equals("PresetTextBoxIndexed()")) {
072                            type = ExpandoColumnConstants.STRING;
073    
074                            properties.setProperty(
075                                    ExpandoColumnConstants.PROPERTY_HEIGHT, "105");
076                            properties.setProperty(
077                                    ExpandoColumnConstants.PROPERTY_WIDTH, "450");
078                            properties.setProperty(
079                                    ExpandoColumnConstants.INDEX_TYPE,
080                                    String.valueOf(ExpandoColumnConstants.INDEX_TYPE_TEXT));
081                    }
082                    else if (preset.equals("PresetTextFieldSecret()")) {
083                            type = ExpandoColumnConstants.STRING;
084    
085                            properties.setProperty(
086                                    ExpandoColumnConstants.PROPERTY_SECRET,
087                                    Boolean.TRUE.toString());
088                    }
089                    else {
090                            type = ExpandoColumnConstants.STRING;
091    
092                            properties.setProperty(
093                                    ExpandoColumnConstants.INDEX_TYPE,
094                                    String.valueOf(ExpandoColumnConstants.INDEX_TYPE_TEXT));
095                    }
096    
097                    expandoBridge.addAttribute(name, type);
098    
099                    expandoBridge.setAttributeProperties(name, properties);
100    
101                    return type;
102            }
103    
104    }