1 7 8 package javax.print; 9 10 import java.io.IOException ; 11 import java.io.ObjectInputStream ; 12 import java.io.ObjectOutputStream ; 13 import java.io.Serializable ; 14 15 import java.util.Map ; 16 17 429 public class DocFlavor implements Serializable , Cloneable { 430 431 private static final long serialVersionUID = -4512080796965449721L; 432 433 445 public static final String hostEncoding; 446 447 static { 448 hostEncoding = 449 (String )java.security.AccessController.doPrivileged( 450 new sun.security.action.GetPropertyAction("file.encoding")); 451 } 452 453 456 private transient MimeType myMimeType; 457 458 462 private String myClassName; 463 464 467 private transient String myStringValue = null; 468 469 470 485 public DocFlavor(String mimeType, String className) { 486 if (className == null) { 487 throw new NullPointerException (); 488 } 489 myMimeType = new MimeType (mimeType); 490 myClassName = className; 491 } 492 493 498 public String getMimeType() { 499 return myMimeType.getMimeType(); 500 } 501 502 506 public String getMediaType() { 507 return myMimeType.getMediaType(); 508 } 509 510 514 public String getMediaSubtype() { 515 return myMimeType.getMediaSubtype(); 516 } 517 518 533 public String getParameter(String paramName) { 534 return 535 (String )myMimeType.getParameterMap().get(paramName.toLowerCase()); 536 } 537 538 542 public String getRepresentationClassName() { 543 return myClassName; 544 } 545 546 554 public String toString() { 555 return getStringValue(); 556 } 557 558 561 public int hashCode() { 562 return getStringValue().hashCode(); 563 } 564 565 583 public boolean equals(Object obj) { 584 return 585 obj != null && 586 obj instanceof DocFlavor && 587 getStringValue().equals (((DocFlavor ) obj).getStringValue()); 588 } 589 590 593 private String getStringValue() { 594 if (myStringValue == null) { 595 myStringValue = myMimeType + "; class=\"" + myClassName + "\""; 596 } 597 return myStringValue; 598 } 599 600 603 private void writeObject(ObjectOutputStream s) throws IOException { 604 605 s.defaultWriteObject(); 606 s.writeObject(myMimeType.getMimeType()); 607 } 608 609 617 private void readObject(ObjectInputStream s) 618 throws ClassNotFoundException , IOException { 619 620 s.defaultReadObject(); 621 myMimeType = new MimeType ((String )s.readObject()); 622 } 623 624 632 public static class BYTE_ARRAY extends DocFlavor { 633 634 private static final long serialVersionUID = -9065578006593857475L; 635 636 648 public BYTE_ARRAY (String mimeType) { 649 super (mimeType, "[B"); 650 } 651 652 659 public static final BYTE_ARRAY TEXT_PLAIN_HOST = 660 new BYTE_ARRAY ("text/plain; charset="+hostEncoding); 661 662 668 public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 = 669 new BYTE_ARRAY ("text/plain; charset=utf-8"); 670 671 677 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 = 678 new BYTE_ARRAY ("text/plain; charset=utf-16"); 679 680 681 688 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE = 689 new BYTE_ARRAY ("text/plain; charset=utf-16be"); 690 691 698 public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE = 699 new BYTE_ARRAY ("text/plain; charset=utf-16le"); 700 701 707 public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = 708 new BYTE_ARRAY ("text/plain; charset=us-ascii"); 709 710 711 718 public static final BYTE_ARRAY TEXT_HTML_HOST = 719 new BYTE_ARRAY ("text/html; charset="+hostEncoding); 720 721 727 public static final BYTE_ARRAY TEXT_HTML_UTF_8 = 728 new BYTE_ARRAY ("text/html; charset=utf-8"); 729 730 736 public static final BYTE_ARRAY TEXT_HTML_UTF_16 = 737 new BYTE_ARRAY ("text/html; charset=utf-16"); 738 739 746 public static final BYTE_ARRAY TEXT_HTML_UTF_16BE = 747 new BYTE_ARRAY ("text/html; charset=utf-16be"); 748 749 756 public static final BYTE_ARRAY TEXT_HTML_UTF_16LE = 757 new BYTE_ARRAY ("text/html; charset=utf-16le"); 758 759 765 public static final BYTE_ARRAY TEXT_HTML_US_ASCII = 766 new BYTE_ARRAY ("text/html; charset=us-ascii"); 767 768 769 773 public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf"); 774 775 780 public static final BYTE_ARRAY POSTSCRIPT = 781 new BYTE_ARRAY ("application/postscript"); 782 783 788 public static final BYTE_ARRAY PCL = 789 new BYTE_ARRAY ("application/vnd.hp-PCL"); 790 791 795 public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif"); 796 797 801 public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg"); 802 803 807 public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png"); 808 809 816 public static final BYTE_ARRAY AUTOSENSE = 817 new BYTE_ARRAY ("application/octet-stream"); 818 819 } 820 821 830 public static class INPUT_STREAM extends DocFlavor { 831 832 private static final long serialVersionUID = -7045842700749194127L; 833 834 847 public INPUT_STREAM (String mimeType) { 848 super (mimeType, "java.io.InputStream"); 849 } 850 851 858 public static final INPUT_STREAM TEXT_PLAIN_HOST = 859 new INPUT_STREAM ("text/plain; charset="+hostEncoding); 860 861 867 public static final INPUT_STREAM TEXT_PLAIN_UTF_8 = 868 new INPUT_STREAM ("text/plain; charset=utf-8"); 869 870 876 public static final INPUT_STREAM TEXT_PLAIN_UTF_16 = 877 new INPUT_STREAM ("text/plain; charset=utf-16"); 878 879 886 public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE = 887 new INPUT_STREAM ("text/plain; charset=utf-16be"); 888 889 896 public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE = 897 new INPUT_STREAM ("text/plain; charset=utf-16le"); 898 899 905 public static final INPUT_STREAM TEXT_PLAIN_US_ASCII = 906 new INPUT_STREAM ("text/plain; charset=us-ascii"); 907 908 915 public static final INPUT_STREAM TEXT_HTML_HOST = 916 new INPUT_STREAM ("text/html; charset="+hostEncoding); 917 918 924 public static final INPUT_STREAM TEXT_HTML_UTF_8 = 925 new INPUT_STREAM ("text/html; charset=utf-8"); 926 927 933 public static final INPUT_STREAM TEXT_HTML_UTF_16 = 934 new INPUT_STREAM ("text/html; charset=utf-16"); 935 936 943 public static final INPUT_STREAM TEXT_HTML_UTF_16BE = 944 new INPUT_STREAM ("text/html; charset=utf-16be"); 945 946 953 public static final INPUT_STREAM TEXT_HTML_UTF_16LE = 954 new INPUT_STREAM ("text/html; charset=utf-16le"); 955 956 962 public static final INPUT_STREAM TEXT_HTML_US_ASCII = 963 new INPUT_STREAM ("text/html; charset=us-ascii"); 964 965 966 971 public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf"); 972 973 978 public static final INPUT_STREAM POSTSCRIPT = 979 new INPUT_STREAM ("application/postscript"); 980 981 986 public static final INPUT_STREAM PCL = 987 new INPUT_STREAM ("application/vnd.hp-PCL"); 988 989 994 public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif"); 995 996 1001 public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg"); 1002 1003 1008 public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png"); 1009 1010 1018 public static final INPUT_STREAM AUTOSENSE = 1019 new INPUT_STREAM ("application/octet-stream"); 1020 1021 } 1022 1023 1033 public static class URL extends DocFlavor { 1034 1035 1047 public URL (String mimeType) { 1048 super (mimeType, "java.net.URL"); 1049 } 1050 1051 1058 public static final URL TEXT_PLAIN_HOST = 1059 new URL ("text/plain; charset="+hostEncoding); 1060 1061 1067 public static final URL TEXT_PLAIN_UTF_8 = 1068 new URL ("text/plain; charset=utf-8"); 1069 1070 1076 public static final URL TEXT_PLAIN_UTF_16 = 1077 new URL ("text/plain; charset=utf-16"); 1078 1079 1086 public static final URL TEXT_PLAIN_UTF_16BE = 1087 new URL ("text/plain; charset=utf-16be"); 1088 1089 1096 public static final URL TEXT_PLAIN_UTF_16LE = 1097 new URL ("text/plain; charset=utf-16le"); 1098 1099 1105 public static final URL TEXT_PLAIN_US_ASCII = 1106 new URL ("text/plain; charset=us-ascii"); 1107 1108 1115 public static final URL TEXT_HTML_HOST = 1116 new URL ("text/html; charset="+hostEncoding); 1117 1118 1124 public static final URL TEXT_HTML_UTF_8 = 1125 new URL ("text/html; charset=utf-8"); 1126 1127 1133 public static final URL TEXT_HTML_UTF_16 = 1134 new URL ("text/html; charset=utf-16"); 1135 1136 1143 public static final URL TEXT_HTML_UTF_16BE = 1144 new URL ("text/html; charset=utf-16be"); 1145 1146 1153 public static final URL TEXT_HTML_UTF_16LE = 1154 new URL ("text/html; charset=utf-16le"); 1155 1156 1162 public static final URL TEXT_HTML_US_ASCII = 1163 new URL ("text/html; charset=us-ascii"); 1164 1165 1166 1170 public static final URL PDF = new URL ("application/pdf"); 1171 1172 1176 public static final URL POSTSCRIPT = new URL ("application/postscript"); 1177 1178 1182 public static final URL PCL = new URL ("application/vnd.hp-PCL"); 1183 1184 1188 public static final URL GIF = new URL ("image/gif"); 1189 1190 1194 public static final URL JPEG = new URL ("image/jpeg"); 1195 1196 1200 public static final URL PNG = new URL ("image/png"); 1201 1202 1209 public static final URL AUTOSENSE = new URL ("application/octet-stream"); 1210 1211 } 1212 1213 1222 public static class CHAR_ARRAY extends DocFlavor { 1223 1224 private static final long serialVersionUID = -8720590903724405128L; 1225 1226 1241 public CHAR_ARRAY (String mimeType) { 1242 super (mimeType, "[C"); 1243 } 1244 1245 1250 public static final CHAR_ARRAY TEXT_PLAIN = 1251 new CHAR_ARRAY ("text/plain; charset=utf-16"); 1252 1253 1258 public static final CHAR_ARRAY TEXT_HTML = 1259 new CHAR_ARRAY ("text/html; charset=utf-16"); 1260 1261 } 1262 1263 1272 public static class STRING extends DocFlavor { 1273 1274 private static final long serialVersionUID = 4414407504887034035L; 1275 1276 1290 public STRING (String mimeType) { 1291 super (mimeType, "java.lang.String"); 1292 } 1293 1294 1299 public static final STRING TEXT_PLAIN = 1300 new STRING ("text/plain; charset=utf-16"); 1301 1302 1307 public static final STRING TEXT_HTML = 1308 new STRING ("text/html; charset=utf-16"); 1309 } 1310 1311 1320 public static class READER extends DocFlavor { 1321 1322 private static final long serialVersionUID = 7100295812579351567L; 1323 1324 1339 public READER (String mimeType) { 1340 super (mimeType, "java.io.Reader"); 1341 } 1342 1343 1348 public static final READER TEXT_PLAIN = 1349 new READER ("text/plain; charset=utf-16"); 1350 1351 1356 public static final READER TEXT_HTML = 1357 new READER ("text/html; charset=utf-16"); 1358 1359 } 1360 1361 1369 public static class SERVICE_FORMATTED extends DocFlavor { 1370 1371 private static final long serialVersionUID = 6181337766266637256L; 1372 1373 1385 public SERVICE_FORMATTED (String className) { 1386 super ("application/x-java-jvm-local-objectref", className); 1387 } 1388 1389 1395 public static final SERVICE_FORMATTED RENDERABLE_IMAGE = 1396 new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage"); 1397 1398 1403 public static final SERVICE_FORMATTED PRINTABLE = 1404 new SERVICE_FORMATTED ("java.awt.print.Printable"); 1405 1406 1411 public static final SERVICE_FORMATTED PAGEABLE = 1412 new SERVICE_FORMATTED ("java.awt.print.Pageable"); 1413 1414 } 1415 1416} 1417 | Popular Tags |