tohokuaikiのチラシの裏

技術的ネタとか。

Confluenceのプラグインを作ってみるメモ(3) - WEBリソースの変更するプラグイン

JavaScriptをヘッダータグ内に読み込ませる記述を書くプラグイン

Web Resource Module - Confluence Development - Atlassian Developer Documentation
を参考に。

atlassian-plugin.xml

プラグインの設定ファイルであるatlassian-plugin.xmlに、<web-resource>セクションを埋め込む。

こんな感じ。

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
    </plugin-info>

    <web-resource key="my-macro-resources">
        <resource type="download" name="mymacro2.js" location="js/alert.js"/>
        <context>atl.general</context>
    </web-resource>
</atlassian-plugin>

このXML設定について詳しくは
Adding Plugin and Module Resources - Confluence Development - Atlassian Developer Documentation
に書いてある。

web-resource要素について、key属性は、このプラグインでのキーとなる。プラグイン内でユニークであること。

その中の<resource>要素については、name属性が実際にヘッダータグ内に書き出される<script src=の所に関係するものになる。上記のXML設定だと、

<script type="text/javascript" src="/confluence/s/1911/42974/1.0-SNAPSHOT/_/download/resources/jp.junoe.confluence.plugins.junoeeditplus:my-macro-resources/mymacro2.js" ></script>

みたいになる。

重要なのはlocationで、これは相対パス指定になっているけど、それはatlassian-plugin.xmlからの相対指定。

また、<context>要素については、このリソースをどこに出すかっていう設定で、

  1. atl.general:どこでも
  2. atl.admin:管理画面
  3. atl.userprofile:ユーザー情報
  4. atl.popup:OAuthの認証チェックなんかで開かれるポップアップ画面

となっている。

ただし、David Simpsonさんがこのページのコメントで言ってるように、atl.adminは次の4つのタイプも併せて記述しないと動かないみたい。

		<context>page</context>
		<context>dashboard</context>
		<context>space</context>
		<context>main</context>

それぞれの意味するところは、何となくわかる。