Class AttachmentPart
- All Implemented Interfaces:
Serializable
,Part
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBulds a newAttachmentPart
.Bulds a newAttachmentPart
with aDataHandler
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMimeHeader
(String header, String value) Add the specified MIME header, as per JAXM.void
Clears out the content of thisAttachmentPart
object.void
Detach the attachment file from this class, so it is not cleaned up.void
dispose()
when an attachment part is disposed, any associated files are deleted, and the datahandler itself nulled.protected void
finalize()
On death, we clean up our file.Get the data handler.Retrieves all the headers for thisAttachmentPart
object as an iterator over theMimeHeader
objects.Get the filename of this attachment.Gets the content of thisAttachmentPart
object as a Java object.Gets the value of the MIME header whose name is "Content-Id".Content ID.Gets the value of the MIME header "Content-Location".getContentTypeGets theDataHandler
object for thisAttachmentPart
object.getFirstMimeHeader
(String header) Get the specified MIME header.getMatchingMimeHeaders
(String[] match) Retrieves allMimeHeader
objects that match a name in the given array.String[]
getMimeHeader
(String name) Gets all the values of the header identified by the givenString
.getNonMatchingMimeHeaders
(String[] match) Retrieves allMimeHeader
objects whose name does not match a name in the given array.int
getSize()
Returns the number of bytes in thisAttachmentPart
object.boolean
matches
(MimeHeaders headers) check if this Part's mimeheaders matches the one passed in.void
Removes all the MIME header entries.void
removeMimeHeader
(String header) Removes all MIME headers that match the given name.protected void
setAttachmentFile
(String path) Set the filename of this attachment part.void
setContent
(Object object, String contentType) Sets the content of this attachment part to that of the givenObject
and sets the value of theContent-Type
header to the given type.void
setContentId
(String newCid) Sets the MIME header "Content-Id" with the given value.void
setContentLocation
(String loc) Sets the MIME header "Content-Location" with the given value.void
setDataHandler
(DataHandler datahandler) Sets the givenDataHandler
object as the data handler for thisAttachmentPart
object.void
setMimeHeader
(String name, String value) Changes the first header entry that matches the given name to the given value, adding a new header if no existing header matches.Methods inherited from class javax.xml.soap.AttachmentPart
setContentType
-
Field Details
-
log
protected static org.apache.commons.logging.Log logField log
-
-
Constructor Details
-
AttachmentPart
public AttachmentPart()Bulds a newAttachmentPart
. -
AttachmentPart
Bulds a newAttachmentPart
with aDataHandler
.- Parameters:
dh
- theDataHandler
-
-
Method Details
-
finalize
On death, we clean up our file. -
getActivationDataHandler
Get the data handler.- Returns:
- the activation
DataHandler
-
getContentType
getContentType- Specified by:
getContentType
in interfacePart
- Overrides:
getContentType
in classAttachmentPart
- Returns:
- content type
-
addMimeHeader
Add the specified MIME header, as per JAXM.- Specified by:
addMimeHeader
in interfacePart
- Specified by:
addMimeHeader
in classAttachmentPart
- Parameters:
header
-value
-
-
getFirstMimeHeader
Get the specified MIME header.- Parameters:
header
-- Returns:
-
matches
check if this Part's mimeheaders matches the one passed in. TODO: Am not sure about the logic.- Parameters:
headers
- theMimeHeaders
to check- Returns:
- true if all header name, values in
headers
are found, false otherwise
-
getContentLocation
Description copied from class:AttachmentPart
Gets the value of the MIME header "Content-Location".- Specified by:
getContentLocation
in interfacePart
- Overrides:
getContentLocation
in classAttachmentPart
- Returns:
- a
String
giving the value of the "Content-Location" header ornull
if there is none
-
setContentLocation
Description copied from class:AttachmentPart
Sets the MIME header "Content-Location" with the given value.- Specified by:
setContentLocation
in interfacePart
- Overrides:
setContentLocation
in classAttachmentPart
- Parameters:
loc
- aString
giving the value of the "Content-Location" header
-
setContentId
Description copied from class:AttachmentPart
Sets the MIME header "Content-Id" with the given value.- Specified by:
setContentId
in interfacePart
- Overrides:
setContentId
in classAttachmentPart
- Parameters:
newCid
- aString
giving the value of the "Content-Id" header- See Also:
-
getContentId
Description copied from class:AttachmentPart
Gets the value of the MIME header whose name is "Content-Id".- Specified by:
getContentId
in interfacePart
- Overrides:
getContentId
in classAttachmentPart
- Returns:
- a
String
giving the value of the "Content-Id" header ornull
if there is none - See Also:
-
getMatchingMimeHeaders
Description copied from class:AttachmentPart
Retrieves allMimeHeader
objects that match a name in the given array.- Specified by:
getMatchingMimeHeaders
in interfacePart
- Specified by:
getMatchingMimeHeaders
in classAttachmentPart
- Parameters:
match
- aString
array with the name(s) of the MIME headers to be returned- Returns:
- all of the MIME headers that match one of the names
in the given array as an
Iterator
object
-
getNonMatchingMimeHeaders
Description copied from class:AttachmentPart
Retrieves allMimeHeader
objects whose name does not match a name in the given array.- Specified by:
getNonMatchingMimeHeaders
in interfacePart
- Specified by:
getNonMatchingMimeHeaders
in classAttachmentPart
- Parameters:
match
- aString
array with the name(s) of the MIME headers not to be returned- Returns:
- all of the MIME headers in this
AttachmentPart
object except those that match one of the names in the given array. The nonmatching MIME headers are returned as anIterator
object.
-
getAllMimeHeaders
Description copied from class:AttachmentPart
Retrieves all the headers for thisAttachmentPart
object as an iterator over theMimeHeader
objects.- Specified by:
getAllMimeHeaders
in classAttachmentPart
- Returns:
- an
Iterator
object with all of the Mime headers for thisAttachmentPart
object
-
setMimeHeader
Changes the first header entry that matches the given name to the given value, adding a new header if no existing header matches. This method also removes all matching headers but the first.Note that RFC822 headers can only contain US-ASCII characters.
- Specified by:
setMimeHeader
in classAttachmentPart
- Parameters:
name
- aString
giving the name of the header for which to searchvalue
- aString
giving the value to be set for the header whose name matches the given name- Throws:
IllegalArgumentException
- if there was a problem with the specified mime header name or value
-
removeAllMimeHeaders
public void removeAllMimeHeaders()Removes all the MIME header entries.- Specified by:
removeAllMimeHeaders
in classAttachmentPart
-
removeMimeHeader
Removes all MIME headers that match the given name.- Specified by:
removeMimeHeader
in classAttachmentPart
- Parameters:
header
- - the string name of the MIME header/s to be removed
-
getDataHandler
Gets theDataHandler
object for thisAttachmentPart
object.- Specified by:
getDataHandler
in classAttachmentPart
- Returns:
- the
DataHandler
object associated with thisAttachmentPart
object - Throws:
SOAPException
- if there is no data in thisAttachmentPart
object
-
setDataHandler
Sets the givenDataHandler
object as the data handler for thisAttachmentPart
object. Typically, on an incoming message, the data handler is automatically set. When a message is being created and populated with content, thesetDataHandler
method can be used to get data from various data sources into the message.- Specified by:
setDataHandler
in classAttachmentPart
- Parameters:
datahandler
-DataHandler
object to be set- Throws:
IllegalArgumentException
- if there was a problem with the specifiedDataHandler
object
-
getContent
Gets the content of thisAttachmentPart
object as a Java object. The type of the returned Java object depends on (1) theDataContentHandler
object that is used to interpret the bytes and (2) theContent-Type
given in the header.For the MIME content types "text/plain", "text/html" and "text/xml", the
DataContentHandler
object does the conversions to and from the Java types corresponding to the MIME types. For other MIME types,theDataContentHandler
object can return anInputStream
object that contains the content data as raw bytes.A JAXM-compliant implementation must, as a minimum, return a
java.lang.String
object corresponding to any content stream with aContent-Type
value oftext/plain
and ajavax.xml.transform.StreamSource
object corresponding to a content stream with aContent-Type
value oftext/xml
. For those content types that an installedDataContentHandler
object does not understand, theDataContentHandler
object is required to return ajava.io.InputStream
object with the raw bytes.- Specified by:
getContent
in classAttachmentPart
- Returns:
- a Java object with the content of this
AttachmentPart
object - Throws:
SOAPException
- if there is no content set into thisAttachmentPart
object or if there was a data transformation error
-
setContent
Sets the content of this attachment part to that of the givenObject
and sets the value of theContent-Type
header to the given type. The type of theObject
should correspond to the value given for theContent-Type
. This depends on the particular set ofDataContentHandler
objects in use.- Specified by:
setContent
in classAttachmentPart
- Parameters:
object
- the Java object that makes up the content for this attachment partcontentType
- the MIME string that specifies the type of the content- Throws:
IllegalArgumentException
- if the contentType does not match the type of the content object, or if there was noDataContentHandler
object for this content object- See Also:
-
clearContent
public void clearContent()Clears out the content of thisAttachmentPart
object. The MIME header portion is left untouched.- Specified by:
clearContent
in classAttachmentPart
-
getSize
Returns the number of bytes in thisAttachmentPart
object.- Specified by:
getSize
in classAttachmentPart
- Returns:
- the size of this
AttachmentPart
object in bytes or -1 if the size cannot be determined - Throws:
SOAPException
- if the content of this attachment is corrupted of if there was an exception while trying to determine the size.
-
getMimeHeader
Gets all the values of the header identified by the givenString
.- Specified by:
getMimeHeader
in interfacePart
- Specified by:
getMimeHeader
in classAttachmentPart
- Parameters:
name
- the name of the header; example: "Content-Type"- Returns:
- a
String
array giving the value for the specified header - See Also:
-
getContentIdRef
Content ID.- Specified by:
getContentIdRef
in interfacePart
- Returns:
- the contentId reference value that should be used directly as an href in a SOAP element to reference this attachment. Not part of JAX-RPC, JAX-M, SAAJ, etc.
-
setAttachmentFile
Set the filename of this attachment part.- Parameters:
path
- the new file path
-
detachAttachmentFile
public void detachAttachmentFile()Detach the attachment file from this class, so it is not cleaned up. This has the side-effect of making subsequent calls to getAttachmentFile() returnnull
. -
getAttachmentFile
Get the filename of this attachment.- Returns:
- the filename or null for an uncached file
-
dispose
public void dispose()when an attachment part is disposed, any associated files are deleted, and the datahandler itself nulled. The object is no longer completely usable, at this point
-