Package org.apache.wiki.attachment

# Class DynamicAttachment

java.lang.Object
org.apache.wiki.WikiPage
org.apache.wiki.attachment.Attachment
org.apache.wiki.attachment.DynamicAttachment

All Implemented Interfaces:
  `Cloneable`, `Comparable<org.apache.wiki.api.core.Page>`, `org.apache.wiki.api.core.Attachment`, `org.apache.wiki.api.core.Page`

public class DynamicAttachment extends Attachment
A DynamicAttachment is an attachment which does not really exist, but is created dynamically by a JSPWiki component.

Note that a DynamicAttachment might not be available before it is actually created by a component (e.g. plugin), and therefore trying to access it before that component has been invoked, might result in a surprising 404.

DynamicAttachments are not listed among regular attachments in the current version.

Usage:

      class MyDynamicComponent implements DynamicAttachmentProvider {
      ...

         DynamicAttachment destatt = mgr.getDynamicAttachment( destattname );

         if( destatt == null ) {
             destatt = new DynamicAttachment( context.getEngine(),
                                              context.getPage().getName(),
                                              destfilename,
                                              this );
             destatt.setCacheable( false );
         }

         // This is used to check whether the attachment is modified or not so don't forget to update this if your attachment source changes!
         // Else JSPWiki will be serving 304s to anyone who asks...

         destatt.setLastModified( context.getPage().getLastModified() );
         mgr.storeDynamicAttachment( context,  destatt );
      ...

          public InputStream getAttachmentData( WikiContext context, Attachment att ) throws IOException {
              byte[] bytes = "This is a test".getBytes();
              return new ByteArrayInputStream( bytes );
          }

Since:
  2.5.34

## Field Summary

### Fields inherited from interface org.apache.wiki.api.core.Page

`ALIAS, AUTHOR, CHANGENOTE, DESCRIPTION, REDIRECT, VIEWCOUNT`

## Constructor Summary

Constructors
Constructor
Description
`DynamicAttachment(org.apache.wiki.api.core.Engine engine, String parentPage, String fileName, DynamicAttachmentProvider provider)`
Creates a DynamicAttachment.

## Method Summary

Modifier and Type
Method
Description
`DynamicAttachmentProvider`
`getProvider()`
Returns the provider which is used to generate this attachment.

### Methods inherited from class org.apache.wiki.attachment.Attachment

`getFileName, getParentName, isCacheable, setCacheable, setFileName, toString`

### Methods inherited from class org.apache.wiki.WikiPage

`clone, compareTo, equals, getAcl, getAttribute, getAttributes, getAuthor, getLastModified, getName, getSize, getVersion, getWiki, hashCode, hasMetadata, invalidateMetadata, removeAttribute, setAcl, setAcl, setAttribute, setAuthor, setHasMetadata, setLastModified, setSize, setVersion`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Comparable

`compareTo`

### Methods inherited from interface org.apache.wiki.api.core.Page

`clone, getAcl, getAttribute, getAttributes, getAuthor, getLastModified, getName, getSize, getVersion, getWiki, hasMetadata, invalidateMetadata, removeAttribute, setAcl, setAttribute, setAuthor, setHasMetadata, setLastModified, setSize, setVersion`

## Constructor Details

### DynamicAttachment

public DynamicAttachment(org.apache.wiki.api.core.Engine engine, String parentPage, String fileName, DynamicAttachmentProvider provider)
Creates a DynamicAttachment.

Parameters:
  `engine` - The engine which owns this attachment
  `parentPage` - The page which owns this attachment
  `fileName` - The filename of the attachment
  `provider` - The provider which will be used to generate the attachment.

## Method Details

### getProvider

public DynamicAttachmentProvider getProvider()
Returns the provider which is used to generate this attachment.

Returns:
  A Provider component for this attachment.