各種Manager系Objectが取れないと話にならないですよねーってことで。
Servletプラグイン編
servletプラグインの場合は、コンストラクタに書く。
書いておいて当たればSpringの方で適当にInjectionしてくれる。
public class HogehogeServlet extends HttpServlet{ private final SpaceManager spaceManager; private final PageManager pageManager; private final BandanaManager bandanaManager; private final ContentPropertyManager contentPropertyManager; private final AttachmentManager attachmentManager; HogehogeServlet(SpaceManager spaceManager, PageManager pageManager,BandanaManager bandanaManager, ContentPropertyManager contentPropertyManager, AttachmentManager attachmentManager) { this.spaceManager = spaceManager; this.pageManager = pageManager; this.bandanaManager = bandanaManager; this.contentPropertyManager = contentPropertyManager; this.attachmentManager = attachmentManager; } }
といった感じで。Injectionしてくれるから、順番とか個数とかは適当でOK。うーん、便利。
XWork編
XWork/Webworkを使った場合は、各Managerのsetterを定義しておく。こうすることでSpringの方でInjectionしてくれる。
http://lsd.luminis.eu/developing-a-confluence-plugin/
To get hold of the correct manager objects, all you need to do is declare a variable and a setter for the variable and Spring will auto-inject the right managers:
XWork/Webworkの場合、pageもsetterを作っておけばPageオブジェクトを入れてくれる。こんな感じになる。
public class FooAction extends ViewPageAction implements PageAware { private AbstractPage page; /** * Get the value of page * * @return the value of page */ @Override public AbstractPage getPage() { return page; } /** * Set the value of page * * @param page new value of page */ @Override public void setPage(AbstractPage page) { this.page = page; } private BandanaManager bandanaManager; /** * Set the value of bandanaManager * * @param bandanaManager */ public void setBandanaManager(BandanaManager bandanaManager) { this.bandanaManager = bandanaManager; } private ContentPropertyManager contentPropertyManager; /** * Set the value of contentPropertyManager * * @param contentPropertyManager new value of contentPropertyManager */ public void setContentPropertyManager(ContentPropertyManager contentPropertyManager) { this.contentPropertyManager = contentPropertyManager; } }
どういったManagerが取れるのか?
しっかり調べてないけど・・・
confluence-core/confluence/src/etc/java/applicationContext.xml
辺りでずらずらっと並んでいるのは取れそうな感じ。。。
userStatusManager followManager spaceManager spaceGroupManager spaceDescriptionManager labelManager pageManager pageTemplateManager linkManager commentManager contentEntityManager smartListManager referralManager notificationManager contentPropertyManager userContentManager messageManager clusterSafetyManager formatSettingsManager trashManager likeManager
とか?
更に、デフォルトでは使えないManagerも
atlassian-plugin.xmlでcomponent-importすれば使えるらしい?
Component Import Plugin Module - Documentation - Atlassian Developer Documentation
によると、プラグイン間でcomponentを貸し借りすることができるようだ。
たとえば、ここにないloginUriProviderというのは、
confluence-project/confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-plugin/src/main/resources/atlassian-plugin.xml
にcomponentが定義してあって、使う側では
<component-import key="loginUriProvider" interface="com.atlassian.sal.api.auth.LoginUriProvider" />
ってatlassian-plugin.xmlに記述してやることで、ServletやXWorkから使えるようになる。
ようだっていうのは、まだこれ以外のcomponentについては未確認。