aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.messaging.saaj.soap; aoqi@0: aoqi@0: import java.io.*; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.logging.Logger; aoqi@0: import java.util.logging.Level; aoqi@0: aoqi@0: import javax.activation.DataHandler; aoqi@0: import javax.activation.DataSource; aoqi@0: import javax.xml.soap.*; aoqi@0: import javax.xml.transform.Source; aoqi@0: import javax.xml.transform.stream.StreamSource; aoqi@0: aoqi@0: import org.w3c.dom.*; aoqi@0: aoqi@0: import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart; aoqi@0: aoqi@0: import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.util.*; aoqi@0: aoqi@0: import javax.xml.transform.dom.DOMSource; aoqi@0: import javax.xml.transform.sax.SAXSource; aoqi@0: aoqi@0: /** aoqi@0: * SOAPPartImpl is the first attachment. This contains the XML/SOAP document. aoqi@0: * aoqi@0: * @author Anil Vijendran (anil@sun.com) aoqi@0: */ aoqi@0: public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument { aoqi@0: protected static final Logger log = aoqi@0: Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, aoqi@0: "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); aoqi@0: aoqi@0: protected MimeHeaders headers; aoqi@0: protected Envelope envelope; aoqi@0: protected Source source; aoqi@0: protected SOAPDocumentImpl document; aoqi@0: aoqi@0: //flag to indicate if a setContent happened. aoqi@0: private boolean sourceWasSet = false; aoqi@0: aoqi@0: // Records whether the input source had an xml decl or not. aoqi@0: protected boolean omitXmlDecl = true; aoqi@0: aoqi@0: // Records the charset encoding of the input stream source if provided. aoqi@0: protected String sourceCharsetEncoding = null; aoqi@0: aoqi@0: /** aoqi@0: * Reference to containing message (may be null) aoqi@0: */ aoqi@0: protected MessageImpl message; aoqi@0: aoqi@0: static final boolean lazyContentLength; aoqi@0: static { aoqi@0: lazyContentLength = SAAJUtil.getSystemBoolean("saaj.lazy.contentlength"); aoqi@0: } aoqi@0: aoqi@0: protected SOAPPartImpl() { aoqi@0: this(null); aoqi@0: } aoqi@0: aoqi@0: protected SOAPPartImpl(MessageImpl message) { aoqi@0: document = new SOAPDocumentImpl(this); aoqi@0: headers = new MimeHeaders(); aoqi@0: this.message = message; aoqi@0: headers.setHeader("Content-Type", getContentType()); aoqi@0: } aoqi@0: aoqi@0: protected abstract String getContentType(); aoqi@0: protected abstract Envelope createEnvelopeFromSource() aoqi@0: throws SOAPException; aoqi@0: protected abstract Envelope createEmptyEnvelope(String prefix) aoqi@0: throws SOAPException; aoqi@0: protected abstract SOAPPartImpl duplicateType(); aoqi@0: aoqi@0: protected String getContentTypeString() { aoqi@0: return getContentType(); aoqi@0: } aoqi@0: aoqi@0: public boolean isFastInfoset() { aoqi@0: return (message != null) ? message.isFastInfoset() : false; aoqi@0: } aoqi@0: aoqi@0: public SOAPEnvelope getEnvelope() throws SOAPException { aoqi@0: aoqi@0: // If there is no SOAP envelope already created, then create aoqi@0: // one from a source if one exists. If there is a newer source aoqi@0: // then use that source. aoqi@0: aoqi@0: if (sourceWasSet) aoqi@0: sourceWasSet = false; aoqi@0: aoqi@0: lookForEnvelope(); aoqi@0: if (envelope != null) { aoqi@0: if (source != null) { // there's a newer source, use it aoqi@0: document.removeChild(envelope); aoqi@0: envelope = createEnvelopeFromSource(); aoqi@0: } aoqi@0: } else if (source != null) { aoqi@0: envelope = createEnvelopeFromSource(); aoqi@0: } else { aoqi@0: envelope = createEmptyEnvelope(null); aoqi@0: document.insertBefore(envelope, null); aoqi@0: } aoqi@0: return envelope; aoqi@0: } aoqi@0: aoqi@0: protected void lookForEnvelope() throws SOAPException { aoqi@0: Element envelopeChildElement = document.doGetDocumentElement(); aoqi@0: if (envelopeChildElement == null || envelopeChildElement instanceof Envelope) { aoqi@0: envelope = (EnvelopeImpl) envelopeChildElement; aoqi@0: } else if (!(envelopeChildElement instanceof ElementImpl)) { aoqi@0: log.severe("SAAJ0512.soap.incorrect.factory.used"); aoqi@0: throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction"); aoqi@0: } else { aoqi@0: ElementImpl soapElement = (ElementImpl) envelopeChildElement; aoqi@0: if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) { aoqi@0: String prefix = soapElement.getPrefix(); aoqi@0: String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix); aoqi@0: if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) { aoqi@0: log.severe("SAAJ0513.soap.unknown.ns"); aoqi@0: throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized"); aoqi@0: } aoqi@0: } else { aoqi@0: log.severe("SAAJ0514.soap.root.elem.not.named.envelope"); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "Unable to create envelope from given source because the root element is not named \"Envelope\""); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void removeAllMimeHeaders() { aoqi@0: headers.removeAllHeaders(); aoqi@0: } aoqi@0: aoqi@0: public void removeMimeHeader(String header) { aoqi@0: headers.removeHeader(header); aoqi@0: } aoqi@0: aoqi@0: public String[] getMimeHeader(String name) { aoqi@0: return headers.getHeader(name); aoqi@0: } aoqi@0: aoqi@0: public void setMimeHeader(String name, String value) { aoqi@0: headers.setHeader(name, value); aoqi@0: } aoqi@0: aoqi@0: public void addMimeHeader(String name, String value) { aoqi@0: headers.addHeader(name, value); aoqi@0: } aoqi@0: aoqi@0: public Iterator getAllMimeHeaders() { aoqi@0: return headers.getAllHeaders(); aoqi@0: } aoqi@0: aoqi@0: public Iterator getMatchingMimeHeaders(String[] names) { aoqi@0: return headers.getMatchingHeaders(names); aoqi@0: } aoqi@0: aoqi@0: public Iterator getNonMatchingMimeHeaders(String[] names) { aoqi@0: return headers.getNonMatchingHeaders(names); aoqi@0: } aoqi@0: aoqi@0: public Source getContent() throws SOAPException { aoqi@0: if (source != null) { aoqi@0: InputStream bis = null; aoqi@0: if (source instanceof JAXMStreamSource) { aoqi@0: StreamSource streamSource = (StreamSource)source; aoqi@0: bis = streamSource.getInputStream(); aoqi@0: } else if (FastInfosetReflection.isFastInfosetSource(source)) { aoqi@0: // FastInfosetSource inherits from SAXSource aoqi@0: SAXSource saxSource = (SAXSource)source; aoqi@0: bis = saxSource.getInputSource().getByteStream(); aoqi@0: } aoqi@0: aoqi@0: if (bis != null) { aoqi@0: try { aoqi@0: bis.reset(); aoqi@0: } catch (IOException e) { aoqi@0: /* This exception will never be thrown. aoqi@0: * aoqi@0: * The setContent method will modify the source aoqi@0: * if StreamSource to JAXMStreamSource, that uses aoqi@0: * a ByteInputStream, and for a FastInfosetSource will aoqi@0: * replace the InputStream with a ByteInputStream. aoqi@0: */ aoqi@0: } aoqi@0: } aoqi@0: return source; aoqi@0: } aoqi@0: aoqi@0: return ((Envelope) getEnvelope()).getContent(); aoqi@0: } aoqi@0: aoqi@0: public void setContent(Source source) throws SOAPException { aoqi@0: try { aoqi@0: if (source instanceof StreamSource) { aoqi@0: InputStream is = ((StreamSource) source).getInputStream(); aoqi@0: Reader rdr = ((StreamSource) source).getReader(); aoqi@0: aoqi@0: if (is != null) { aoqi@0: this.source = new JAXMStreamSource(is); aoqi@0: } else if (rdr != null) { aoqi@0: this.source = new JAXMStreamSource(rdr); aoqi@0: } else { aoqi@0: log.severe("SAAJ0544.soap.no.valid.reader.for.src"); aoqi@0: throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream"); aoqi@0: } aoqi@0: } aoqi@0: else if (FastInfosetReflection.isFastInfosetSource(source)) { aoqi@0: // InputStream is = source.getInputStream() aoqi@0: InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source); aoqi@0: aoqi@0: /* aoqi@0: * Underlying stream must be ByteInputStream for getContentAsStream(). We pay the aoqi@0: * cost of copying the underlying bytes here to avoid multiple copies every time aoqi@0: * getBytes() is called on a ByteInputStream. aoqi@0: */ aoqi@0: if (!(is instanceof ByteInputStream)) { aoqi@0: ByteOutputStream bout = new ByteOutputStream(); aoqi@0: bout.write(is); aoqi@0: aoqi@0: // source.setInputStream(new ByteInputStream(...)) aoqi@0: FastInfosetReflection.FastInfosetSource_setInputStream( aoqi@0: source, bout.newInputStream()); aoqi@0: } aoqi@0: this.source = source; aoqi@0: } aoqi@0: else { aoqi@0: this.source = source; aoqi@0: } aoqi@0: sourceWasSet = true; aoqi@0: } aoqi@0: catch (Exception ex) { aoqi@0: ex.printStackTrace(); aoqi@0: aoqi@0: log.severe("SAAJ0545.soap.cannot.set.src.for.part"); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "Error setting the source for SOAPPart: " + ex.getMessage()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public InputStream getContentAsStream() throws IOException { aoqi@0: if (source != null) { aoqi@0: InputStream is = null; aoqi@0: aoqi@0: // Allow message to be transcode if so requested aoqi@0: if (source instanceof StreamSource && !isFastInfoset()) { aoqi@0: is = ((StreamSource) source).getInputStream(); aoqi@0: } aoqi@0: else if (FastInfosetReflection.isFastInfosetSource(source) && aoqi@0: isFastInfoset()) aoqi@0: { aoqi@0: try { aoqi@0: // InputStream is = source.getInputStream() aoqi@0: is = FastInfosetReflection.FastInfosetSource_getInputStream(source); aoqi@0: } aoqi@0: catch (Exception e) { aoqi@0: throw new IOException(e.toString()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (is != null) { aoqi@0: if (lazyContentLength) { aoqi@0: return is; aoqi@0: } aoqi@0: if (!(is instanceof ByteInputStream)) { aoqi@0: log.severe("SAAJ0546.soap.stream.incorrect.type"); aoqi@0: throw new IOException("Internal error: stream not of the right type"); aoqi@0: } aoqi@0: return (ByteInputStream) is; aoqi@0: } aoqi@0: // need to do something here for reader... aoqi@0: // for now we'll see if we can fallback... aoqi@0: } aoqi@0: aoqi@0: ByteOutputStream b = new ByteOutputStream(); aoqi@0: aoqi@0: Envelope env = null; aoqi@0: aoqi@0: try { aoqi@0: env = (Envelope) getEnvelope(); aoqi@0: env.output(b, isFastInfoset()); aoqi@0: } aoqi@0: catch (SOAPException soapException) { aoqi@0: log.severe("SAAJ0547.soap.cannot.externalize"); aoqi@0: throw new SOAPIOException( aoqi@0: "SOAP exception while trying to externalize: ", aoqi@0: soapException); aoqi@0: } aoqi@0: aoqi@0: return b.newInputStream(); aoqi@0: } aoqi@0: aoqi@0: MimeBodyPart getMimePart() throws SOAPException { aoqi@0: try { aoqi@0: MimeBodyPart headerEnvelope = new MimeBodyPart(); aoqi@0: aoqi@0: headerEnvelope.setDataHandler(getDataHandler()); aoqi@0: AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope); aoqi@0: aoqi@0: return headerEnvelope; aoqi@0: } catch (SOAPException ex) { aoqi@0: throw ex; aoqi@0: } catch (Exception ex) { aoqi@0: log.severe("SAAJ0548.soap.cannot.externalize.hdr"); aoqi@0: throw new SOAPExceptionImpl("Unable to externalize header", ex); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: MimeHeaders getMimeHeaders() { aoqi@0: return headers; aoqi@0: } aoqi@0: aoqi@0: DataHandler getDataHandler() { aoqi@0: DataSource ds = new DataSource() { aoqi@0: public OutputStream getOutputStream() throws IOException { aoqi@0: throw new IOException("Illegal Operation"); aoqi@0: } aoqi@0: aoqi@0: public String getContentType() { aoqi@0: return getContentTypeString(); aoqi@0: } aoqi@0: aoqi@0: public String getName() { aoqi@0: return getContentId(); aoqi@0: } aoqi@0: aoqi@0: public InputStream getInputStream() throws IOException { aoqi@0: return getContentAsStream(); aoqi@0: } aoqi@0: }; aoqi@0: return new DataHandler(ds); aoqi@0: } aoqi@0: aoqi@0: public SOAPDocumentImpl getDocument() { aoqi@0: handleNewSource(); aoqi@0: return document; aoqi@0: } aoqi@0: aoqi@0: public SOAPPartImpl getSOAPPart() { aoqi@0: return this; aoqi@0: } aoqi@0: aoqi@0: public DocumentType getDoctype() { aoqi@0: return document.getDoctype(); aoqi@0: } aoqi@0: aoqi@0: // Forward all of these calls to the document to ensure that they work the aoqi@0: // same way whether they are called from here or directly from the document. aoqi@0: // If the document needs any help from this SOAPPart then aoqi@0: // Make it use a call-back as in doGetDocumentElement() below aoqi@0: public DOMImplementation getImplementation() { aoqi@0: return document.getImplementation(); aoqi@0: } aoqi@0: aoqi@0: public Element getDocumentElement() { aoqi@0: // If there is no SOAP envelope already created, then create aoqi@0: // one from a source if one exists. If there is a newer source aoqi@0: // then use that source. aoqi@0: try { aoqi@0: getEnvelope(); aoqi@0: } catch (SOAPException e) { aoqi@0: } aoqi@0: return document.getDocumentElement(); aoqi@0: } aoqi@0: aoqi@0: protected void doGetDocumentElement() { aoqi@0: handleNewSource(); aoqi@0: try { aoqi@0: lookForEnvelope(); aoqi@0: } catch (SOAPException e) { aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public Element createElement(String tagName) throws DOMException { aoqi@0: return document.createElement(tagName); aoqi@0: } aoqi@0: aoqi@0: public DocumentFragment createDocumentFragment() { aoqi@0: return document.createDocumentFragment(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Text createTextNode(String data) { aoqi@0: return document.createTextNode(data); aoqi@0: } aoqi@0: aoqi@0: public Comment createComment(String data) { aoqi@0: return document.createComment(data); aoqi@0: } aoqi@0: aoqi@0: public CDATASection createCDATASection(String data) throws DOMException { aoqi@0: return document.createCDATASection(data); aoqi@0: } aoqi@0: aoqi@0: public ProcessingInstruction createProcessingInstruction( aoqi@0: String target, aoqi@0: String data) aoqi@0: throws DOMException { aoqi@0: return document.createProcessingInstruction(target, data); aoqi@0: } aoqi@0: aoqi@0: public Attr createAttribute(String name) throws DOMException { aoqi@0: return document.createAttribute(name); aoqi@0: } aoqi@0: aoqi@0: public EntityReference createEntityReference(String name) aoqi@0: throws DOMException { aoqi@0: return document.createEntityReference(name); aoqi@0: } aoqi@0: aoqi@0: public NodeList getElementsByTagName(String tagname) { aoqi@0: handleNewSource(); aoqi@0: return document.getElementsByTagName(tagname); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node importNode( aoqi@0: org.w3c.dom.Node importedNode, aoqi@0: boolean deep) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.importNode(importedNode, deep); aoqi@0: } aoqi@0: aoqi@0: public Element createElementNS(String namespaceURI, String qualifiedName) aoqi@0: throws DOMException { aoqi@0: return document.createElementNS(namespaceURI, qualifiedName); aoqi@0: } aoqi@0: aoqi@0: public Attr createAttributeNS(String namespaceURI, String qualifiedName) aoqi@0: throws DOMException { aoqi@0: return document.createAttributeNS(namespaceURI, qualifiedName); aoqi@0: } aoqi@0: aoqi@0: public NodeList getElementsByTagNameNS( aoqi@0: String namespaceURI, aoqi@0: String localName) { aoqi@0: handleNewSource(); aoqi@0: return document.getElementsByTagNameNS(namespaceURI, localName); aoqi@0: } aoqi@0: aoqi@0: public Element getElementById(String elementId) { aoqi@0: handleNewSource(); aoqi@0: return document.getElementById(elementId); aoqi@0: } aoqi@0: public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.appendChild(newChild); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node cloneNode(boolean deep) { aoqi@0: handleNewSource(); aoqi@0: return document.cloneNode(deep); aoqi@0: } aoqi@0: aoqi@0: protected SOAPPartImpl doCloneNode() { aoqi@0: handleNewSource(); aoqi@0: SOAPPartImpl newSoapPart = duplicateType(); aoqi@0: aoqi@0: newSoapPart.headers = MimeHeadersUtil.copy(this.headers); aoqi@0: newSoapPart.source = this.source; aoqi@0: return newSoapPart; aoqi@0: } aoqi@0: aoqi@0: public NamedNodeMap getAttributes() { aoqi@0: return document.getAttributes(); aoqi@0: } aoqi@0: aoqi@0: public NodeList getChildNodes() { aoqi@0: handleNewSource(); aoqi@0: return document.getChildNodes(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node getFirstChild() { aoqi@0: handleNewSource(); aoqi@0: return document.getFirstChild(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node getLastChild() { aoqi@0: handleNewSource(); aoqi@0: return document.getLastChild(); aoqi@0: } aoqi@0: aoqi@0: public String getLocalName() { aoqi@0: return document.getLocalName(); aoqi@0: } aoqi@0: aoqi@0: public String getNamespaceURI() { aoqi@0: return document.getNamespaceURI(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node getNextSibling() { aoqi@0: handleNewSource(); aoqi@0: return document.getNextSibling(); aoqi@0: } aoqi@0: aoqi@0: public String getNodeName() { aoqi@0: return document.getNodeName(); aoqi@0: } aoqi@0: aoqi@0: public short getNodeType() { aoqi@0: return document.getNodeType(); aoqi@0: } aoqi@0: aoqi@0: public String getNodeValue() throws DOMException { aoqi@0: return document.getNodeValue(); aoqi@0: } aoqi@0: aoqi@0: public Document getOwnerDocument() { aoqi@0: return document.getOwnerDocument(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node getParentNode() { aoqi@0: return document.getParentNode(); aoqi@0: } aoqi@0: aoqi@0: public String getPrefix() { aoqi@0: return document.getPrefix(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node getPreviousSibling() { aoqi@0: return document.getPreviousSibling(); aoqi@0: } aoqi@0: aoqi@0: public boolean hasAttributes() { aoqi@0: return document.hasAttributes(); aoqi@0: } aoqi@0: aoqi@0: public boolean hasChildNodes() { aoqi@0: handleNewSource(); aoqi@0: return document.hasChildNodes(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node insertBefore( aoqi@0: org.w3c.dom.Node arg0, aoqi@0: org.w3c.dom.Node arg1) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.insertBefore(arg0, arg1); aoqi@0: } aoqi@0: aoqi@0: public boolean isSupported(String arg0, String arg1) { aoqi@0: return document.isSupported(arg0, arg1); aoqi@0: } aoqi@0: aoqi@0: public void normalize() { aoqi@0: handleNewSource(); aoqi@0: document.normalize(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.removeChild(arg0); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node replaceChild( aoqi@0: org.w3c.dom.Node arg0, aoqi@0: org.w3c.dom.Node arg1) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.replaceChild(arg0, arg1); aoqi@0: } aoqi@0: aoqi@0: public void setNodeValue(String arg0) throws DOMException { aoqi@0: document.setNodeValue(arg0); aoqi@0: } aoqi@0: aoqi@0: public void setPrefix(String arg0) throws DOMException { aoqi@0: document.setPrefix(arg0); aoqi@0: } aoqi@0: aoqi@0: private void handleNewSource() { aoqi@0: if (sourceWasSet) { aoqi@0: // There is a newer source use that source. aoqi@0: try { aoqi@0: getEnvelope(); aoqi@0: } catch (SOAPException e) { aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: protected XMLDeclarationParser lookForXmlDecl() throws SOAPException { aoqi@0: if ((source != null) && (source instanceof StreamSource)) { aoqi@0: aoqi@0: Reader reader = null; aoqi@0: aoqi@0: InputStream inputStream = ((StreamSource) source).getInputStream(); aoqi@0: if (inputStream != null) { aoqi@0: if (getSourceCharsetEncoding() == null) { aoqi@0: reader = new InputStreamReader(inputStream); aoqi@0: } else { aoqi@0: try { aoqi@0: reader = aoqi@0: new InputStreamReader( aoqi@0: inputStream, getSourceCharsetEncoding()); aoqi@0: } catch (UnsupportedEncodingException uee) { aoqi@0: log.log( aoqi@0: Level.SEVERE, aoqi@0: "SAAJ0551.soap.unsupported.encoding", aoqi@0: new Object[] {getSourceCharsetEncoding()}); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "Unsupported encoding " + getSourceCharsetEncoding(), aoqi@0: uee); aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: reader = ((StreamSource) source).getReader(); aoqi@0: } aoqi@0: if (reader != null) { aoqi@0: PushbackReader pushbackReader = aoqi@0: new PushbackReader(reader, 4096); //some size to unread aoqi@0: XMLDeclarationParser ev = aoqi@0: new XMLDeclarationParser(pushbackReader); aoqi@0: try { aoqi@0: ev.parse(); aoqi@0: } catch (Exception e) { aoqi@0: log.log( aoqi@0: Level.SEVERE, aoqi@0: "SAAJ0552.soap.xml.decl.parsing.failed"); aoqi@0: throw new SOAPExceptionImpl( aoqi@0: "XML declaration parsing failed", e); aoqi@0: } aoqi@0: String xmlDecl = ev.getXmlDeclaration(); aoqi@0: if ((xmlDecl != null) && (xmlDecl.length() > 0)) { aoqi@0: this.omitXmlDecl = false; aoqi@0: } aoqi@0: if (lazyContentLength) { aoqi@0: source = new StreamSource(pushbackReader); aoqi@0: } aoqi@0: return ev; aoqi@0: } aoqi@0: } else if ((source != null) && (source instanceof DOMSource)) { aoqi@0: //TODO: A Domsource maynot contain XMLDecl ?. aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void setSourceCharsetEncoding(String charset) { aoqi@0: this.sourceCharsetEncoding = charset; aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName) aoqi@0: throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.renameNode(n, namespaceURI, qualifiedName); aoqi@0: } aoqi@0: aoqi@0: public void normalizeDocument() { aoqi@0: document.normalizeDocument(); aoqi@0: } aoqi@0: aoqi@0: public DOMConfiguration getDomConfig() { aoqi@0: return document.getDomConfig(); aoqi@0: } aoqi@0: aoqi@0: public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException { aoqi@0: handleNewSource(); aoqi@0: return document.adoptNode(source); aoqi@0: } aoqi@0: aoqi@0: public void setDocumentURI(String documentURI) { aoqi@0: document.setDocumentURI(documentURI); aoqi@0: } aoqi@0: aoqi@0: public String getDocumentURI() { aoqi@0: return document.getDocumentURI(); aoqi@0: } aoqi@0: aoqi@0: public void setStrictErrorChecking(boolean strictErrorChecking) { aoqi@0: document.setStrictErrorChecking(strictErrorChecking); aoqi@0: } aoqi@0: aoqi@0: public String getInputEncoding() { aoqi@0: return document.getInputEncoding(); aoqi@0: } aoqi@0: aoqi@0: public String getXmlEncoding() { aoqi@0: return document.getXmlEncoding(); aoqi@0: } aoqi@0: aoqi@0: public boolean getXmlStandalone() { aoqi@0: return document.getXmlStandalone(); aoqi@0: } aoqi@0: aoqi@0: public void setXmlStandalone(boolean xmlStandalone) throws DOMException { aoqi@0: document.setXmlStandalone(xmlStandalone); aoqi@0: } aoqi@0: aoqi@0: public String getXmlVersion() { aoqi@0: return document.getXmlVersion(); aoqi@0: } aoqi@0: aoqi@0: public void setXmlVersion(String xmlVersion) throws DOMException { aoqi@0: document.setXmlVersion(xmlVersion); aoqi@0: } aoqi@0: aoqi@0: public boolean getStrictErrorChecking() { aoqi@0: return document.getStrictErrorChecking(); aoqi@0: } aoqi@0: aoqi@0: // DOM L3 methods from org.w3c.dom.Node aoqi@0: public String getBaseURI() { aoqi@0: return document.getBaseURI(); aoqi@0: } aoqi@0: aoqi@0: public short compareDocumentPosition(org.w3c.dom.Node other) aoqi@0: throws DOMException { aoqi@0: return document.compareDocumentPosition(other); aoqi@0: } aoqi@0: aoqi@0: public String getTextContent() aoqi@0: throws DOMException { aoqi@0: return document.getTextContent(); aoqi@0: } aoqi@0: aoqi@0: public void setTextContent(String textContent) throws DOMException { aoqi@0: document.setTextContent(textContent); aoqi@0: } aoqi@0: aoqi@0: public boolean isSameNode(org.w3c.dom.Node other) { aoqi@0: return document.isSameNode(other); aoqi@0: } aoqi@0: aoqi@0: public String lookupPrefix(String namespaceURI) { aoqi@0: return document.lookupPrefix(namespaceURI); aoqi@0: } aoqi@0: aoqi@0: public boolean isDefaultNamespace(String namespaceURI) { aoqi@0: return document.isDefaultNamespace(namespaceURI); aoqi@0: } aoqi@0: aoqi@0: public String lookupNamespaceURI(String prefix) { aoqi@0: return document.lookupNamespaceURI(prefix); aoqi@0: } aoqi@0: aoqi@0: public boolean isEqualNode(org.w3c.dom.Node arg) { aoqi@0: return document.isEqualNode(arg); aoqi@0: } aoqi@0: aoqi@0: public Object getFeature(String feature, aoqi@0: String version) { aoqi@0: return document.getFeature(feature,version); aoqi@0: } aoqi@0: aoqi@0: public Object setUserData(String key, aoqi@0: Object data, aoqi@0: UserDataHandler handler) { aoqi@0: return document.setUserData(key, data, handler); aoqi@0: } aoqi@0: aoqi@0: public Object getUserData(String key) { aoqi@0: return document.getUserData(key); aoqi@0: } aoqi@0: aoqi@0: public void recycleNode() { aoqi@0: // Nothing seems to be required to be done here aoqi@0: } aoqi@0: aoqi@0: public String getValue() { aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void setValue(String value) { aoqi@0: log.severe("SAAJ0571.soappart.setValue.not.defined"); aoqi@0: throw new IllegalStateException("Setting value of a soap part is not defined"); aoqi@0: } aoqi@0: aoqi@0: public void setParentElement(SOAPElement parent) throws SOAPException { aoqi@0: log.severe("SAAJ0570.soappart.parent.element.not.defined"); aoqi@0: throw new SOAPExceptionImpl("The parent element of a soap part is not defined"); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement getParentElement() { aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: public void detachNode() { aoqi@0: // Nothing seems to be required to be done here aoqi@0: } aoqi@0: aoqi@0: public String getSourceCharsetEncoding() { aoqi@0: return sourceCharsetEncoding; aoqi@0: } aoqi@0: }