blob: 475473a4c93986276b22be499a9355a04daeb0b4 [file] [log] [blame]
The FileSystemResourceRenference comes along with the FileSystemResource, FileSystemResourceStreamReference and the FileSystemResourceStream. Those classes provide a simple way to handle resources with Java's NIO API in Wicket starting from JDK version 7.0. (Available since Wicket 7.2.0 / Wicket 8.0.0)
Example: To include a resource which is zipped into a file and located in a specific folder in the file system you can simply write code like this:
Java:
{code}
URI uri = URI.create("jar:file:///videosFolder/videos.zip!/folderInZip/Video.mp4");
Path path = FileSystemResourceReference.getPath(uri);
FileSystemResourceReference ref = new FileSystemResourceReference("video",path);
Video video = new Video("video",ref);
add(vide);
{code}
HTML:
{code}
<video wicket:id="video"/>
{code}
Using FileSystemResourceReference mounted:
Java:
{code}
mountResource("/filecontent/${name}", new FileSystemResourceReference("filesystem")
{
private static final long serialVersionUID = 1L;
@Override
public IResource getResource()
{
return new FileSystemResource()
{
private static final long serialVersionUID = 1L;
protected ResourceResponse newResourceResponse(Attributes attributes)
{
try
{
String name = attributes.getParameters().get("name").toString("");
URI uri = URI.create(
"jar:file:////folder/example.zip!/zipfolder/" + name);
return createResourceResponse(
FileSystemResourceReference.getPath(uri));
}
catch (IOException | URISyntaxException e)
{
throw new WicketRuntimeException("Error while reading the file.", e);
}
};
};
}
});
{code}
FileSystemResourceReference.getPath(uri) uses a FileSystemPathService to setup a path the resource reference can work on.
So if you write a custom file system you can easily handle every path by adding a *org.apache.wicket.resource.FileSystemPathService* text file into *META-INF/services* and put in your implementation.
A reference implementation can be found in the java class org.apache.wicket.resource.FileSystemJarPathService.
Further FileSystemProviders and the corresponding FileSystems can be implemented as described here:
[http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html|http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html]