Available: | Confluence 3.4 and later |
WebDAV Resource modules allow you to define new kinds of content within Confluence that can be accessed remotely via the Confluence WebDAV plugin. You could use this functionality to expose your own custom entities over WebDAV, or expose existing Confluence content that is not currently accessible over WebDAV.
The definition for the WebDAV Resource module resides within the Confluence WebDAV plugin. In order to use the module, you will need to add a dependency on the WebDAV plugin to your plugin's pom.xml
.
The new dependency should look like this:
1 2<dependency> <groupId>com.atlassian.confluence.extra.webdav</groupId> <artifactId>webdav-plugin</artifactId> <version>2.5</version> <scope>provided</scope> </dependency>
Your plugin will need to be a plugin framework version 2 plugin for the dependency to work. See Version 1 or Version 2 Plugin (Glossary Entry) and Converting from Version 1 to Version 2 (OSGi) Plugins.
You will also need to add a new element to your atlassian-plugin.xml
that declares your WebDAV Resource module. The root element for the module is davResourceFactory
. It allows the following attributes and child elements for configuration:
Name* | Description |
---|---|
class | The class which implements this plugin module. For the WebDAV Resource module, this class must implement |
disabled | Indicate whether the plugin module should be disabled by default (value='true') or enabled by default (value='false'). Default: false |
i18n-name-key | The localisation key for the human-readable name of the plugin module. |
key | The identifier of the plugin module. This key must be unique within the plugin where it is defined. Default: N/A |
name | The human-readable name of the plugin module. Default: The plugin key. |
workspace | The name of the root WebDAV context where your content will be hosted. This workspace name forms part of the URL to your WebDAV content. For example, a workspace name of 'mywebdav' would result in a WebDAV URL of |
*class, key, and workspace attributes are required
Name | Description |
---|---|
description | The description of the plugin module. You can specify the 'key' attribute to declare a localisation key for the value instead of text in the element body. |
Here is an example atlassian-plugin.xml
containing a definition for a single WebDAV Resource module:
1 2<atlassian-plugin name="My WebDAV Plugin" key="example.plugin.webdav" plugins-version="2"> <plugin-info> <description>A basic WebDAV Resource module test</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <davResourceFactory key="myResourceFactory" name="My WebDAV Resource Factory" workspace="mywebdav" class="example.plugin.webdav.MyResourceFactory"> <description> Exposes my plugin's content through the Confluence WebDAV plugin. </description> </davResourceFactory> <atlassian-plugin>
The MyResourceFactory
class needs to implement the org.apache.jackrabbit.webdav.DavResourceFactory
interface. The purpose of this class is to construct new instances of objects that implement the org.apache.jackrabbit.webdav.DavResource
interface. The factory will typically inspect the incoming request URL from the client in order to determine which DavResource should be created and returned. For example, a request to /plugins/servlet/confluence/default/Global/DS
will return a com.atlassian.confluence.extra.webdav.resource.SpaceResource
for the Confluence Demonstration space.
Here's an example of an implementation for MyResourceFactory:
1 2package example.plugin.webdav; import com.atlassian.confluence.extra.webdav.ConfluenceDavSession; import org.apache.jackrabbit.webdav.*; public class MyResourceFactory implements DavResourceFactory { private SettingsManager settingsManager; // used by the HelloWorldResource. public MyResourceFactory(SettingsManager settingsManager) { this.settingsManager = settingsManager; } public DavResource createResource(DavResourceLocator davResourceLocator, DavServletRequest davServletRequest, DavServletResponse davServletResponse) throws DavException { // Delegate this call to the alternative createResource overload DavSession davSession = (DavSession) davServletRequest.getSession().getAttribute(ConfluenceDavSession.class.getName()); return createResource(davResourceLocator, davSession); } /** * Returns a reference to the WebDAV resource identified by the current location (represented in the * davResourceLocator parameter). For example, a WebDAV request for the URL * "http://confluence-server/plugins/servlet/confluence/default/ds" would return a {@link SpaceResource} * representing the Demonstration Space. * @param davResourceLocator identifies the requested resource * @param davSession the current web session * @return A instance of {@link DavResource} representing the WebDAV resource at the requested location * @throws DavException thrown if any kind of non-OK HTTP Status should be returned. */ public DavResource createResource(DavResourceLocator davResourceLocator, DavSession davSession) throws DavException { // this is a trivial example that always returns the HelloWorldResource. A more complete implementation would // probably examine the davResourceLocator.getResourcePath() value to examine the incoming request URL. ConfluenceDavSession confluenceDavSession = (ConfluenceDavSession)davSession; return new HelloWorldResource(davResourceLocator, this, confluenceDavSession.getLockManager(), confluenceDavSession, settingsManager); } }
As part of your implementation of a WebDAV Resource Module, you will need to create classes that implement DavResource
representing the content you want to expose over WebDAV. The Confluence WebDAV plugin provides a number of base classes that you can inherit from in order to simplify this step. Here is a brief listing of the classes that your WebDAV resources can inherit from:
Here is a sample implementation of the HelloWorldResource, which inherits from AbstractTextContentResource
.
1 2package example.plugin.webdav; import org.apache.jackrabbit.webdav.*; import com.atlassian.confluence.extra.webdav.*; public class HelloWorldResource extends AbstractTextContentResource { private const String HELLO_WORLD = "Hello, World!"; public AbstractTextContentResource( DavResourceLocator davResourceLocator, DavResourceFactory davResourceFactory, LockManager lockManager, ConfluenceDavSession davSession, SettingsManager settingsManager) { super(davResourceLocator, davResourceFactory, lockManager, davSession, settingsManager); } protected long getCreationtTime() { return 0; } protected byte[] getTextContentAsBytes(String encoding) throws UnsupportedEncodingException { return HELLO_WORLD.getBytes(encoding); } }
Writing Confluence Plugins
Installing a Plugin
Confluence WebDAV Plugin
Rate this page: