src/share/jaxws_classes/com/sun/xml/internal/ws/encoding/ContentType.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 /*
aoqi@0 27 * @(#)ContentType.java 1.7 02/03/27
aoqi@0 28 */
aoqi@0 29
aoqi@0 30
aoqi@0 31
aoqi@0 32 package com.sun.xml.internal.ws.encoding;
aoqi@0 33
aoqi@0 34 import javax.xml.ws.WebServiceException;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * This class represents a MIME ContentType value. It provides
aoqi@0 38 * methods to parse a ContentType string into individual components
aoqi@0 39 * and to generate a MIME style ContentType string.
aoqi@0 40 *
aoqi@0 41 * @version 1.7, 02/03/27
aoqi@0 42 * @author John Mani
aoqi@0 43 */
aoqi@0 44 public final class ContentType {
aoqi@0 45
aoqi@0 46 private String primaryType; // primary type
aoqi@0 47 private String subType; // subtype
aoqi@0 48 private ParameterList list; // parameter list
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * Constructor that takes a Content-Type string. The String
aoqi@0 52 * is parsed into its constituents: primaryType, subType
aoqi@0 53 * and parameters. A ParseException is thrown if the parse fails.
aoqi@0 54 *
aoqi@0 55 * @param s the Content-Type string.
aoqi@0 56 * @exception WebServiceException if the parse fails.
aoqi@0 57 */
aoqi@0 58 public ContentType(String s) throws WebServiceException {
aoqi@0 59 HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
aoqi@0 60 HeaderTokenizer.Token tk;
aoqi@0 61
aoqi@0 62 // First "type" ..
aoqi@0 63 tk = h.next();
aoqi@0 64 if (tk.getType() != HeaderTokenizer.Token.ATOM)
aoqi@0 65 throw new WebServiceException();
aoqi@0 66 primaryType = tk.getValue();
aoqi@0 67
aoqi@0 68 // The '/' separator ..
aoqi@0 69 tk = h.next();
aoqi@0 70 if ((char)tk.getType() != '/')
aoqi@0 71 throw new WebServiceException();
aoqi@0 72
aoqi@0 73 // Then "subType" ..
aoqi@0 74 tk = h.next();
aoqi@0 75 if (tk.getType() != HeaderTokenizer.Token.ATOM)
aoqi@0 76 throw new WebServiceException();
aoqi@0 77 subType = tk.getValue();
aoqi@0 78
aoqi@0 79 // Finally parameters ..
aoqi@0 80 String rem = h.getRemainder();
aoqi@0 81 if (rem != null)
aoqi@0 82 list = new ParameterList(rem);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85
aoqi@0 86 /**
aoqi@0 87 * Return the primary type.
aoqi@0 88 * @return the primary type
aoqi@0 89 */
aoqi@0 90 public String getPrimaryType() {
aoqi@0 91 return primaryType;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 /**
aoqi@0 95 * Return the subType.
aoqi@0 96 * @return the subType
aoqi@0 97 */
aoqi@0 98 public String getSubType() {
aoqi@0 99 return subType;
aoqi@0 100 }
aoqi@0 101
aoqi@0 102 /**
aoqi@0 103 * Return the MIME type string, without the parameters.
aoqi@0 104 * The returned value is basically the concatenation of
aoqi@0 105 * the primaryType, the '/' character and the secondaryType.
aoqi@0 106 *
aoqi@0 107 * @return the type
aoqi@0 108 */
aoqi@0 109 public String getBaseType() {
aoqi@0 110 return primaryType + '/' + subType;
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 /**
aoqi@0 114 * Return the specified parameter value. Returns <code>null</code>
aoqi@0 115 * if this parameter is absent.
aoqi@0 116 *
aoqi@0 117 * @param name parameter name
aoqi@0 118 * @return parameter value
aoqi@0 119 */
aoqi@0 120 public String getParameter(String name) {
aoqi@0 121 if (list == null)
aoqi@0 122 return null;
aoqi@0 123
aoqi@0 124 return list.get(name);
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 /**
aoqi@0 128 * Return a ParameterList object that holds all the available
aoqi@0 129 * parameters. Returns null if no parameters are available.
aoqi@0 130 *
aoqi@0 131 * @return ParameterList
aoqi@0 132 */
aoqi@0 133 public ParameterList getParameterList() {
aoqi@0 134 return list;
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 }

mercurial