ZIP Explorer Plugin
Provides an API to create links to files inside a ZIP file |
Type | Plugin |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Table of contents
Description
ZIP-related APIs to list content of a ZIP attachments and to intercept XWiki download requests so that it's possible to display contents found inside ZIP files.
This plugin accepts specially formatted URLs pointing to files inside ZIP files by using the following syntax: http://[...]/download/Document/zipfile.zip/SomeDirectory/SomeFile.txt. In this example, the URL points to the SomeFile.txt file located in a directory named SomeDirectory inside a ZIP file named zipfile.zip and attached to the document named Document.
The following API are provided:
* @param document the document containing the ZIP file as an attachment
* @param attachmentName the name under which the ZIP file is attached in the document
* @return the list of file entries in the ZIP file attached under the passed attachment name inside the passed
* document
*/
List<String> getFileList(Document document, String attachmentName);
/**
* Finds the ZIP attachment with passed name from the passed document matching and parse the ZIP to generate a list
* of {@link com.xpn.xwiki.objects.classes.ListItem} elements representing a tree view of all directories and files
* in the ZIP. For example the following zip:
*
* <pre>
* zipfile.zip:
* Directory/File.txt
* File2.txt
* </pre>
*
* generates the following ListItem list:
*
* <pre>
*
* { id = "Directory/", value = "Directory", parent = ""}
* { id = "Directory/File.txt", value = "File.txt", parent = "Directory/"}
* { id = "File2.txt", value = "File2.txt", parent = ""}
*
* </pre>
*
* @param document the document containing the ZIP file as an attachment
* @param attachmentName the name under which the ZIP file is attached in the document
* @return a tree view list of {@link com.xpn.xwiki.objects.classes.ListItem} elements representing the content of
* the ZIP file
*/
List<ListItem> getFileTreeList(Document document, String attachmentName);
/**
* @param document the document containing the ZIP file as an attachment
* @param attachmentName the name under which the ZIP file is attached in the document
* @param fileName the filename to concatenate at the end of the attachment URL
* @return the attachment URL of the passed attachment located in the passed document to which the passed filename
* has been suffixed.
*/
String getFileLink(Document document, String attachmentName, String fileName);
In practice the Zip Explorer plugin intercepts the download action and adds support for the following type of URLs:
Example 1: Link to an attached Javadoc zip
Imagine that you have a JAR/ZIP file named xwiki-commons-component-api-3.4-javadoc.jar attached to the current page and that it contains some Javadoc (and thus it has an entry page named index.html). You'd create a link to the Javadoc like this:
[[Javadoc>>path:$xwiki.zipexplorer.getFileLink($doc, "xwiki-commons-component-api-3.4-javadoc.jar", "index.html")]]
{{/velocity}}
Example 2: List files in an attachment
The following example lists the files in an attached zip file. The file content may be viewed by clicking on the generated links.
#set($attachment="sample.zip")
#set($plugin=$xwiki.zipexplorer)
#foreach($file in $plugin.getFileTreeList($doc, $attachment))
* [[$file.id>>path:$plugin.getFileLink($doc, $attachment, $file.id)]]
#end
{{/velocity}}
Result
Prerequisites & Installation Instructions
To activate this plugin make sure the class com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPlugin is listed in the plugins property of the xwiki.cfg configuration file.
The id of the plugin is zipexplorer.