1 17 package org.apache.axis2.om.impl.llom.mtom; 18 19 import org.apache.axis2.attachments.MIMEHelper; 20 import org.apache.axis2.om.*; 21 import org.apache.axis2.om.impl.llom.OMTextImpl; 22 import org.apache.axis2.soap.SOAPFactory; 23 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import javax.activation.DataHandler ; 28 import javax.xml.stream.XMLStreamReader; 29 30 33 34 public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder { 35 private Log log = LogFactory.getLog(getClass()); 36 37 41 MIMEHelper mimeHelper; 42 43 int partIndex = 0; 44 45 public MTOMStAXSOAPModelBuilder(XMLStreamReader parser, 46 SOAPFactory factory, MIMEHelper mimeHelper) { 47 super(parser, factory); 48 this.mimeHelper = mimeHelper; 49 } 50 51 55 public MTOMStAXSOAPModelBuilder(XMLStreamReader reader, 56 MIMEHelper mimeHelper) { 57 super(reader); 58 this.mimeHelper = mimeHelper; 59 } 60 61 protected OMNode createOMElement() throws OMException { 62 63 String elementName = parser.getLocalName(); 64 65 String namespaceURI = parser.getNamespaceURI(); 66 67 if (elementName.equalsIgnoreCase("Include") 69 & namespaceURI 70 .equalsIgnoreCase("http://www.w3.org/2004/08/xop/include")) { 71 72 OMText node; 73 String contentID = null; 74 String contentIDName = null; 75 OMAttribute Attr; 76 if (lastNode == null) { 77 throw new OMException( 79 "XOP:Include element is not supported here"); 80 } 81 if (parser.getAttributeCount() > 0) { 82 contentID = parser.getAttributeValue(0); 83 contentID = contentID.trim(); 84 contentIDName = parser.getAttributeLocalName(0); 85 if (contentIDName.equalsIgnoreCase("href") 86 & contentID.substring(0, 3).equalsIgnoreCase("cid")) { 87 contentID = contentID.substring(4); 88 } else { 89 throw new OMException( 90 "contentID not Found in XOP:Include element"); 91 } 92 } else { 93 throw new OMException( 94 "Href attribute not found in XOP:Include element"); 95 } 96 97 OMElement e = (OMElement) lastNode; 105 node = new OMTextImpl(contentID, (OMElement) lastNode, this); 106 e.setFirstChild(node); 107 node.setComplete(true); 108 return node; 110 111 } else { 112 OMElement node; 113 if (lastNode == null) { 114 node = constructNode(null, elementName, true); 115 } else if (lastNode.isComplete()) { 116 node = constructNode((OMElement)lastNode.getParent(), elementName, false); 117 lastNode.setNextSibling(node); 118 node.setPreviousSibling(lastNode); 119 } else { 120 OMElement e = (OMElement) lastNode; 121 node = constructNode((OMElement) lastNode, elementName, false); 122 e.setFirstChild(node); 123 } 124 125 processAttributes(node); 127 return node; 131 } 132 } 133 134 public DataHandler getDataHandler(String blobContentID) throws OMException { 135 return mimeHelper.getDataHandler(blobContentID); 136 } 137 } 138 | Popular Tags |