PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/atlassian-plugins-webfragment/src/main/java/com/atlassian/plugin/web/descriptors/DefaultWebItemModuleDescriptor.java

https://bitbucket.org/atlassian/atlassian-plugins-webfragment
Java | 95 lines | 74 code | 17 blank | 4 comment | 12 complexity | de69fdaa5259552337c7bdbd9c37da6c MD5 | raw file
  1. package com.atlassian.plugin.web.descriptors;
  2. import com.atlassian.plugin.Plugin;
  3. import com.atlassian.plugin.PluginParseException;
  4. import com.atlassian.plugin.web.WebInterfaceManager;
  5. import com.atlassian.plugin.web.model.DefaultWebIcon;
  6. import com.atlassian.plugin.web.model.DefaultWebLink;
  7. import com.atlassian.plugin.web.model.WebIcon;
  8. import com.atlassian.plugin.web.model.WebLink;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.dom4j.Element;
  11. /**
  12. * Represents a pluggable link.
  13. */
  14. public class DefaultWebItemModuleDescriptor extends AbstractWebFragmentModuleDescriptor<Void> implements WebItemModuleDescriptor {
  15. private String section;
  16. private WebIcon icon;
  17. private DefaultWebLink link;
  18. private String styleClass;
  19. private String entryPoint;
  20. public DefaultWebItemModuleDescriptor(final WebInterfaceManager webInterfaceManager) {
  21. super(webInterfaceManager);
  22. }
  23. public DefaultWebItemModuleDescriptor() {
  24. }
  25. @Override
  26. public void init(final Plugin plugin, final Element element) throws PluginParseException {
  27. super.init(plugin, element);
  28. section = element.attributeValue("section");
  29. if (element.element("styleClass") != null) {
  30. styleClass = element.element("styleClass")
  31. .getTextTrim();
  32. } else {
  33. styleClass = "";
  34. }
  35. if (element.element("entry-point") != null) {
  36. entryPoint = element.element("entry-point")
  37. .getTextTrim();
  38. } else {
  39. entryPoint = "";
  40. }
  41. }
  42. public String getSection() {
  43. return section;
  44. }
  45. public WebLink getLink() {
  46. return link;
  47. }
  48. public WebIcon getIcon() {
  49. return icon;
  50. }
  51. public String getStyleClass() {
  52. return styleClass;
  53. }
  54. public String getEntryPoint() {
  55. if (StringUtils.isNotBlank(entryPoint)) {
  56. if (entryPoint.matches("^.+:.+$")) {
  57. return entryPoint;
  58. }
  59. return plugin.getKey() + ":" + entryPoint;
  60. }
  61. return null;
  62. }
  63. @Override
  64. public void enabled() {
  65. super.enabled();
  66. // contextProvider is not available until the module is enabled because they may need to have dependencies injected
  67. if (element.element("icon") != null) {
  68. icon = new DefaultWebIcon(element.element("icon"), webInterfaceManager.getWebFragmentHelper(), contextProvider, this);
  69. }
  70. if (element.element("link") != null) {
  71. link = new DefaultWebLink(element.element("link"), webInterfaceManager.getWebFragmentHelper(), contextProvider, this);
  72. }
  73. }
  74. @Override
  75. public Void getModule() {
  76. return null;
  77. }
  78. }