2362N/A * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Class MimeType encapsulates a Multipurpose Internet Mail Extensions (MIME) 0N/A * MIME type object is part of a {@link DocFlavor DocFlavor} object and 0N/A * specifies the format of the print data. 0N/A * Class MimeType is similar to the like-named 0N/A * class in package {@link java.awt.datatransfer java.awt.datatransfer}. Class 0N/A * java.awt.datatransfer.MimeType is not used in the Jini Print Service API 0N/A * Since not all Java profiles include the AWT, the Jini Print Service should 0N/A * not depend on an AWT class. 0N/A * The implementation of class java.awt.datatransfer.MimeType does not 0N/A * that equivalent MIME types will have the same serialized representation. 0N/A * Thus, since the Jini Lookup Service (JLUS) matches service attributes based 0N/A * on equality of serialized representations, JLUS searches involving MIME 0N/A * types encapsulated in class java.awt.datatransfer.MimeType may incorrectly 0N/A * Class MimeType's serialized representation is based on the following 0N/A * canonical form of a MIME type string. Thus, two MIME types that are not 0N/A * identical but that are equivalent (that have the same canonical form) will 0N/A * be considered equal by the JLUS's matching algorithm. 0N/A * <LI> The media type, media subtype, and parameters are retained, but all 0N/A * comments and whitespace characters are discarded. 0N/A * <LI> The media type, media subtype, and parameter names are converted to 0N/A * <LI> The parameter values retain their original case, except a charset 0N/A * parameter value for a text media type is converted to lowercase. 0N/A * <LI> Quote characters surrounding parameter values are removed. 0N/A * <LI> Quoting backslash characters inside parameter values are removed. 0N/A * <LI> The parameters are arranged in ascending order of parameter name. 0N/A * @author Alan Kaminsky 0N/A * Array of strings that hold pieces of this MIME type's canonical form. 0N/A * If the MIME type has <I>n</I> parameters, <I>n</I> >= 0, then the 0N/A * strings in the array are: 0N/A * <BR>Index 0 -- Media type. 0N/A * <BR>Index 1 -- Media subtype. 0N/A * <BR>Index 2<I>i</I>+2 -- Name of parameter <I>i</I>, 0N/A * <I>i</I>=0,1,...,<I>n</I>-1. 0N/A * <BR>Index 2<I>i</I>+3 -- Value of parameter <I>i</I>, 0N/A * <I>i</I>=0,1,...,<I>n</I>-1. 0N/A * <BR>Parameters are arranged in ascending order of parameter name. 0N/A * String value for this MIME type. Computed when needed and cached. 0N/A * Parameter map entry set. Computed when needed and cached. 0N/A * Parameter map. Computed when needed and cached. 0N/A * Parameter map entry. 0N/A * Parameter map entry set iterator. 0N/A * Parameter map entry set. 0N/A * Construct a new MIME type object from the given string. The given 0N/A * string is converted into canonical form and stored internally. 0N/A * @param s MIME media type string. 0N/A * @exception NullPointerException 0N/A * (unchecked exception) Thrown if <CODE>s</CODE> is null. 0N/A * @exception IllegalArgumentException 0N/A * (unchecked exception) Thrown if <CODE>s</CODE> does not obey the 0N/A * syntax for a MIME media type string. 0N/A * Returns this MIME type object's MIME type string based on the canonical 0N/A * form. Each parameter value is enclosed in quotes. 0N/A * Returns this MIME type object's media type. 0N/A * Returns this MIME type object's media subtype. 0N/A * Returns an unmodifiable map view of the parameters in this MIME type 0N/A * object. Each entry in the parameter map view consists of a parameter 0N/A * name String (key) mapping to a parameter value String. If this MIME 0N/A * type object has no parameters, an empty map is returned. 0N/A * @return Parameter map for this MIME type object. 0N/A * Converts this MIME type object to a string. 0N/A * @return MIME type string based on the canonical form. Each parameter 0N/A * value is enclosed in quotes. 0N/A * Returns a hash code for this MIME type object. 0N/A * Determine if this MIME type object is equal to the given object. The two 0N/A * are equal if the given object is not null, is an instance of class 0N/A * net.jini.print.data.MimeType, and has the same canonical form as this 0N/A * MIME type object (that is, has the same type, subtype, and parameters). 0N/A * Thus, if two MIME type objects are the same except for comments, they are 0N/A * charset=us-ascii" are not considered equal, even though they represent 0N/A * the same media type (because the default character set for plain text is 0N/A * @param obj Object to test. 0N/A * @return True if this MIME type object equals <CODE>obj</CODE>, false 0N/A * Returns this MIME type's string value in canonical form. 0N/A for (
int i =
2; i < n; i +=
2) {
0N/A// Hidden classes, constants, and operations for parsing a MIME media type 0N/A // Class for a lexical analyzer. 0N/A // Looking for a token, quoted string, or tspecial 0N/A }
else if (c ==
'\"') {
0N/A }
else if (c ==
'(') {
0N/A }
else if (c ==
'/' || c ==
';' || c ==
'=' ||
0N/A c ==
')' || c ==
'<' || c ==
'>' ||
0N/A c ==
'@' || c ==
',' || c ==
':' ||
0N/A c ==
'\\' || c ==
'[' || c ==
']' ||
0N/A // In a quoted string 0N/A }
else if (c ==
'\\') {
0N/A // In a quoted string, backslash seen 0N/A }
else if (c ==
')') {
0N/A }
else if (c ==
'\\') {
0N/A // In a comment, backslash seen 0N/A }
else if (c ==
'\"' || c ==
'(' || c ==
'/' ||
0N/A c ==
';' || c ==
'=' || c ==
')' ||
0N/A c ==
'<' || c ==
'>' || c ==
'@' ||
0N/A c ==
',' || c ==
':' || c ==
'\\' ||
0N/A c ==
'[' || c ==
']' || c ==
'?') {
0N/A * Returns a lowercase version of the given string. The lowercase version 0N/A * is constructed by applying Character.toLowerCase() to each character of 0N/A * the given string, which maps characters to lowercase using the rules of 0N/A * Unicode. This mapping is the same regardless of locale, whereas the 0N/A * mapping of String.toLowerCase() may be different depending on the 0N/A for (
int i =
0; i < n; ++ i) {
0N/A * Returns a version of the given string with backslashes removed. 0N/A for (i =
0; i < n; ++ i) {
0N/A * Returns a version of the string surrounded by quotes and with interior 0N/A * quotes preceded by a backslash. 0N/A for (i =
0; i < n; ++ i) {
0N/A * Parses the given string into canonical pieces and stores the pieces in 0N/A * {@link #myPieces <CODE>myPieces</CODE>}. 0N/A * Special rules applied: 0N/A * <LI> If the media type is text, the value of a charset parameter is 0N/A * converted to lowercase. 0N/A * @param s MIME media type string. 0N/A * @exception NullPointerException 0N/A * (unchecked exception) Thrown if <CODE>s</CODE> is null. 0N/A * @exception IllegalArgumentException 0N/A * (unchecked exception) Thrown if <CODE>s</CODE> does not obey the 0N/A * syntax for a MIME media type string. 0N/A // Parse media type. 0N/A // Parse zero or more parameters. 0N/A // Parse parameter name. 0N/A // Parse parameter value. 0N/A // Make sure we've consumed everything. 0N/A // Save the pieces. Parameters are not in ascending order yet. 0N/A // Sort the parameters into ascending order using an insertion sort. 0N/A for (i =
4; i < n; i +=
2) {