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.ws.encoding; aoqi@0: aoqi@0: import com.sun.istack.internal.Nullable; aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: aoqi@0: /** aoqi@0: * @author Vivek Pandey aoqi@0: */ aoqi@0: public final class ContentTypeImpl implements com.sun.xml.internal.ws.api.pipe.ContentType { aoqi@0: private final @NotNull String contentType; aoqi@0: private final @NotNull String soapAction; aoqi@0: private String accept; aoqi@0: private final @Nullable String charset; aoqi@0: private String boundary; aoqi@0: private String boundaryParameter; aoqi@0: private String rootId; aoqi@0: private ContentType internalContentType; aoqi@0: aoqi@0: public ContentTypeImpl(String contentType) { aoqi@0: this(contentType, null, null); aoqi@0: } aoqi@0: aoqi@0: public ContentTypeImpl(String contentType, @Nullable String soapAction) { aoqi@0: this(contentType, soapAction, null); aoqi@0: } aoqi@0: aoqi@0: public ContentTypeImpl(String contentType, @Nullable String soapAction, @Nullable String accept) { aoqi@0: this(contentType, soapAction, accept, null); aoqi@0: } aoqi@0: aoqi@0: public ContentTypeImpl(String contentType, @Nullable String soapAction, @Nullable String accept, String charsetParam) { aoqi@0: this.contentType = contentType; aoqi@0: this.accept = accept; aoqi@0: this.soapAction = getQuotedSOAPAction(soapAction); aoqi@0: if (charsetParam == null) { aoqi@0: String tmpCharset = null; aoqi@0: try { aoqi@0: internalContentType = new ContentType(contentType); aoqi@0: tmpCharset = internalContentType.getParameter("charset"); aoqi@0: } catch(Exception e) { aoqi@0: //Ignore the parsing exception. aoqi@0: } aoqi@0: charset = tmpCharset; aoqi@0: } else { aoqi@0: charset = charsetParam; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns the character set encoding. aoqi@0: * aoqi@0: * @return returns the character set encoding. aoqi@0: */ aoqi@0: public @Nullable String getCharSet() { aoqi@0: return charset; aoqi@0: } aoqi@0: aoqi@0: /** BP 1.1 R1109 requires SOAPAction too be a quoted value **/ aoqi@0: private String getQuotedSOAPAction(String soapAction){ aoqi@0: if(soapAction == null || soapAction.length() == 0){ aoqi@0: return "\"\""; aoqi@0: }else if(soapAction.charAt(0) != '"' && soapAction.charAt(soapAction.length() -1) != '"'){ aoqi@0: //surround soapAction by double quotes for BP R1109 aoqi@0: return "\"" + soapAction + "\""; aoqi@0: }else{ aoqi@0: return soapAction; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getContentType() { aoqi@0: return contentType; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getSOAPActionHeader() { aoqi@0: return soapAction; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getAcceptHeader() { aoqi@0: return accept; aoqi@0: } aoqi@0: aoqi@0: public void setAcceptHeader(String accept) { aoqi@0: this.accept = accept; aoqi@0: } aoqi@0: aoqi@0: public String getBoundary() { aoqi@0: if (boundary == null) { aoqi@0: if (internalContentType == null) internalContentType = new ContentType(contentType); aoqi@0: boundary = internalContentType.getParameter("boundary"); aoqi@0: } aoqi@0: return boundary; aoqi@0: } aoqi@0: aoqi@0: public void setBoundary(String boundary) { aoqi@0: this.boundary = boundary; aoqi@0: } aoqi@0: aoqi@0: public String getBoundaryParameter() { aoqi@0: return boundaryParameter; aoqi@0: } aoqi@0: aoqi@0: public void setBoundaryParameter(String boundaryParameter) { aoqi@0: this.boundaryParameter = boundaryParameter; aoqi@0: } aoqi@0: aoqi@0: public String getRootId() { aoqi@0: if (rootId == null) { aoqi@0: if (internalContentType == null) internalContentType = new ContentType(contentType); aoqi@0: rootId = internalContentType.getParameter("start"); aoqi@0: } aoqi@0: return rootId; aoqi@0: } aoqi@0: aoqi@0: public void setRootId(String rootId) { aoqi@0: this.rootId = rootId; aoqi@0: } aoqi@0: aoqi@0: public static class Builder { aoqi@0: public String contentType; aoqi@0: public String soapAction; aoqi@0: public String accept; aoqi@0: public String charset; aoqi@0: public ContentTypeImpl build() { aoqi@0: return new ContentTypeImpl(contentType, soapAction, accept, charset); aoqi@0: } aoqi@0: } aoqi@0: }