Temporary Resource API

Last modified by Admin on 2017/11/29 20:16

cogAdds support for temporary resources
TypeJAR
Developed by

XWiki Development Team

Active Installs5
Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise

Compatibility

XWiki 8.3+, 8.2.2+, 7.4.6+

Installable with the Extension Manager

Description

Adds support for creating and accessing temporary resources by implementing and extending the Resource API.

Usage

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
@Named("standard/tmp")
private ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> urlTemporaryResourceReferenceSerializer;

Then you need to use the injected components like this:

// (1) Create the temporary resource reference.
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.urlTemporaryResourceReferenceSerializer.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.

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). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

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 9.10.1):

Tags:
Created by Marius Dumitru Florea on 2016/10/18 16:41
    

Get Connected