org.apache.axiom.attachments
Class Attachments

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

public class Attachments
extends java.lang.Object


Field Summary
(package private)  java.lang.String applicationType
          applicationType used to distinguish between MTOM & SWA If the message is MTOM optimised type is application/xop+xml If the message is SWA, type is ??have to find out
private  java.lang.String attachmentRepoDir
           
(package private)  java.util.TreeMap attachmentsMap
          attachmentsMap stores the Data Handlers of the already parsed Mime Body Parts.
(package private)  byte[] boundary
          Mime boundary which separates mime parts
(package private)  java.util.ArrayList cids
          cids stores the content ids in the order that the attachments occur in the message
(package private)  int contentLength
           
(package private)  javax.mail.internet.ContentType contentType
          ContentType of the MIME message
private  boolean endOfStreamReached
          endOfStreamReached flag which is to be set by MIMEBodyPartStream when MIME message terminator is found.
private  boolean fileCacheEnable
           
private  int fileStorageThreshold
           
private  java.lang.String firstPartId
           
protected static org.apache.commons.logging.Log log
           
private  LifecycleManager manager
           
private  boolean noStreams
          noStreams flag which is to be set when this class is instantiated by the SwA API to handle programatic added attachements.
(package private)  int partIndex
          partIndex- Number of Mime parts parsed
private  boolean partsRequested
          boolean Indicating if any data handlers have been directly requested
(package private)  int PUSHBACK_SIZE
           
(package private)  java.io.PushbackInputStream pushbackInStream
          pushbackInStream stores the reference to the incoming stream A PushbackStream has the ability to "push back" or "unread" one byte.
(package private)  IncomingAttachmentStreams streams
          Container to hold streams for direct access
private  boolean streamsRequested
          boolean Indicating if any streams have been directly requested
 
Constructor Summary
Attachments()
          Use this constructor when instantiating this to store the attachments set programatically through the SwA API.
Attachments(java.io.InputStream inStream, java.lang.String contentTypeString)
          Sets file cache to false.
Attachments(java.io.InputStream inStream, java.lang.String contentTypeString, boolean fileCacheEnable, java.lang.String attachmentRepoDir, java.lang.String fileThreshold)
          Moves the pointer to the beginning of the first MIME part.
Attachments(java.io.InputStream inStream, java.lang.String contentTypeString, boolean fileCacheEnable, java.lang.String attachmentRepoDir, java.lang.String fileThreshold, int contentLength)
          Moves the pointer to the beginning of the first MIME part.
Attachments(LifecycleManager manager, java.io.InputStream inStream, java.lang.String contentTypeString, boolean fileCacheEnable, java.lang.String attachmentRepoDir, java.lang.String fileThreshold)
          Moves the pointer to the beginning of the first MIME part.
Attachments(LifecycleManager manager, java.io.InputStream inStream, java.lang.String contentTypeString, boolean fileCacheEnable, java.lang.String attachmentRepoDir, java.lang.String fileThreshold, int contentLength)
          Moves the pointer to the beginning of the first MIME part.
 
Method Summary
 void addDataHandler(java.lang.String contentID, javax.activation.DataHandler dataHandler)
          Programatically adding an SOAP with Attachments(SwA) Attachment.
 java.lang.String[] getAllContentIDs()
           
 java.lang.String getAttachmentSpecType()
           
 java.util.List getContentIDList()
           
 java.util.Set getContentIDSet()
           
 javax.activation.DataHandler getDataHandler(java.lang.String blobContentID)
          Checks whether the MIME part is already parsed by checking the attachments HashMap.
 java.io.InputStream getIncomingAttachmentsAsSingleStream()
          Returns the rest of mime stream.
 IncomingAttachmentStreams getIncomingAttachmentStreams()
          Stream based access
 LifecycleManager getLifecycleManager()
           
private  javax.activation.DataHandler getNextPartDataHandler()
           
private  Part getPart()
           
 java.lang.String getSOAPPartContentID()
           
 java.lang.String getSOAPPartContentType()
           
 java.io.InputStream getSOAPPartInputStream()
           
private static int readToBuffer(java.io.InputStream is, byte[] buffer)
          Read bytes into the buffer until full or until the EOS
 void removeDataHandler(java.lang.String blobContentID)
          Removes the DataHandler corresponding to the given contenID.
protected  void setEndOfStream(boolean value)
          endOfStreamReached will be set to true if the message ended in MIME Style having "--" suffix with the last mime boundary
 void setLifecycleManager(LifecycleManager manager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentType

javax.mail.internet.ContentType contentType
ContentType of the MIME message


contentLength

int contentLength

boundary

byte[] boundary
Mime boundary which separates mime parts


applicationType

java.lang.String applicationType
applicationType used to distinguish between MTOM & SWA If the message is MTOM optimised type is application/xop+xml If the message is SWA, type is ??have to find out


pushbackInStream

java.io.PushbackInputStream pushbackInStream
pushbackInStream stores the reference to the incoming stream A PushbackStream has the ability to "push back" or "unread" one byte.


PUSHBACK_SIZE

int PUSHBACK_SIZE

attachmentsMap

java.util.TreeMap attachmentsMap
attachmentsMap stores the Data Handlers of the already parsed Mime Body Parts. This ordered Map is keyed using the content-ID's.


cids

java.util.ArrayList cids
cids stores the content ids in the order that the attachments occur in the message


partIndex

int partIndex
partIndex- Number of Mime parts parsed


streams

IncomingAttachmentStreams streams
Container to hold streams for direct access


streamsRequested

private boolean streamsRequested
boolean Indicating if any streams have been directly requested


partsRequested

private boolean partsRequested
boolean Indicating if any data handlers have been directly requested


endOfStreamReached

private boolean endOfStreamReached
endOfStreamReached flag which is to be set by MIMEBodyPartStream when MIME message terminator is found.


noStreams

private boolean noStreams
noStreams flag which is to be set when this class is instantiated by the SwA API to handle programatic added attachements. An InputStream with attachments is not present at that occation.


firstPartId

private java.lang.String firstPartId

fileCacheEnable

private boolean fileCacheEnable

attachmentRepoDir

private java.lang.String attachmentRepoDir

fileStorageThreshold

private int fileStorageThreshold

manager

private LifecycleManager manager

log

protected static org.apache.commons.logging.Log log
Constructor Detail

Attachments

public Attachments(LifecycleManager manager,
                   java.io.InputStream inStream,
                   java.lang.String contentTypeString,
                   boolean fileCacheEnable,
                   java.lang.String attachmentRepoDir,
                   java.lang.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,
                   java.io.InputStream inStream,
                   java.lang.String contentTypeString,
                   boolean fileCacheEnable,
                   java.lang.String attachmentRepoDir,
                   java.lang.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(java.io.InputStream inStream,
                   java.lang.String contentTypeString,
                   boolean fileCacheEnable,
                   java.lang.String attachmentRepoDir,
                   java.lang.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(java.io.InputStream inStream,
                   java.lang.String contentTypeString,
                   boolean fileCacheEnable,
                   java.lang.String attachmentRepoDir,
                   java.lang.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(java.io.InputStream inStream,
                   java.lang.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 Detail

getLifecycleManager

public LifecycleManager getLifecycleManager()

setLifecycleManager

public void setLifecycleManager(LifecycleManager manager)

getAttachmentSpecType

public java.lang.String getAttachmentSpecType()
Returns:
whether Message Type is SOAP with Attachments or MTOM optimized, by checking the application type parameter in the Content Type.

getDataHandler

public javax.activation.DataHandler getDataHandler(java.lang.String blobContentID)
Checks whether the MIME part is already parsed by checking the attachments HashMap. If it is not parsed yet then call the getNextPart() till the required part is found.

Parameters:
blobContentID - (without the surrounding angle brackets and "cid:" prefix)
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(java.lang.String contentID,
                           javax.activation.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(java.lang.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 java.io.InputStream getSOAPPartInputStream()
                                           throws OMException
Returns:
the InputStream which includes the SOAP Envelope. It assumes that the root mime part is always pointed by "start" parameter in content-type.
Throws:
OMException

getSOAPPartContentID

public java.lang.String getSOAPPartContentID()
Returns:
the Content-ID of the SOAP part It'll be the value Start Parameter of Content-Type header if given in the Content type of the MIME message. Else it'll be the content-id of the first MIME part of the MIME message

getSOAPPartContentType

public java.lang.String getSOAPPartContentType()

getIncomingAttachmentStreams

public IncomingAttachmentStreams getIncomingAttachmentStreams()
                                                       throws java.lang.IllegalStateException
Stream based access

Returns:
The stream container of type IncomingAttachmentStreams
Throws:
java.lang.IllegalStateException - if application has alreadt started using Part's directly

getAllContentIDs

public java.lang.String[] getAllContentIDs()

getContentIDSet

public java.util.Set getContentIDSet()

getContentIDList

public java.util.List getContentIDList()
Returns:
List of content ids in order of appearance in message

setEndOfStream

protected void setEndOfStream(boolean value)
endOfStreamReached will be set to true if the message ended in MIME Style having "--" suffix with the last mime boundary

Parameters:
value -

getIncomingAttachmentsAsSingleStream

public java.io.InputStream getIncomingAttachmentsAsSingleStream()
                                                         throws java.lang.IllegalStateException
Returns the rest of mime stream. It will contain all attachments without soappart (first attachment) with headers and mime boundary. Raw content!

Throws:
java.lang.IllegalStateException

getNextPartDataHandler

private javax.activation.DataHandler getNextPartDataHandler()
                                                     throws OMException
Returns:
the Next valid MIME part + store the Part in the Parts List
Throws:
OMException - throw if content id is null or if two MIME parts contain the same content-ID & the exceptions throws by getPart()

getPart

private Part getPart()
              throws OMException
Returns:
This will return the next available MIME part in the stream.
Throws:
OMException - if Stream ends while reading the next part...

readToBuffer

private static int readToBuffer(java.io.InputStream is,
                                byte[] buffer)
                         throws java.io.IOException
Read bytes into the buffer until full or until the EOS

Parameters:
is -
buffer -
Returns:
number of bytes read
Throws:
java.io.IOException