1 package com.atlassian.plugin.web.model;
2
3 import com.atlassian.plugin.PluginParseException;
4 import com.atlassian.plugin.web.WebFragmentHelper;
5 import com.atlassian.plugin.web.ContextProvider;
6 import com.atlassian.plugin.web.descriptors.WebFragmentModuleDescriptor;
7 import org.dom4j.Element;
8
9 import javax.servlet.http.HttpServletRequest;
10 import java.util.*;
11
12
13
14
15 public class DefaultWebLabel extends DefaultWebParam implements WebLabel
16 {
17 String key;
18 String noKeyValue;
19
20 public DefaultWebLabel(Element labelEl, WebFragmentHelper webFragmentHelper, ContextProvider contextProvider, WebFragmentModuleDescriptor descriptor) throws PluginParseException
21 {
22 super(labelEl, webFragmentHelper, contextProvider, descriptor);
23 if (labelEl == null)
24 {
25 throw new PluginParseException("You must specify a label for the section.");
26 }
27 else
28 {
29 this.key = labelEl.attributeValue("key");
30
31 if (this.key == null)
32 {
33 this.noKeyValue = labelEl.getTextTrim();
34 }
35 }
36 }
37
38 public String getKey()
39 {
40 return key;
41 }
42
43 public String getNoKeyValue()
44 {
45 return noKeyValue;
46 }
47
48 public String getDisplayableLabel(HttpServletRequest req, Map context)
49 {
50 context.putAll(getContextMap(context));
51 if (key != null)
52 {
53 if (params == null || params.isEmpty())
54 {
55 return getWebFragmentHelper().getI18nValue(key, null, context);
56 }
57 else
58 {
59 List arguments = new ArrayList();
60
61
62 for (Iterator iterator = params.keySet().iterator(); iterator.hasNext();)
63 {
64 String key = (String) iterator.next();
65 if (key.startsWith("param"))
66 arguments.add(getWebFragmentHelper().renderVelocityFragment((String) params.get(key), context));
67 }
68
69 return getWebFragmentHelper().getI18nValue(key, arguments, context);
70 }
71 }
72 else
73 {
74 return getWebFragmentHelper().renderVelocityFragment(noKeyValue, context);
75 }
76 }
77 }