1   package com.atlassian.plugins.codegen.modules.confluence.blueprint;
2   
3   import com.atlassian.fugue.Pair;
4   import com.atlassian.plugins.codegen.modules.AbstractNameBasedModuleProperties;
5   import com.atlassian.plugins.codegen.modules.common.ContextProviderProperties;
6   import com.atlassian.plugins.codegen.modules.common.Resource;
7   import com.atlassian.plugins.codegen.modules.common.ResourcedProperties;
8   import com.google.common.collect.ImmutableMap;
9   import com.google.common.collect.Lists;
10  
11  import java.util.List;
12  
13  /**
14   * Holds properties for the <content-template> module descriptor used in Blueprint creation.
15   *
16   * @since 4.1.8
17   */
18  public class ContentTemplateProperties extends AbstractNameBasedModuleProperties implements ResourcedProperties
19  {
20      public static final String LOCATION = "LOCATION";
21      public static final String RESOURCES = "RESOURCES";
22      public static final String CONTEXT_PROVIDER = "CONTEXT_PROVIDER";
23      public static final String CONTENT_I18N_KEY = "CONTENT_I18N_KEY";
24      public static final String CONTENT_I18N_VALUE = "CONTENT_I18N_VALUE";
25      public static final String CONTENT_I18N_DEFAULT_VALUE = "This text will replace the at:i18n placeholder in the content template XML.";
26      public static final String INDEX_TEMPLATE_CONTENT_VALUE =
27          "This index page has used instead of the default one, by setting the index-template-key attribute of the blueprint config element.";
28  
29      public ContentTemplateProperties(String moduleKey)
30      {
31          super();
32          setModuleKey(moduleKey);
33      }
34  
35      public void addResource(Resource resource)
36      {
37          List<Resource> resources = getResources();
38          if (resources == null)
39          {
40              resources = Lists.newArrayList();
41              put(RESOURCES, resources);
42          }
43          resources.add(resource);
44      }
45  
46      public void setResources(List<Resource> resources)
47      {
48          put(RESOURCES, resources);
49      }
50  
51      @SuppressWarnings("unchecked")
52      public List<Resource> getResources()
53      {
54          return (List<Resource>) get(RESOURCES);
55      }
56  
57      public void setContextProvider(ContextProviderProperties provider)
58      {
59          put(CONTEXT_PROVIDER, provider);
60      }
61  
62      public ContextProviderProperties getContextProvider()
63      {
64          return (ContextProviderProperties) get(CONTEXT_PROVIDER);
65      }
66  
67      /**
68       * Sets the i18n key and value for the at:i18n placeholder in the template file XML.
69       */
70      public void setContentText(String i18nKey, String value)
71      {
72          put(CONTENT_I18N_KEY, i18nKey);
73          put(CONTENT_I18N_VALUE, value);
74      }
75  
76      @Override
77      public ImmutableMap<String, String> getI18nProperties()
78      {
79          return ImmutableMap.<String, String>builder()
80              .putAll(super.getI18nProperties())
81              .put(getProperty(CONTENT_I18N_KEY), getProperty(CONTENT_I18N_VALUE))
82              .build();
83      }
84  
85      @SuppressWarnings("unchecked")
86      public Pair getContentText()
87      {
88          return new Pair(getProperty(CONTENT_I18N_KEY), getProperty(CONTENT_I18N_VALUE));
89      }
90  }