Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / print / DocFlavor.java
blob1e96a70c024505b3ce82692d987ccf646bcc6b5e
1 /* DocFlavor.java --
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.print;
41 import java.io.Serializable;
42 import java.util.HashMap;
43 import java.util.Iterator;
44 import java.util.Map;
46 /**
47 * @author Michael Koch (konqueror@gmx.de)
49 public class DocFlavor implements Cloneable, Serializable
51 /**
52 * @author Michael Koch (konqueror@gmx.de)
54 public static class BYTE_ARRAY
55 extends DocFlavor
57 private static final long serialVersionUID = -9065578006593857475L;
59 public static final BYTE_ARRAY AUTOSENSE = new BYTE_ARRAY("application/octet-stream");
60 public static final BYTE_ARRAY GIF = new BYTE_ARRAY("image/gif");
61 public static final BYTE_ARRAY JPEG = new BYTE_ARRAY("image/jpeg");
62 public static final BYTE_ARRAY PCL = new BYTE_ARRAY("application/vnd.hp-PCL");
63 public static final BYTE_ARRAY PDF = new BYTE_ARRAY("application/pdf");
64 public static final BYTE_ARRAY PNG = new BYTE_ARRAY("image/png");
65 public static final BYTE_ARRAY POSTSCRIPT = new BYTE_ARRAY("application/postscript");
66 public static final BYTE_ARRAY TEXT_HTML_HOST = new BYTE_ARRAY("text/html");
67 public static final BYTE_ARRAY TEXT_HTML_US_ASCII = new BYTE_ARRAY("text/html; charset=us-ascii");
68 public static final BYTE_ARRAY TEXT_HTML_UTF_16 = new BYTE_ARRAY("text/html; charset=utf-16");
69 public static final BYTE_ARRAY TEXT_HTML_UTF_16BE = new BYTE_ARRAY("text/html; charset=utf-16be");
70 public static final BYTE_ARRAY TEXT_HTML_UTF_16LE = new BYTE_ARRAY("text/html; charset=utf-16le");
71 public static final BYTE_ARRAY TEXT_HTML_UTF_8 = new BYTE_ARRAY("text/html; charset=utf-8");
72 public static final BYTE_ARRAY TEXT_PLAIN_HOST = new BYTE_ARRAY("text/plain");
73 public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = new BYTE_ARRAY("text/plain; charset=us-ascii");
74 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 = new BYTE_ARRAY("text/plain; charset=utf-16");
75 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE = new BYTE_ARRAY("text/plain; charset=utf-16be");
76 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE = new BYTE_ARRAY("text/plain; charset=utf-16le");
77 public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 = new BYTE_ARRAY("text/plain; charset=utf-8");
79 public BYTE_ARRAY(String mimeType)
81 super(mimeType, "[B");
85 /**
86 * @author Michael Koch (konqueror@gmx.de)
88 public static class CHAR_ARRAY
89 extends DocFlavor
91 private static final long serialVersionUID = -8720590903724405128L;
93 public static final DocFlavor.CHAR_ARRAY TEXT_HTML = new CHAR_ARRAY("text/html; charset=utf-16");
94 public static final DocFlavor.CHAR_ARRAY TEXT_PLAIN = new CHAR_ARRAY("text/plain; charset=utf-16");
96 public CHAR_ARRAY(String mimeType)
98 super(mimeType, "[C");
103 * @author Michael Koch (konqueror@gmx.de)
105 public static class INPUT_STREAM
106 extends DocFlavor
108 private static final long serialVersionUID = -7045842700749194127L;
110 public static final INPUT_STREAM AUTOSENSE = new INPUT_STREAM("application/octet-stream");
111 public static final INPUT_STREAM GIF = new INPUT_STREAM("image/gif");
112 public static final INPUT_STREAM JPEG = new INPUT_STREAM("image/jpeg");
113 public static final INPUT_STREAM PCL = new INPUT_STREAM("application/vnd.hp-PCL");
114 public static final INPUT_STREAM PDF = new INPUT_STREAM("application/pdf");
115 public static final INPUT_STREAM PNG = new INPUT_STREAM("image/png");
116 public static final INPUT_STREAM POSTSCRIPT = new INPUT_STREAM("application/postscript");
117 public static final INPUT_STREAM TEXT_HTML_HOST = new INPUT_STREAM("text/html");
118 public static final INPUT_STREAM TEXT_HTML_US_ASCII = new INPUT_STREAM("text/html; charset=us-ascii");
119 public static final INPUT_STREAM TEXT_HTML_UTF_16 = new INPUT_STREAM("text/html; charset=utf-16");
120 public static final INPUT_STREAM TEXT_HTML_UTF_16BE = new INPUT_STREAM("text/html; charset=utf-16be");
121 public static final INPUT_STREAM TEXT_HTML_UTF_16LE = new INPUT_STREAM("text/html; charset=utf-16le");
122 public static final INPUT_STREAM TEXT_HTML_UTF_8 = new INPUT_STREAM("text/html; charset=utf-8");
123 public static final INPUT_STREAM TEXT_PLAIN_HOST = new INPUT_STREAM("text/plain");
124 public static final INPUT_STREAM TEXT_PLAIN_US_ASCII = new INPUT_STREAM("text/plain; charset=us-ascii");
125 public static final INPUT_STREAM TEXT_PLAIN_UTF_16 = new INPUT_STREAM("text/plain; charset=utf-16");
126 public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE = new INPUT_STREAM("text/plain; charset=utf-16be");
127 public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE = new INPUT_STREAM("text/plain; charset=utf-16le");
128 public static final INPUT_STREAM TEXT_PLAIN_UTF_8 = new INPUT_STREAM("text/plain; charset=utf-8");
130 public INPUT_STREAM(String mimeType)
132 super(mimeType, "java.io.InputStream");
137 * @author Michael Koch (konqueror@gmx.de)
139 public static class READER
140 extends DocFlavor
142 private static final long serialVersionUID = 7100295812579351567L;
144 public static final DocFlavor.READER TEXT_HTML = new READER("text/html; charset=utf-16");
145 public static final DocFlavor.READER TEXT_PLAIN = new READER("text/plain; charset=utf-16");
147 public READER(String mimeType)
149 super(mimeType, "java.io.Reader");
154 * @author Michael Koch (konqueror@gmx.de)
156 public static class SERVICE_FORMATTED
157 extends DocFlavor
159 private static final long serialVersionUID = 6181337766266637256L;
161 public static final DocFlavor.SERVICE_FORMATTED PAGEABLE = new SERVICE_FORMATTED("java.awt.print.Pageable");
162 public static final DocFlavor.SERVICE_FORMATTED PRINTABLE = new SERVICE_FORMATTED("java.awt.print.Printable");
163 public static final DocFlavor.SERVICE_FORMATTED RENDERABLE_IMAGE = new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");
165 public SERVICE_FORMATTED(String className)
167 super("application/x-java-jvm-local-objectref", className);
172 * @author Michael Koch (konqueror@gmx.de)
174 public static class STRING
175 extends DocFlavor
177 private static final long serialVersionUID = 4414407504887034035L;
179 public static final DocFlavor.STRING TEXT_HTML = new STRING("text/html; charset=utf-16");
180 public static final DocFlavor.STRING TEXT_PLAIN = new STRING("text/plain; charset=utf-16");
182 public STRING(String mimeType)
184 super(mimeType, "java.lang.String");
189 * @author Michael Koch (konqueror@gmx.de)
191 public static class URL
192 extends DocFlavor
194 private static final long serialVersionUID = 2936725788144902062L;
196 public static final DocFlavor.URL AUTOSENSE = new URL("application/octet-stream");
197 public static final DocFlavor.URL GIF = new URL("image/gif");
198 public static final DocFlavor.URL JPEG = new URL("image/jpeg");
199 public static final DocFlavor.URL PCL = new URL("application/vnd.hp-PCL");
200 public static final DocFlavor.URL PDF = new URL("application/pdf");
201 public static final DocFlavor.URL PNG = new URL("image/png");
202 public static final DocFlavor.URL POSTSCRIPT = new URL("application/postscript");
203 public static final DocFlavor.URL TEXT_HTML_HOST = new URL("text/html");
204 public static final DocFlavor.URL TEXT_HTML_US_ASCII = new URL("text/html; charset=us-ascii");
205 public static final DocFlavor.URL TEXT_HTML_UTF_16 = new URL("text/html; charset=utf-16");
206 public static final DocFlavor.URL TEXT_HTML_UTF_16BE = new URL("text/html; charset=utf-16be");
207 public static final DocFlavor.URL TEXT_HTML_UTF_16LE = new URL("text/html; charset=utf-16le");
208 public static final DocFlavor.URL TEXT_HTML_UTF_8 = new URL("text/html; charset=utf-8");
209 public static final DocFlavor.URL TEXT_PLAIN_HOST = new URL("text/plain");
210 public static final DocFlavor.URL TEXT_PLAIN_US_ASCII = new URL("text/plain; charset=us-ascii");
211 public static final DocFlavor.URL TEXT_PLAIN_UTF_16 = new URL("text/plain; charset=utf-16");
212 public static final DocFlavor.URL TEXT_PLAIN_UTF_16BE = new URL("text/plain; charset=utf-16be");
213 public static final DocFlavor.URL TEXT_PLAIN_UTF_16LE = new URL("text/plain; charset=utf-16le");
214 public static final DocFlavor.URL TEXT_PLAIN_UTF_8 = new URL("text/plain; charset=utf-8");
216 public URL(String mimeType)
218 super(mimeType, "java.net.URL");
222 private static final long serialVersionUID = -4512080796965449721L;
224 // FIXME: Get the host encoding from somewhere. Note that the new String is to make
225 // sure the field won't be a compile time constant.
226 public static final String hostEncoding = new String("US-ASCII");
228 private String mediaSubtype;
229 private String mediaType;
230 private String className;
231 private HashMap params = new HashMap();
233 public DocFlavor(String mimeType, String className)
235 if (mimeType == null || className == null)
236 throw new NullPointerException();
238 parseMimeType(mimeType);
239 this.className = className;
242 private void parseMimeType(String mimeType)
244 // FIXME: This method is know to be not completely correct, but it works for now.
246 int pos = mimeType.indexOf(';');
248 if (pos != -1)
250 String tmp = mimeType.substring(pos + 2);
251 mimeType = mimeType.substring(0, pos);
252 pos = tmp.indexOf('=');
253 params.put(tmp.substring(0, pos), tmp.substring(pos + 1));
256 pos = mimeType.indexOf('/');
258 if (pos == -1)
259 throw new IllegalArgumentException();
261 mediaType = mimeType.substring(0, pos);
262 mediaSubtype = mimeType.substring(pos + 1);
265 public boolean equals(Object obj)
267 if (! (obj instanceof DocFlavor))
268 return false;
270 DocFlavor tmp = (DocFlavor) obj;
272 return (getMimeType().equals(tmp.getMimeType())
273 && getRepresentationClassName().equals(tmp.getRepresentationClassName()));
276 public String getMediaSubtype()
278 return mediaSubtype;
281 public String getMediaType()
283 return mediaType;
286 public String getMimeType()
288 // FIXME: Check if this algorithm is correct.
290 String mimeType = getMediaType() + "/" + getMediaSubtype();
291 Iterator it = params.entrySet().iterator();
293 while (it.hasNext())
295 Map.Entry entry = (Map.Entry) it.next();
296 mimeType += "; " + entry.getKey() + "=\"" + entry.getValue() + "\"";
299 return mimeType;
302 public String getParameter(String paramName)
304 if (paramName == null)
305 throw new NullPointerException();
307 return (String) params.get(paramName);
310 public String getRepresentationClassName()
312 return className;
315 public int hashCode()
317 return ((mediaType.hashCode()
318 * mediaSubtype.hashCode()
319 * className.hashCode()) ^ params.hashCode());
322 public String toString()
324 return getMimeType();