MimeType.java revision 0
553N/A * Copyright 2000-2003 Sun Microsystems, Inc. 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 553N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 553N/A * by Sun 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. 553N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 553N/A * CA 95054 USA or visit www.sun.com if you need additional information or 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 765N/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 765N/A * on equality of serialized representations, JLUS searches involving MIME 765N/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 765N/A * identical but that are equivalent (that have the same canonical form) will 765N/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. 765N/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 765N/A * Array of strings that hold pieces of this MIME type's canonical form. 765N/A * If the MIME type has <I>n</I> parameters, <I>n</I> >= 0, then the 765N/A * strings in the array are: 765N/A * <BR>Index 0 -- Media type. 765N/A * <BR>Index 1 -- Media subtype. 765N/A * <BR>Index 2<I>i</I>+2 -- Name of parameter <I>i</I>, 765N/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. 765N/A * <BR>Parameters are arranged in ascending order of parameter name. 765N/A * String value for this MIME type. Computed when needed and cached. 765N/A * Parameter map entry set. Computed when needed and cached. 765N/A * Parameter map. Computed when needed and cached. * Parameter map entry set iterator. * Parameter map entry set. * Construct a new MIME type object from the given string. The given * string is converted into canonical form and stored internally. * @param s MIME media type string. * @exception NullPointerException * (unchecked exception) Thrown if <CODE>s</CODE> is null. * @exception IllegalArgumentException * (unchecked exception) Thrown if <CODE>s</CODE> does not obey the * syntax for a MIME media type string. * Returns this MIME type object's MIME type string based on the canonical * form. Each parameter value is enclosed in quotes. * Returns this MIME type object's media type. * Returns this MIME type object's media subtype. * Returns an unmodifiable map view of the parameters in this MIME type * object. Each entry in the parameter map view consists of a parameter * name String (key) mapping to a parameter value String. If this MIME * type object has no parameters, an empty map is returned. * @return Parameter map for this MIME type object. * Converts this MIME type object to a string. * @return MIME type string based on the canonical form. Each parameter * value is enclosed in quotes. * Returns a hash code for this MIME type object. * Determine if this MIME type object is equal to the given object. The two * are equal if the given object is not null, is an instance of class * net.jini.print.data.MimeType, and has the same canonical form as this * MIME type object (that is, has the same type, subtype, and parameters). * Thus, if two MIME type objects are the same except for comments, they are * charset=us-ascii" are not considered equal, even though they represent * the same media type (because the default character set for plain text is * @param obj Object to test. * @return True if this MIME type object equals <CODE>obj</CODE>, false * Returns this MIME type's string value in canonical form. for (
int i =
2; i < n; i +=
2) {
// Hidden classes, constants, and operations for parsing a MIME media type // Class for a lexical analyzer. // Looking for a token, quoted string, or tspecial }
else if (c ==
'/' || c ==
';' || c ==
'=' ||
c ==
')' || c ==
'<' || c ==
'>' ||
c ==
'@' || c ==
',' || c ==
':' ||
c ==
'\\' || c ==
'[' || c ==
']' ||
// In a quoted string, backslash seen // In a comment, backslash seen }
else if (c ==
'\"' || c ==
'(' || c ==
'/' ||
c ==
';' || c ==
'=' || c ==
')' ||
c ==
'<' || c ==
'>' || c ==
'@' ||
c ==
',' || c ==
':' || c ==
'\\' ||
c ==
'[' || c ==
']' || c ==
'?') {
* Returns a lowercase version of the given string. The lowercase version * is constructed by applying Character.toLowerCase() to each character of * the given string, which maps characters to lowercase using the rules of * Unicode. This mapping is the same regardless of locale, whereas the * mapping of String.toLowerCase() may be different depending on the for (
int i =
0; i < n; ++ i) {
* Returns a version of the given string with backslashes removed. for (i =
0; i < n; ++ i) {
* Returns a version of the string surrounded by quotes and with interior * quotes preceded by a backslash. for (i =
0; i < n; ++ i) {
* Parses the given string into canonical pieces and stores the pieces in * {@link #myPieces <CODE>myPieces</CODE>}. * <LI> If the media type is text, the value of a charset parameter is * converted to lowercase. * @param s MIME media type string. * @exception NullPointerException * (unchecked exception) Thrown if <CODE>s</CODE> is null. * @exception IllegalArgumentException * (unchecked exception) Thrown if <CODE>s</CODE> does not obey the * syntax for a MIME media type string. // Parse zero or more parameters. // Parse parameter value. // Make sure we've consumed everything. // Save the pieces. Parameters are not in ascending order yet. // Sort the parameters into ascending order using an insertion sort. for (i =
4; i < n; i +=
2) {