1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46:
49: public class DocFlavor implements Cloneable, Serializable
50: {
51:
54: public static class BYTE_ARRAY
55: extends DocFlavor
56: {
57: private static final long serialVersionUID = -9065578006593857475L;
58:
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");
78:
79: public BYTE_ARRAY(String mimeType)
80: {
81: super(mimeType, "[B");
82: }
83: }
84:
85:
88: public static class CHAR_ARRAY
89: extends DocFlavor
90: {
91: private static final long serialVersionUID = -8720590903724405128L;
92:
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");
95:
96: public CHAR_ARRAY(String mimeType)
97: {
98: super(mimeType, "[C");
99: }
100: }
101:
102:
105: public static class INPUT_STREAM
106: extends DocFlavor
107: {
108: private static final long serialVersionUID = -7045842700749194127L;
109:
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");
129:
130: public INPUT_STREAM(String mimeType)
131: {
132: super(mimeType, "java.io.InputStream");
133: }
134: }
135:
136:
139: public static class READER
140: extends DocFlavor
141: {
142: private static final long serialVersionUID = 7100295812579351567L;
143:
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");
146:
147: public READER(String mimeType)
148: {
149: super(mimeType, "java.io.Reader");
150: }
151: }
152:
153:
156: public static class SERVICE_FORMATTED
157: extends DocFlavor
158: {
159: private static final long serialVersionUID = 6181337766266637256L;
160:
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");
164:
165: public SERVICE_FORMATTED(String className)
166: {
167: super("application/x-java-jvm-local-objectref", className);
168: }
169: }
170:
171:
174: public static class STRING
175: extends DocFlavor
176: {
177: private static final long serialVersionUID = 4414407504887034035L;
178:
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");
181:
182: public STRING(String mimeType)
183: {
184: super(mimeType, "java.lang.String");
185: }
186: }
187:
188:
191: public static class URL
192: extends DocFlavor
193: {
194: private static final long serialVersionUID = 2936725788144902062L;
195:
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");
215:
216: public URL(String mimeType)
217: {
218: super(mimeType, "java.net.URL");
219: }
220: }
221:
222: private static final long serialVersionUID = -4512080796965449721L;
223:
224:
225:
226: public static final String hostEncoding = new String("US-ASCII");
227:
228: private String mediaSubtype;
229: private String mediaType;
230: private String className;
231: private HashMap params = new HashMap();
232:
233: public DocFlavor(String mimeType, String className)
234: {
235: if (mimeType == null || className == null)
236: throw new NullPointerException();
237:
238: parseMimeType(mimeType);
239: this.className = className;
240: }
241:
242: private void parseMimeType(String mimeType)
243: {
244:
245:
246: int pos = mimeType.indexOf(';');
247:
248: if (pos != -1)
249: {
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));
254: }
255:
256: pos = mimeType.indexOf('/');
257:
258: if (pos == -1)
259: throw new IllegalArgumentException();
260:
261: mediaType = mimeType.substring(0, pos);
262: mediaSubtype = mimeType.substring(pos + 1);
263: }
264:
265: public boolean equals(Object obj)
266: {
267: if (! (obj instanceof DocFlavor))
268: return false;
269:
270: DocFlavor tmp = (DocFlavor) obj;
271:
272: return (getMimeType().equals(tmp.getMimeType())
273: && getRepresentationClassName().equals(tmp.getRepresentationClassName()));
274: }
275:
276: public String getMediaSubtype()
277: {
278: return mediaSubtype;
279: }
280:
281: public String getMediaType()
282: {
283: return mediaType;
284: }
285:
286: public String getMimeType()
287: {
288:
289:
290: String mimeType = getMediaType() + "/" + getMediaSubtype();
291: Iterator it = params.entrySet().iterator();
292:
293: while (it.hasNext())
294: {
295: Map.Entry entry = (Map.Entry) it.next();
296: mimeType += "; " + entry.getKey() + "=\"" + entry.getValue() + "\"";
297: }
298:
299: return mimeType;
300: }
301:
302: public String getParameter(String paramName)
303: {
304: if (paramName == null)
305: throw new NullPointerException();
306:
307: return (String) params.get(paramName);
308: }
309:
310: public String getRepresentationClassName()
311: {
312: return className;
313: }
314:
315: public int hashCode()
316: {
317: return ((mediaType.hashCode()
318: * mediaSubtype.hashCode()
319: * className.hashCode()) ^ params.hashCode());
320: }
321:
322: public String toString()
323: {
324: return getMimeType();
325: }
326: }