Class AttachmentPart
- java.lang.Object
-
- javax.xml.soap.AttachmentPart
-
- org.apache.axis.attachments.AttachmentPart
-
- All Implemented Interfaces:
java.io.Serializable
,Part
public class AttachmentPart extends AttachmentPart implements Part
An attachment part.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Log
log
Field log
-
Constructor Summary
Constructors Constructor Description AttachmentPart()
Bulds a newAttachmentPart
.AttachmentPart(javax.activation.DataHandler dh)
Bulds a newAttachmentPart
with aDataHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMimeHeader(java.lang.String header, java.lang.String value)
Add the specified MIME header, as per JAXM.void
clearContent()
Clears out the content of thisAttachmentPart
object.void
detachAttachmentFile()
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.javax.activation.DataHandler
getActivationDataHandler()
Get the data handler.java.util.Iterator
getAllMimeHeaders()
Retrieves all the headers for thisAttachmentPart
object as an iterator over theMimeHeader
objects.java.lang.String
getAttachmentFile()
Get the filename of this attachment.java.lang.Object
getContent()
Gets the content of thisAttachmentPart
object as a Java object.java.lang.String
getContentId()
Gets the value of the MIME header whose name is "Content-Id".java.lang.String
getContentIdRef()
Content ID.java.lang.String
getContentLocation()
Gets the value of the MIME header "Content-Location".java.lang.String
getContentType()
getContentTypejavax.activation.DataHandler
getDataHandler()
Gets theDataHandler
object for thisAttachmentPart
object.java.lang.String
getFirstMimeHeader(java.lang.String header)
Get the specified MIME header.java.util.Iterator
getMatchingMimeHeaders(java.lang.String[] match)
Retrieves allMimeHeader
objects that match a name in the given array.java.lang.String[]
getMimeHeader(java.lang.String name)
Gets all the values of the header identified by the givenString
.java.util.Iterator
getNonMatchingMimeHeaders(java.lang.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
removeAllMimeHeaders()
Removes all the MIME header entries.void
removeMimeHeader(java.lang.String header)
Removes all MIME headers that match the given name.protected void
setAttachmentFile(java.lang.String path)
Set the filename of this attachment part.void
setContent(java.lang.Object object, java.lang.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(java.lang.String newCid)
Sets the MIME header "Content-Id" with the given value.void
setContentLocation(java.lang.String loc)
Sets the MIME header "Content-Location" with the given value.void
setDataHandler(javax.activation.DataHandler datahandler)
Sets the givenDataHandler
object as the data handler for thisAttachmentPart
object.void
setMimeHeader(java.lang.String name, java.lang.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
-
-
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.Throwable
On death, we clean up our file.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
- if anything went wrong during finalization
-
getActivationDataHandler
public javax.activation.DataHandler getActivationDataHandler()
Get the data handler.- Returns:
- the activation
DataHandler
-
getContentType
public java.lang.String getContentType()
getContentType- Specified by:
getContentType
in interfacePart
- Overrides:
getContentType
in classAttachmentPart
- Returns:
- content type
-
addMimeHeader
public void addMimeHeader(java.lang.String header, java.lang.String value)
Add the specified MIME header, as per JAXM.- Specified by:
addMimeHeader
in interfacePart
- Specified by:
addMimeHeader
in classAttachmentPart
- Parameters:
header
-value
-
-
getFirstMimeHeader
public java.lang.String getFirstMimeHeader(java.lang.String header)
Get the specified MIME header.- Parameters:
header
-- Returns:
-
matches
public boolean matches(MimeHeaders headers)
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
public java.lang.String 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
public void setContentLocation(java.lang.String loc)
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
public void setContentId(java.lang.String newCid)
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()
-
getContentId
public java.lang.String 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:
setContentId(java.lang.String)
-
getMatchingMimeHeaders
public java.util.Iterator getMatchingMimeHeaders(java.lang.String[] match)
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
public java.util.Iterator getNonMatchingMimeHeaders(java.lang.String[] match)
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
public java.util.Iterator 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
public void setMimeHeader(java.lang.String name, java.lang.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. 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:
java.lang.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
public void removeMimeHeader(java.lang.String header)
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
public javax.activation.DataHandler getDataHandler() throws SOAPException
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
public void setDataHandler(javax.activation.DataHandler datahandler)
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:
java.lang.IllegalArgumentException
- if there was a problem with the specifiedDataHandler
object
-
getContent
public java.lang.Object getContent() throws SOAPException
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
public void setContent(java.lang.Object object, java.lang.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. 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:
java.lang.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:
getContent()
-
clearContent
public void clearContent()
Clears out the content of thisAttachmentPart
object. The MIME header portion is left untouched.- Specified by:
clearContent
in classAttachmentPart
-
getSize
public int getSize() throws SOAPException
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
public java.lang.String[] getMimeHeader(java.lang.String name)
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:
setMimeHeader(java.lang.String, java.lang.String)
-
getContentIdRef
public java.lang.String 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
protected void setAttachmentFile(java.lang.String path)
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
public java.lang.String 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
-
-