Package org.apache.axiom.attachments

# Class Attachments

java.lang.Object
org.apache.axiom.attachments.Attachments

All Implemented Interfaces:
  `OMAttachmentAccessor`

public class Attachments extends Object implements OMAttachmentAccessor

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Attachments()`
  Use this constructor when instantiating this to store the attachments set programatically through the SwA API.
  `Attachments(InputStream inStream, String contentTypeString)`
  Sets file cache to false.
  `Attachments(InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold)`
  Moves the pointer to the beginning of the first MIME part.
  `Attachments(InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold, int contentLength)`
  Moves the pointer to the beginning of the first MIME part.
  `Attachments(LifecycleManager manager, InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold)`
  Moves the pointer to the beginning of the first MIME part.
  `Attachments(LifecycleManager manager, InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold, int contentLength)`
  Moves the pointer to the beginning of the first MIME part.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addDataHandler(String contentID, DataHandler dataHandler)`
  Programatically adding an SOAP with Attachments(SwA) Attachment.
  `String[]`
  `getAllContentIDs()`
  Get the content IDs of all MIME parts in the message.
  `String`
  `getAttachmentSpecType()`
  Identify the type of message (MTOM or SOAP with attachments) represented by this object.
  `Blob`
  `getBlob(String contentID)`
  Get the content of the MIME part identified by a given content ID.
  `List<String>`
  `getContentIDList()`
  Get the content IDs of the already loaded MIME parts in the message.
  `Set<String>`
  `getContentIDSet()`
  Get the content IDs of all MIME parts in the message.
  `long`
  `getContentLength()`
  If the Attachments is backed by an InputStream, then this method returns the length of the message contents (Length of the entire message - Length of the Transport Headers)
  `DataHandler`
  `getDataHandler(String contentID)`
  Get the `DataHandler` object for the MIME part with a given content ID.
  `InputStream`
  `getIncomingAttachmentsAsSingleStream()`
  Deprecated.
  As of Axiom 1.2.13, this method is no longer supported.
  `IncomingAttachmentStreams`
  `getIncomingAttachmentStreams()`
  Stream based access
  `LifecycleManager`
  `getLifecycleManager()`
  `Map<String,DataHandler>`
  `getMap()`
  Get a map of all MIME parts in the message.
  `MultipartBody`
  `getMultipartBody()`
  `String`
  `getRootPartContentID()`
  Get the content ID of the root part of the MIME message.
  `String`
  `getRootPartContentType()`
  Get the content type of the root part of the MIME message.
  `InputStream`
  `getRootPartInputStream()`
  Get an input stream for the root part of the MIME message.
  `InputStream`
  `getRootPartInputStream(boolean preserve)`
  Get an input stream for the root part of the MIME message.
  `String`
  `getSOAPPartContentID()`
  Deprecated.
  Use `getRootPartContentID()` instead.
  `String`
  `getSOAPPartContentType()`
  Deprecated.
  Use `getRootPartContentType()` instead.
  `InputStream`
  `getSOAPPartInputStream()`
  Deprecated.
  Use `getRootPartInputStream()` instead.
  `void`
  `removeDataHandler(String blobContentID)`
  Removes the DataHandler corresponding to the given contenID.
  `void`
  `setLifecycleManager(LifecycleManager manager)`

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Attachments

    public Attachments(LifecycleManager manager, InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold) throws OMException
    Moves the pointer to the beginning of the first MIME part. Reads till first MIME boundary is found or end of stream is reached.
    Parameters:
      `inStream` -
      `contentTypeString` -
      `fileCacheEnable` -
      `attachmentRepoDir` -
    Throws:
      `OMException`

  - ### Attachments

    public Attachments(LifecycleManager manager, InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold, int contentLength) throws OMException
    Moves the pointer to the beginning of the first MIME part. Reads till first MIME boundary is found or end of stream is reached.
    Parameters:
      `inStream` -
      `contentTypeString` -
      `fileCacheEnable` -
      `attachmentRepoDir` -
      `fileThreshold` -
      `contentLength` -
    Throws:
      `OMException`

  - ### Attachments

    public Attachments(InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold) throws OMException
    Moves the pointer to the beginning of the first MIME part. Reads till first MIME boundary is found or end of stream is reached.
    Parameters:
      `inStream` -
      `contentTypeString` -
      `fileCacheEnable` -
      `attachmentRepoDir` -
    Throws:
      `OMException`

  - ### Attachments

    public Attachments(InputStream inStream, String contentTypeString, boolean fileCacheEnable, String attachmentRepoDir, String fileThreshold, int contentLength) throws OMException
    Moves the pointer to the beginning of the first MIME part. Reads till first MIME boundary is found or end of stream is reached.
    Parameters:
      `inStream` -
      `contentTypeString` -
      `fileCacheEnable` -
      `attachmentRepoDir` -
      `fileThreshold` -
      `contentLength` -
    Throws:
      `OMException`

  - ### Attachments

    public Attachments(InputStream inStream, String contentTypeString) throws OMException
    Sets file cache to false.
    Parameters:
      `inStream` -
      `contentTypeString` -
    Throws:
      `OMException`

  - ### Attachments

    public Attachments()
    Use this constructor when instantiating this to store the attachments set programatically through the SwA API.

- ## Method Details

  - ### getLifecycleManager

    public LifecycleManager getLifecycleManager()

  - ### setLifecycleManager

    public void setLifecycleManager(LifecycleManager manager)

  - ### getAttachmentSpecType

    public String getAttachmentSpecType()
    Identify the type of message (MTOM or SOAP with attachments) represented by this object. Note that this method is only meaningful if the instance was created from a stream.
    Returns:
      One of the `MTOMConstants.MTOM_TYPE`, `MTOMConstants.SWA_TYPE` or `MTOMConstants.SWA_TYPE_12` constants.
    Throws:
      `OMException` - if the message doesn't have one of the supported types (i.e. is neither MTOM nor SOAP with attachments) or if the instance was not created from a stream

  - ### getDataHandler

    public DataHandler getDataHandler(String contentID)
    Get the `DataHandler` object for the MIME part with a given content ID. The returned instance MAY implement `DataHandlerExt` in which case the caller can use that API to stream the content of the part. In addition, the `DataSource` linked to the returned `DataHandler` MAY be of type `SizeAwareDataSource` in which case the caller can use that interface to determine the size of the MIME part.
    Parameters:
      `contentID` - the raw content ID (without the surrounding angle brackets and `cid:` prefix) of the MIME part
    Returns:
      the `DataHandler` of the MIME part referred by the content ID or `null` if the MIME part referred by the content ID does not exist

  - ### addDataHandler

    public void addDataHandler(String contentID, DataHandler dataHandler)
    Programatically adding an SOAP with Attachments(SwA) Attachment. These attachments will get serialized only if SOAP with Attachments is enabled.
    Parameters:
      `contentID` -
      `dataHandler` -

  - ### removeDataHandler

    public void removeDataHandler(String blobContentID)
    Removes the DataHandler corresponding to the given contenID. If it is not present, then trying to find it calling the getNextPart() till the required part is found.
    Parameters:
      `blobContentID` -

  - ### getSOAPPartInputStream

    public InputStream getSOAPPartInputStream() throws OMException
    Deprecated.
    Use `getRootPartInputStream()` instead.
    Throws:
      `OMException`

  - ### getSOAPPartContentID

    public String getSOAPPartContentID()
    Deprecated.
    Use `getRootPartContentID()` instead.

  - ### getSOAPPartContentType

    public String getSOAPPartContentType()
    Deprecated.
    Use `getRootPartContentType()` instead.

  - ### getRootPartInputStream

    public InputStream getRootPartInputStream() throws OMException
    Get an input stream for the root part of the MIME message. The root part is located as described in the documentation of the `getRootPartContentID()` method. Note that a new stream is returned each time this method is called, i.e. the method does not consume the root part. Instead it loads the root part into memory so that it can be read several times.
    Returns:
      the input stream for the root part
    Throws:
      `OMException`

  - ### getRootPartInputStream

    public InputStream getRootPartInputStream(boolean preserve) throws OMException
    Get an input stream for the root part of the MIME message. This method is similar to `getRootPartInputStream()`, but can be instructed to consume the root part. This allows streaming of the root part. If that feature is used, the root part will not be loaded into memory unless an attempt is made to access another part of the MIME message, in which case the remaining (i.e. unconsumed) content of the root part will be buffered. If the feature is not enabled, then this method behaves in the same way as `getRootPartInputStream()`.
    Parameters:
      `preserve` - `true` if the content of the root part should be fetched into memory so that it can be read several times, `false` if the root part should be consumed
    Returns:
      the input stream for the root part
    Throws:
      `OMException`

  - ### getRootPartContentID

    public String getRootPartContentID()
    Get the content ID of the root part of the MIME message. This content ID is determined as follows:
    - If the content type of the MIME message has a `start` parameter, then the content ID will be extracted from that parameter.
    - Otherwise the content ID of the first MIME part of the MIME message is returned.
    Returns:
      the content ID of the root part (without the surrounding angle brackets)

  - ### getRootPartContentType

    public String getRootPartContentType()
    Get the content type of the root part of the MIME message. The root part is located as described in the documentation of the `getRootPartContentID()` method.
    Returns:
      the content type of the root part
    Throws:
      `OMException` - if the content type could not be determined

  - ### getIncomingAttachmentStreams

    public IncomingAttachmentStreams getIncomingAttachmentStreams() throws IllegalStateException
    Stream based access
    Returns:
      The stream container of type `IncomingAttachmentStreams`
    Throws:
      `IllegalStateException` - if application has alreadt started using Part's directly

  - ### getAllContentIDs

    public String[] getAllContentIDs()
    Get the content IDs of all MIME parts in the message. This includes the content ID of the SOAP part as well as the content IDs of the attachments. Note that if this object has been created from a stream, a call to this method will force reading of all MIME parts that have not been fetched from the stream yet.
    Returns:
      an array with the content IDs in order of appearance in the message

  - ### getContentIDSet

    public Set<String> getContentIDSet()
    Get the content IDs of all MIME parts in the message. This includes the content ID of the SOAP part as well as the content IDs of the attachments. Note that if this object has been created from a stream, a call to this method will force reading of all MIME parts that have not been fetched from the stream yet.
    Returns:
      the set of content IDs

  - ### getMap

    public Map<String,DataHandler> getMap()
    Get a map of all MIME parts in the message. This includes the SOAP part as well as the attachments. Note that if this object has been created from a stream, a call to this method will force reading of all MIME parts that have not been fetched from the stream yet.
    Returns:
      A map of all MIME parts in the message, with content IDs as keys and `DataHandler` objects as values.

  - ### getContentIDList

    public List<String> getContentIDList()
    Get the content IDs of the already loaded MIME parts in the message. This includes the content ID of the SOAP part as well as the content IDs of the attachments. If this object has been created from a stream, only the content IDs of the MIME parts that have already been fetched from the stream are returned. If this is not the desired behavior, `getAllContentIDs()` or `getContentIDSet()` should be used instead.
    Returns:
      List of content IDs in order of appearance in message

  - ### getContentLength

    public long getContentLength() throws IOException
    If the Attachments is backed by an InputStream, then this method returns the length of the message contents (Length of the entire message - Length of the Transport Headers)
    Returns:
      length of message content or -1 if Attachments is not backed by an InputStream
    Throws:
      `IOException`

  - ### getIncomingAttachmentsAsSingleStream

    public InputStream getIncomingAttachmentsAsSingleStream() throws IllegalStateException
    Deprecated.
    As of Axiom 1.2.13, this method is no longer supported.
    Throws:
      `IllegalStateException`

  - ### getMultipartBody

    public MultipartBody getMultipartBody()

  - ### getBlob

    public Blob getBlob(String contentID)
    Description copied from interface: `OMAttachmentAccessor`
    Get the content of the MIME part identified by a given content ID.
    Specified by:
      `getBlob` in interface `OMAttachmentAccessor`
    Parameters:
      `contentID` - the raw content ID (without the surrounding angle brackets and `cid:` prefix) of the MIME part
    Returns:
      the content of the MIME part referred by the content ID or `null` if the MIME part referred by the content ID does not exist