1   package com.atlassian.plugins.codegen.modules.confluence.blueprint;
2   
3   import com.atlassian.plugins.codegen.ComponentDeclaration;
4   import com.atlassian.plugins.codegen.modules.BasicNameModuleProperties;
5   import com.atlassian.plugins.codegen.modules.common.web.WebItemProperties;
6   import com.atlassian.plugins.codegen.modules.common.web.WebResourceProperties;
7   import com.google.common.collect.ImmutableMap;
8   
9   import java.util.List;
10  
11  import static com.google.common.collect.Lists.newArrayList;
12  
13  /**
14   * Holds properties for a Confluence Blueprint.
15   *
16   * @since 4.1.8
17   */
18  public class BlueprintProperties extends BasicNameModuleProperties
19  {
20      public static final String INDEX_KEY = "INDEX_KEY";
21      public static final String WEB_ITEM = "WEB_ITEM";
22      private static final String WEB_RESOURCE = "WEB_RESOURCE";
23      public static final String WEB_ITEM_BLUEPRINT_KEY = "blueprintKey";
24      public static final String CONTENT_TEMPLATES = "CONTENT_TEMPLATES";
25      private static final String HOW_TO_USE_TEMPLATE = "HOW_TO_USE_TEMPLATE";
26      private static final String CREATE_RESULT = "CREATE_RESULT";
27      private static final String INDEX_PAGE_TEMPLATE = "INDEX_PAGE_TEMPLATE";
28      public static final String DIALOG_WIZARD = "DIALOG_WIZARD";
29      public static final String INDEX_TITLE_I18N_KEY = "INDEX_TITLE_I18N_KEY";
30  
31      public static final String SOY_PACKAGE = "SOY_PACKAGE";
32  
33      public static final String PLUGIN_KEY = "PLUGIN_KEY";
34      public static final String WEB_ITEM_KEY = "WEB_ITEM_KEY";
35      public static final String EVENT_LISTENER = "EVENT_LISTENER";
36      public static final String WIZARD_FORM_TITLE_FIELD_ID = "WIZARD_FORM_TITLE_FIELD_ID";
37      public static final String CREATE_RESULT_VIEW = "view";
38      public static final String INDEX_TEMPLATE_DEFAULT_KEY = "custom-index-page-template";
39  
40      public BlueprintProperties()
41      {
42          List<ContentTemplateProperties> contentTemplateKeys = newArrayList();
43          put(CONTENT_TEMPLATES, contentTemplateKeys);
44      }
45  
46      public void setPluginKey(String pluginKey)
47      {
48          setProperty(PLUGIN_KEY, pluginKey);
49      }
50  
51      public String getPluginKey()
52      {
53          return getProperty(PLUGIN_KEY);
54      }
55  
56      public void addContentTemplate(ContentTemplateProperties templateProps)
57      {
58          getContentTemplates().add(templateProps);
59      }
60  
61      @SuppressWarnings("unchecked")
62      public List<ContentTemplateProperties> getContentTemplates()
63      {
64          return (List<ContentTemplateProperties>) get(CONTENT_TEMPLATES);
65      }
66  
67      public void setWebItem(WebItemProperties webItem)
68      {
69          put(WEB_ITEM, webItem);
70      }
71  
72      public WebItemProperties getWebItem()
73      {
74          return (WebItemProperties) get(WEB_ITEM);
75      }
76  
77      public void setWebResource(WebResourceProperties webResource)
78      {
79          put(WEB_RESOURCE, webResource);
80      }
81  
82      public WebResourceProperties getWebResource()
83      {
84          return (WebResourceProperties) get(WEB_RESOURCE);
85      }
86  
87      public void setIndexKey(String indexKey)
88      {
89          setProperty(INDEX_KEY, indexKey);
90      }
91  
92      public String getIndexKey()
93      {
94          return getProperty(INDEX_KEY);
95      }
96  
97      public void setHowToUseTemplate(String howToUseTemplate)
98      {
99          put(HOW_TO_USE_TEMPLATE, howToUseTemplate);
100     }
101 
102     public String getHowToUseTemplate()
103     {
104         return (String) get(HOW_TO_USE_TEMPLATE);
105     }
106 
107     public void setCreateResult(String createResult)
108     {
109         setProperty(CREATE_RESULT, createResult);
110     }
111 
112     public String getCreateResult()
113     {
114         return getProperty(CREATE_RESULT);
115     }
116 
117     public void setDialogWizard(DialogWizardProperties props)
118     {
119         put(DIALOG_WIZARD, props);
120     }
121 
122     public DialogWizardProperties getDialogWizard()
123     {
124         return (DialogWizardProperties) get(DIALOG_WIZARD);
125     }
126 
127     public void setIndexTitleI18nKey(String key)
128     {
129         setProperty(INDEX_TITLE_I18N_KEY, key);
130     }
131 
132     public String getIndexTitleI18nKey()
133     {
134         return getProperty(INDEX_TITLE_I18N_KEY);
135     }
136 
137     public void setEventListener(ComponentDeclaration component)
138     {
139         put(EVENT_LISTENER, component);
140     }
141 
142     public ComponentDeclaration getEventListener()
143     {
144         return (ComponentDeclaration) get(EVENT_LISTENER);
145     }
146 
147     @Override
148     public ImmutableMap<String, String> getI18nProperties()
149     {
150         ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
151         mapBuilder.putAll(super.getI18nProperties());
152         if (getDialogWizard() != null)
153         {
154             mapBuilder.putAll(getDialogWizard().getI18nProperties());
155         }
156         return mapBuilder.build();
157     }
158 
159     public ContentTemplateProperties getIndexPageContentTemplate()
160     {
161         return (ContentTemplateProperties) get(INDEX_PAGE_TEMPLATE);
162     }
163 
164     public void setIndexPageContentTemplate(ContentTemplateProperties indexPageTemplate)
165     {
166         put(INDEX_PAGE_TEMPLATE, indexPageTemplate);
167     }
168 }