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