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: /* aoqi@0: * @(#)ContentType.java 1.7 02/03/27 aoqi@0: */ aoqi@0: aoqi@0: aoqi@0: aoqi@0: package com.sun.xml.internal.ws.encoding; aoqi@0: aoqi@0: import javax.xml.ws.WebServiceException; aoqi@0: aoqi@0: /** aoqi@0: * This class represents a MIME ContentType value. It provides aoqi@0: * methods to parse a ContentType string into individual components aoqi@0: * and to generate a MIME style ContentType string. aoqi@0: * aoqi@0: * @version 1.7, 02/03/27 aoqi@0: * @author John Mani aoqi@0: */ aoqi@0: public final class ContentType { aoqi@0: aoqi@0: private String primaryType; // primary type aoqi@0: private String subType; // subtype aoqi@0: private ParameterList list; // parameter list aoqi@0: aoqi@0: /** aoqi@0: * Constructor that takes a Content-Type string. The String aoqi@0: * is parsed into its constituents: primaryType, subType aoqi@0: * and parameters. A ParseException is thrown if the parse fails. aoqi@0: * aoqi@0: * @param s the Content-Type string. aoqi@0: * @exception WebServiceException if the parse fails. aoqi@0: */ aoqi@0: public ContentType(String s) throws WebServiceException { aoqi@0: HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME); aoqi@0: HeaderTokenizer.Token tk; aoqi@0: aoqi@0: // First "type" .. aoqi@0: tk = h.next(); aoqi@0: if (tk.getType() != HeaderTokenizer.Token.ATOM) aoqi@0: throw new WebServiceException(); aoqi@0: primaryType = tk.getValue(); aoqi@0: aoqi@0: // The '/' separator .. aoqi@0: tk = h.next(); aoqi@0: if ((char)tk.getType() != '/') aoqi@0: throw new WebServiceException(); aoqi@0: aoqi@0: // Then "subType" .. aoqi@0: tk = h.next(); aoqi@0: if (tk.getType() != HeaderTokenizer.Token.ATOM) aoqi@0: throw new WebServiceException(); aoqi@0: subType = tk.getValue(); aoqi@0: aoqi@0: // Finally parameters .. aoqi@0: String rem = h.getRemainder(); aoqi@0: if (rem != null) aoqi@0: list = new ParameterList(rem); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Return the primary type. aoqi@0: * @return the primary type aoqi@0: */ aoqi@0: public String getPrimaryType() { aoqi@0: return primaryType; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the subType. aoqi@0: * @return the subType aoqi@0: */ aoqi@0: public String getSubType() { aoqi@0: return subType; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the MIME type string, without the parameters. aoqi@0: * The returned value is basically the concatenation of aoqi@0: * the primaryType, the '/' character and the secondaryType. aoqi@0: * aoqi@0: * @return the type aoqi@0: */ aoqi@0: public String getBaseType() { aoqi@0: return primaryType + '/' + subType; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the specified parameter value. Returns null aoqi@0: * if this parameter is absent. aoqi@0: * aoqi@0: * @param name parameter name aoqi@0: * @return parameter value aoqi@0: */ aoqi@0: public String getParameter(String name) { aoqi@0: if (list == null) aoqi@0: return null; aoqi@0: aoqi@0: return list.get(name); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return a ParameterList object that holds all the available aoqi@0: * parameters. Returns null if no parameters are available. aoqi@0: * aoqi@0: * @return ParameterList aoqi@0: */ aoqi@0: public ParameterList getParameterList() { aoqi@0: return list; aoqi@0: } aoqi@0: aoqi@0: }