public class BasicAttachmentProvider extends Object implements WikiAttachmentProvider
Structure is as follows:
attachment_dir/
ThisPage/
attachment.doc/
attachment.properties
1.doc
2.doc
3.doc
picture.png/
attachment.properties
1.png
2.png
ThatPage/
picture.png/
attachment.properties
1.png
The names of the directories will be URLencoded.
"attachment.properties" consists of the following items:
| Modifier and Type | Class and Description |
|---|---|
static class |
BasicAttachmentProvider.AttachmentFilter
Returns only those directories that contain attachments.
|
static class |
BasicAttachmentProvider.AttachmentVersionFilter
Accepts only files that are actual versions, no control files.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
ATTDIR_EXTENSION
The default extension for the attachment directory.
|
static String |
DIR_EXTENSION
The default extension for the page attachment directory name.
|
static String |
PROP_DISABLECACHE
The property name for specifying which attachments are not cached.
|
static String |
PROP_STORAGEDIR
The property name for where the attachments should be stored.
|
static String |
PROPERTY_FILE
The name of the property file.
|
LATEST_VERSION| Constructor and Description |
|---|
BasicAttachmentProvider() |
| Modifier and Type | Method and Description |
|---|---|
void |
deleteAttachment(Attachment att)
Removes an entire page from the repository.
|
void |
deleteVersion(Attachment att)
Removes a specific version from the repository.
|
Collection<Attachment> |
findAttachments(QueryItem[] query)
Finds attachments based on the query.
|
InputStream |
getAttachmentData(Attachment att)
Get attachment data.
|
Attachment |
getAttachmentInfo(WikiPage page,
String name,
int version)
Returns info about an attachment.
|
protected static String |
getFileExtension(String filename)
Returns the file extension.
|
String |
getProviderInfo()
Return a valid HTML string for information.
|
List<Attachment> |
getVersionHistory(Attachment att)
Returns version history.
|
void |
initialize(WikiEngine engine,
Properties properties)
Initializes the page provider.
|
List<Attachment> |
listAllChanged(Date timestamp)
Lists changed attachments since given date.
|
List<Attachment> |
listAttachments(WikiPage page)
Lists all attachments attached to a page.
|
void |
moveAttachmentsForPage(String oldParent,
String newParent)
Move all the attachments for a given page so that they are attached to a
new page.
|
void |
putAttachmentData(Attachment att,
InputStream data)
Put new attachment data.
|
public static final String PROP_STORAGEDIR
public static final String PROP_DISABLECACHE
public static final String PROPERTY_FILE
public static final String DIR_EXTENSION
public static final String ATTDIR_EXTENSION
public BasicAttachmentProvider()
public void initialize(WikiEngine engine, Properties properties) throws NoRequiredPropertyException, IOException
initialize in interface WikiProviderengine - WikiEngine to own this providerproperties - A set of properties used to initialize this providerNoRequiredPropertyException - If the provider needs a property which is not found in the property setIOException - If there is an IO problemprotected static String getFileExtension(String filename)
If file has no extension, will return "bin"
filename - The file name to checkpublic void putAttachmentData(Attachment att, InputStream data) throws ProviderException, IOException
putAttachmentData in interface WikiAttachmentProvideratt - Attachment object to add new data todata - The stream from which the provider should read the dataProviderException - If there are other errors.IOException - If writing failspublic String getProviderInfo()
getProviderInfo in interface WikiProviderpublic InputStream getAttachmentData(Attachment att) throws IOException, ProviderException
getAttachmentData in interface WikiAttachmentProvideratt - The attachmentIOException - If the attachment cannot be openedProviderException - If the attachment cannot be foundpublic List<Attachment> listAttachments(WikiPage page) throws ProviderException
listAttachments in interface WikiAttachmentProviderpage - The page to list the attachments from.ProviderException - If something goes wrong when listing the attachments.public Collection<Attachment> findAttachments(QueryItem[] query)
findAttachments in interface WikiAttachmentProviderquery - An array of QueryItem objects to search forpublic List<Attachment> listAllChanged(Date timestamp) throws ProviderException
This is different from WikiPageProvider, where you basically get a list of all pages, then sort them locally. However, since some providers can be more efficient in locating recently changed files (like any database) than our non-optimized Java code, it makes more sense to fetch the whole list this way.
To get all files, call this with Date(0L);
listAllChanged in interface WikiAttachmentProvidertimestamp - List all files from this date onward.ProviderException - If something goes wrong.public Attachment getAttachmentInfo(WikiPage page, String name, int version) throws ProviderException
getAttachmentInfo in interface WikiAttachmentProviderpage - The parent pagename - The name of the attachmentversion - The version of the attachment (it's okay to use WikiPage.LATEST_VERSION to find the latest one)ProviderException - If the attachment cannot be found or some other error occurs.public List<Attachment> getVersionHistory(Attachment att)
getVersionHistory in interface WikiAttachmentProvideratt - The attachment for which to find the version history for.public void deleteVersion(Attachment att) throws ProviderException
deleteVersion in interface WikiAttachmentProvideratt - Attachment to be removed. The version field is checked, and thus
only that version is removed.ProviderException - If the attachment cannot be removed for some reason.public void deleteAttachment(Attachment att) throws ProviderException
deleteAttachment in interface WikiAttachmentProvideratt - Attachment to delete.ProviderException - If the page could not be removed for some reason.public void moveAttachmentsForPage(String oldParent, String newParent) throws ProviderException
moveAttachmentsForPage in interface WikiAttachmentProvideroldParent - Name of the page we are to move the attachments from.newParent - Name of the page we are to move the attachments to.ProviderException - If the attachments could not be moved for some
reason.Copyright © 2001-2019 The Apache Software Foundation. All rights reserved.