org.ow2.petals.component.framework.api.util
Class MtomUtil

java.lang.Object
  extended by org.ow2.petals.component.framework.api.util.MtomUtil

public final class MtomUtil
extends Object

Contains utility to manipulate MTOM attachments

Author:
”Mathieu CARROLLE - mathieu.carrolle@petalslink.com”, Vincent Zurczak - EBM WebSourcing

Nested Class Summary
static class MtomUtil.MtomMapping
          A bean that describes a mapping of attachments associated with a Petals message.
 
Field Summary
static String MTOM_NSURI
          Include element namespace
static String NODE_ATTACHMENTS
          Element : "attachments"
 
Constructor Summary
MtomUtil()
           
 
Method Summary
static boolean compare(String attachmentElementValue, String attachmentName)
          Compares two strings, the first one being encoded as an URL and not the second.
static String convertQNameToString(QName qname)
          Return a string representation of the given QName.
static Element extractAttachmentRootElement(Document inputDocument)
          Deprecated. useless method
static Set<String> extractAttachmentsIdFromPayload(Element attachmentRootElement)
          In the message payload, extract the identifier(cid) associated with each xop:Include element.
static DocumentFragment generateMtomStructure(Document document, List<String> contentIds, QName element)
          Build the xml structure according to xop standard.
static Node generateMtomStructure(Document document, List<String> contentIds, QName rootNode, QName customNode)
          Build the xml structure according to xop standard.
static Node generateMtomXopElement(Document doc, String contentId)
          Generate an Include element according to xop standard.
static Map<String,DataHandler> getAttachments(Document inputDocument, javax.jbi.messaging.NormalizedMessage nmMessage)
          Deprecated. use getMtomMapping(Exchange exchange, Element element)
static MtomUtil.MtomMapping getMtomMapping(Exchange exchange, Element element)
          Builds a MTOM mapping from both an exchange and a root element.
static String getNodeName(Node node)
          Return the node name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MTOM_NSURI

public static final String MTOM_NSURI
Include element namespace

See Also:
Constant Field Values

NODE_ATTACHMENTS

public static final String NODE_ATTACHMENTS
Element : "attachments"

See Also:
Constant Field Values
Constructor Detail

MtomUtil

public MtomUtil()
Method Detail

compare

public static boolean compare(String attachmentElementValue,
                              String attachmentName)
Compares two strings, the first one being encoded as an URL and not the second.

This method is used to compare attachment names.

Parameters:
attachmentElementValue - the value of the MTOM attachment, as referenced in the href attribute
attachmentName - the attachment name, as specified in the exchange
Returns:
true if the arguments are the same (despite the encoding), false otherwise
Throws:
UnsupportedEncodingException

convertQNameToString

public static final String convertQNameToString(QName qname)
Return a string representation of the given QName. Name with prefix is returned if the given QName contains prefix otherwise return just the localpart.

Parameters:
qname -
Returns:
prefix:localpart or localpart

extractAttachmentRootElement

@Deprecated
public static Element extractAttachmentRootElement(Document inputDocument)
                                            throws javax.jbi.messaging.MessagingException
Deprecated. useless method

Extract element containing xop element.

Parameters:
inputDocument - Input xml message.
Returns:
The xml element "attachments".
Throws:
javax.jbi.messaging.MessagingException

extractAttachmentsIdFromPayload

public static Set<String> extractAttachmentsIdFromPayload(Element attachmentRootElement)
In the message payload, extract the identifier(cid) associated with each xop:Include element.
Document need to be namespaceaware.

Parameters:
inputDocument - Input xml message.
exchange -
Returns:
List of all cid found in the message

generateMtomStructure

public static DocumentFragment generateMtomStructure(Document document,
                                                     List<String> contentIds,
                                                     QName element)
Build the xml structure according to xop standard.

Parameters:
document - Document used to create node.
contentIds - List of attachment id.
element - QName representing the element that encapsulate the xop:Include element.
Returns:
Return an xml structure according to xop standard.
Exemple :
<tns:file>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:MyAttachmentId1"/>
</tns:file>
<tns:file>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:MyAttachmentId2"/>
</tns:file>

generateMtomStructure

public static Node generateMtomStructure(Document document,
                                         List<String> contentIds,
                                         QName rootNode,
                                         QName customNode)
Build the xml structure according to xop standard.

Parameters:
document - Document used to create node.
contentIds - List of attachment id.
rootNode - QName representing the root element.
customNode - QName representing an additional xml element parent to include for each xop:Include element
Returns:
Return an xml structure according to xop standard.
Exemple
<tns:rootNode>
<tns:customNode>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:MyAttachmentId1" />
</tns:customNode>
<tns:customNode>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:MyAttachmentId2" />
</tns:customNode>
</tns:rootNode>

generateMtomXopElement

public static Node generateMtomXopElement(Document doc,
                                          String contentId)
Generate an Include element according to xop standard.
Example : <xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:MYCONTENTID'/>

Parameters:
doc - Document used to create node.
contentId - attachment ID
Returns:

getAttachments

@Deprecated
public static Map<String,DataHandler> getAttachments(Document inputDocument,
                                                                javax.jbi.messaging.NormalizedMessage nmMessage)
                                              throws javax.jbi.messaging.MessagingException
Deprecated. use getMtomMapping(Exchange exchange, Element element)

Return all attachments by using Xml-binary Optimized Packaging (XOP) standard. All xop:Include element need to be child of an elements named attachments.

Parameters:
inputDocument -
exchange -
Returns:
Throws:
javax.jbi.messaging.MessagingException

getMtomMapping

public static MtomUtil.MtomMapping getMtomMapping(Exchange exchange,
                                                  Element element)
                                           throws javax.jbi.messaging.MessagingException
Builds a MTOM mapping from both an exchange and a root element.

Parameters:
exchange - the message exchange
element - the element from which MTOM elements must be searched.

MTOM elements are elements associated with the name space http://www.w3.org/2004/08/xop/include.
If null, the root element of the pay-load is taken.
If you already have extracted the pay-load as a document, you can use Document#getDocumentElement().

Returns:
null if the element is null and could not be built, a MtomUtil.MtomMapping instance otherwise
Throws:
javax.jbi.messaging.MessagingException - if something went wrong while acquiring the message content

getNodeName

public static String getNodeName(Node node)
Return the node name

Parameters:
node -
Returns:
the name of the XML node (with no name space element)


Copyright © 2005-2012 Petals Link (EBM Websourcing). All Rights Reserved.