1 18 package org.apache.batik.apps.rasterizer; 19 20 import org.apache.batik.transcoder.Transcoder; 21 import org.apache.batik.transcoder.image.JPEGTranscoder; 22 import org.apache.batik.transcoder.image.PNGTranscoder; 23 import org.apache.batik.transcoder.image.TIFFTranscoder; 24 25 33 public final class DestinationType { 34 public static final String PNG_STR = "image/png"; 35 public static final String JPEG_STR = "image/jpeg"; 36 public static final String TIFF_STR = "image/tiff"; 37 public static final String PDF_STR = "application/pdf"; 38 39 public static final int PNG_CODE = 0; 40 public static final int JPEG_CODE = 1; 41 public static final int TIFF_CODE = 2; 42 public static final int PDF_CODE = 3; 43 44 public static final String PNG_EXTENSION = ".png"; 45 public static final String JPEG_EXTENSION = ".jpg"; 46 public static final String TIFF_EXTENSION = ".tif"; 47 public static final String PDF_EXTENSION = ".pdf"; 48 49 public static final DestinationType PNG 50 = new DestinationType(PNG_STR, PNG_CODE, PNG_EXTENSION); 51 public static final DestinationType JPEG 52 = new DestinationType(JPEG_STR, JPEG_CODE, JPEG_EXTENSION); 53 public static final DestinationType TIFF 54 = new DestinationType(TIFF_STR, TIFF_CODE, TIFF_EXTENSION); 55 public static final DestinationType PDF 56 = new DestinationType(PDF_STR, PDF_CODE, PDF_EXTENSION); 57 58 private String type; 59 private int code; 60 private String extension; 61 62 private DestinationType(String type, int code, String extension){ 63 this.type = type; 64 this.code = code; 65 this.extension = extension; 66 } 67 68 public String getExtension(){ 69 return extension; 70 } 71 72 public String toString(){ 73 return type; 74 } 75 76 public int toInt(){ 77 return code; 78 } 79 80 85 protected Transcoder getTranscoder(){ 86 switch(code) { 87 case PNG_CODE: 88 return new PNGTranscoder(); 89 case JPEG_CODE: 90 return new JPEGTranscoder(); 91 case TIFF_CODE: 92 return new TIFFTranscoder(); 93 case PDF_CODE: 94 try { 95 Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder"); 96 return (Transcoder)pdfClass.newInstance(); 97 } catch(Exception e) { 98 return null; 99 } 100 default: 101 return null; 102 } 103 104 } 105 106 111 public DestinationType[] getValues() { 112 return new DestinationType[]{PNG, JPEG, TIFF, PDF}; 113 } 114 115 public Object readResolve(){ 116 switch(code){ 117 case PNG_CODE: 118 return PNG; 119 case JPEG_CODE: 120 return JPEG; 121 case TIFF_CODE: 122 return TIFF; 123 case PDF_CODE: 124 return PDF; 125 default: 126 throw new Error (); 127 } 128 } 129 } 130 | Popular Tags |