PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/content/server/framework/atlassian-sdk/web-resource-transformer-plugin-module.md

https://bitbucket.org/zchristmas/atlassian-sdk-docs
Markdown | 188 lines | 153 code | 35 blank | 0 comment | 0 complexity | 66490ee661f04542157f4ae7f0f35ebe MD5 | raw file
Possible License(s): LGPL-2.0
  1. ---
  2. aliases:
  3. - /server/framework/atlassian-sdk/web-resource-transformer-plugin-module-852002.html
  4. - /server/framework/atlassian-sdk/web-resource-transformer-plugin-module-852002.md
  5. category: reference
  6. confluence_id: 852002
  7. dac_edit_link: https://developer.atlassian.com/pages/editpage.action?cjm=wozere&pageId=852002
  8. dac_view_link: https://developer.atlassian.com/pages/viewpage.action?cjm=wozere&pageId=852002
  9. date: '2017-12-08'
  10. legacy_title: Web Resource Transformer Plugin Module
  11. platform: server
  12. product: atlassian-sdk
  13. subcategory: modules
  14. title: Web Resource Transformer plugin module
  15. ---
  16. # Web Resource Transformer plugin module
  17. <table>
  18. <colgroup>
  19. <col style="width: 20%" />
  20. <col style="width: 80%" />
  21. </colgroup>
  22. <tbody>
  23. <tr class="odd">
  24. <td><p>Available:</p></td>
  25. <td><p><a href="https://developer.atlassian.com/pages/viewpage.action?pageId=852001">Atlassian Plugin Framework 2.5</a> and later.</p></td>
  26. </tr>
  27. </tbody>
  28. </table>
  29. ## Purpose of this Module Type
  30. Web Resource Transformer plugin modules allow you to manipulate static web resources before they are batched and delivered to the browser. This means that you can get past the restrictions of straight JavaScript and CSS, including restrictions like no includes, no external resource support, no CSS variables, only one JS context, and so on.
  31. ## Configuration
  32. To use a web resource transformer, you need the following elements in your `atlassian-plugin.xml` file:
  33. - **The transformer module:** A `<web-resource-transformer>` element, defining the transformer plugin module. This module can be in the same plugin as the web resource, or in a different plugin.
  34. - **Transformation elements in the web resource module:** A `<transformation>` element and its child `<transformer>` element inside the `<web-resource>` block, making a particular transformer available to the web resource in the plugin.
  35. Below is a description of the attributes and child elements for each of the above elements.
  36. #### Attributes of `web-resource-transformer`
  37. <table>
  38. <colgroup>
  39. <col style="width: 20%" />
  40. <col style="width: 80%" />
  41. </colgroup>
  42. <thead>
  43. <tr class="header">
  44. <th><p>Name*</p></th>
  45. <th><p>Description</p></th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. <tr class="odd">
  50. <td><p>class</p></td>
  51. <td>The class which implements <a href="http://docs.atlassian.com/atlassian-plugins-webresource/2.6.4/atlassian-plugins-webresource/apidocs/com/atlassian/plugin/webresource/transformer/WebResourceTransformer.html" class="external-link">com.atlassian.plugin.webresource.transformer.WebResourceTransformer</a>. This class is responsible for doing the resource transformation before it is served to the client. See the plugin framework guide to <a href="https://developer.atlassian.com/display/DOCS/Creating+Plugin+Module+Instances">creating plugin module instances</a>.</td>
  52. </tr>
  53. <tr class="even">
  54. <td><p>state</p></td>
  55. <td><p>Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').</p>
  56. <p><strong>Default:</strong> enabled</p></td>
  57. </tr>
  58. <tr class="odd">
  59. <td><p>i18n-name-key</p></td>
  60. <td>The localisation key for the human-readable name of the plugin module.</td>
  61. </tr>
  62. <tr class="even">
  63. <td><p>key</p></td>
  64. <td><p>The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.</p>
  65. <p> </p>
  66. <pre>
  67. <code>&lt;component-import
  68. key=&quot;appProps&quot;
  69. interface=&quot;com.atlassian.sal.api.ApplicationProperties&quot;/&gt;</code></pre>
  70. <p> </p>
  71. <p>In the example, <code>appProps</code> is the key for this particular module declaration, for <code>component-import</code>, in this case.</p>
  72. <p>The value of this attribute must match the <code>key</code> attribute of the <code>transformer</code> element in the <code>web-resource</code>.</p></td>
  73. </tr>
  74. <tr class="odd">
  75. <td><p>name</p></td>
  76. <td><p>The human-readable name of the plugin module.</p></td>
  77. </tr>
  78. <tr class="even">
  79. <td><p>system</p></td>
  80. <td><p>Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins.</p>
  81. <p><strong>Default:</strong> false</p></td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. **\*class and key attributes are required**
  86. #### Child Elements of `web-resource-transformer`
  87. | | |
  88. |-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
  89. | Name | description |
  90. | Description | The description of the plugin module. The 'key' attribute can be specified to declare a localisation key for the value instead of text in the element body. |
  91. #### Attributes of `transformation`
  92. | | |
  93. |:------------|:----------------------------------|
  94. | Name\* | extension |
  95. | Description | Defines a transformation process. |
  96. **\*extension attribute is required**
  97. #### Child Elements of `transformation`
  98. | | |
  99. |:------------|:----------------------------------|
  100. | Name\* | transformer |
  101. | Description | Defines a transformation process. |
  102. **\*transformer element is required**
  103. #### Attributes of `transformer`
  104. | | |
  105. |:------------|:------------------------------------------------------------------------------------------------------|
  106. | Name\* | key |
  107. | Description | The value of this attribute must match the `key` attribute of the `web-resource-transformer` element. |
  108. **\*key attribute is required**
  109. | | |
  110. |:------------|:------------------------------------------------------------------------------------------------------------|
  111. | Name | *(others)* |
  112. | Description | You can add your own attributes as required, to pass information to your implementation of the transformer. |
  113. #### Child Elements of `transformer`
  114. | | |
  115. |:------------|:----------------------------------------------------------------------------------------------------------------|
  116. | Name | *(others)* |
  117. | Description | You can add your own child elements as required, to pass information to your implementation of the transformer. |
  118. ## Example
  119. Here is an example `atlassian-plugin.xml` file containing a web resource and a transformer that turns a static template file into a JavaScript variable. You could use this transformer for common components that need to use client-side templates.
  120. ``` xml
  121. <atlassian-plugin name="Hello World Resource" key="example.plugin.helloworld" plugins-version="2">
  122. <plugin-info>
  123. <description>A web resource module with a transformer</description>
  124. <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
  125. <version>1.0</version>
  126. </plugin-info>
  127. <web-resource key="testTemplate">
  128. <transformation extension="txt">
  129. <transformer key="template" />
  130. </transformation>
  131. <resource type="download" name="testTemplate.js" location="testTemplate.txt" />
  132. <resource type="download" name="testTemplate.css" />
  133. </web-resource>
  134. <web-resource-transformer key="template" class="com.atlassian.labs.template.TemplateTransformer" />
  135. </atlassian-plugin>
  136. ```
  137. The template `testTemplate.txt` file looks like this:
  138. ``` text
  139. Hello world "bob"
  140. and 'friends'
  141. ```
  142. The JavaScript resulting from the transformation is:
  143. ``` javascript
  144. var testTemplate = "Hello world \"bob\"\nand \'friends\'";
  145. ```
  146. ## Notes
  147. Some information to be aware of when developing or configuring a Web Resource Transformer plugin module:
  148. - The `<web-resource-transformer>` module can live in the same plugin as the `<web-resource>` module, or in a different module. The transformers are registered globally.
  149. - You can apply multiple transformers. Any subsequent transformer will process the result of the earlier transformation.
  150. - You can pass information to the transformer by adding arbitrary attributes and child elements to the `<transformer>` element in the resource.
  151. ##### RELATED TOPICS
  152. [Web Resource Plugin Module](/server/framework/atlassian-sdk/web-resource-plugin-module)
  153. [Plugin Modules](/server/framework/atlassian-sdk/plugin-modules)