PageRenderTime 36ms CodeModel.GetById 11ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/plugin-module-codegen-engine/src/main/java/com/atlassian/plugins/codegen/modules/AbstractNameBasedModuleProperties.java

https://bitbucket.org/mmeinhold/amps
Java | 113 lines | 92 code | 18 blank | 3 comment | 7 complexity | d28804882d3d35765e7723c8706f4f4c MD5 | raw file
  1package com.atlassian.plugins.codegen.modules;
  2
  3import com.atlassian.plugins.codegen.util.ClassnameUtil;
  4
  5import com.google.common.collect.ImmutableMap;
  6
  7import org.apache.commons.lang.StringUtils;
  8
  9/**
 10 * @since 3.6
 11 */
 12public abstract class AbstractNameBasedModuleProperties extends AbstractPluginModuleProperties implements NameBasedModuleProperties
 13{
 14
 15    protected AbstractNameBasedModuleProperties()
 16    {
 17        super();
 18    }
 19
 20    protected AbstractNameBasedModuleProperties(AbstractNameBasedModuleProperties from)
 21    {
 22        super(from);
 23    }
 24    
 25    public void setModuleNameAndKey(String moduleName)
 26    {
 27        if (StringUtils.isNotBlank(moduleName))
 28        {
 29            setModuleName(moduleName);
 30            setModuleKey(ClassnameUtil.camelCaseOrSpaceToDashed(moduleName)
 31                    .toLowerCase());
 32            setDescription("The " + getProperty(MODULE_NAME) + " Plugin");
 33            setNameI18nKey(getProperty(MODULE_KEY) + ".name");
 34            setDescriptionI18nKey(getProperty(MODULE_KEY) + ".description");
 35        }
 36    }
 37
 38    @Override
 39    public void setModuleName(String name)
 40    {
 41        setProperty(MODULE_NAME, name);
 42    }
 43
 44    @Override
 45    public String getModuleName()
 46    {
 47        return getProperty(MODULE_NAME);
 48    }
 49
 50    @Override
 51    public void setModuleKey(String name)
 52    {
 53        setProperty(MODULE_KEY, name);
 54    }
 55
 56    @Override
 57    public String getModuleKey()
 58    {
 59        return getProperty(MODULE_KEY);
 60    }
 61
 62    @Override
 63    public void setDescription(String desc)
 64    {
 65        setProperty(DESCRIPTION, desc);
 66    }
 67
 68    @Override
 69    public String getDescription()
 70    {
 71        return getProperty(DESCRIPTION);
 72    }
 73
 74    @Override
 75    public void setDescriptionI18nKey(String key)
 76    {
 77        setProperty(DESCRIPTION_I18N_KEY, key);
 78    }
 79
 80    @Override
 81    public String getDescriptionI18nKey()
 82    {
 83        return getProperty(DESCRIPTION_I18N_KEY);
 84    }
 85
 86    @Override
 87    public void setNameI18nKey(String key)
 88    {
 89        setProperty(NAME_I18N_KEY, key);
 90    }
 91
 92    @Override
 93    public String getNameI18nKey()
 94    {
 95        return getProperty(NAME_I18N_KEY);
 96    }
 97
 98    @Override
 99    public ImmutableMap<String, String> getI18nProperties()
100    {
101        ImmutableMap.Builder<String, String> ret = ImmutableMap.<String, String>builder();
102        ret.putAll(super.getI18nProperties());
103        if (getNameI18nKey() != null)
104        {
105            ret.put(getNameI18nKey(), (getModuleName() == null) ? "" : getModuleName());
106        }
107        if (getDescriptionI18nKey() != null)
108        {
109            ret.put(getDescriptionI18nKey(), (getDescription() == null) ? "" : getDescription());
110        }
111        return ret.build();
112    }
113}