Temporary Resource API
Adds support for temporary resources |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Compatibility | XWiki 8.3+, 8.2.2+, 7.4.6+ |
Table of contents
Description
Adds support for creating and accessing temporary resources by implementing and extending the Resource API.
Usage
From Java
Here's how you can create temporary resources from Java. First you need to inject the required components.
* Used to create and access the temporary files.
*/
@Inject
private TemporaryResourceStore temporaryResourceStore;
/**
* Used to obtain the URL that corresponds to a temporary resource.
*/
@Inject
private ResourceReferenceSerializer<ResourceReference, ExtendedURL> resourceReferenceSerializer;
Then you need to use the injected components like this:
String moduleName = "chart";
List<String> resourcePath = Arrays.asList("pie", "issuesByReporter.png");
EntityReference owningEntityReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page");
TemporaryResourceReference temporaryResourceReference =
new TemporaryResourceReference(moduleName, resourcePath, owningEntityReference);
// (2) Create the temporary file ...
InputStream content = new ByteArrayInputStream("content".getBytes());
File tempFile = this.temporaryResourceStore.createTemporaryFile(temporaryResourceReference, content);
// ... or retrieve the temporary file by its reference (e.g. if you want to update it).
tempFile = this.temporaryResourceStore.getTemporaryFile(temporaryResourceReference);
// (3) Obtain the URL that can be used to access the above temporary file.
String temporaryResourceURL =
this.resourceReferenceSerializer.serialize(temporaryResourceReference).serialize();
Note that the URL format is an implementation detail and thus is subject to change. You should always use the ResourceReferenceSerializer to obtain the temporary resource URL.
From Scripts
XWiki 14.4.2+, 14.5+
There is a script service available to check if a temporary resource exists and to get its URL:
#set ($tempResourceReference = ...)
#if ($services.resource.temporary.exists($tempResourceReference))
[[Download>>path:$services.resource.temporary.getURL($tempResourceReference)]]
#end
{{/velocity}}
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).
You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.
Dependencies
Dependencies for this extension (org.xwiki.platform:xwiki-platform-resource-temporary 16.8.0):
- org.xwiki.platform:xwiki-platform-resource-api 16.8.0
- org.xwiki.platform:xwiki-platform-resource-servlet 16.8.0
- org.xwiki.platform:xwiki-platform-url-api 16.8.0
- org.xwiki.platform:xwiki-platform-security-authorization-api 16.8.0
- org.xwiki.platform:xwiki-platform-model-api 16.8.0