1 4 5 18 package org.wings.externalizer; 19 20 import org.wings.io.Device; 21 22 import java.io.Reader ; 23 import java.io.StringReader ; 24 import java.util.Collection ; 25 26 public class TextExternalizer implements Externalizer { 27 28 private static final Class [] SUPPORTED_CLASSES = {String .class}; 29 30 protected String extension; 31 protected String mimeType; 32 protected final String [] supportedMimeTypes = new String [1]; 33 34 35 public TextExternalizer(String mimeType, String extension) { 36 this.mimeType = mimeType; 37 this.extension = extension; 38 39 supportedMimeTypes[0] = mimeType; 40 } 41 42 public TextExternalizer(String mimeType) { 43 this(mimeType, "txt"); 44 } 45 46 public TextExternalizer() { 47 this("text/plain", "txt"); 48 } 49 50 public void setExtension(String extension) { 51 this.extension = extension; 52 } 53 54 public String getExtension(Object obj) { 55 return extension; 56 } 57 58 public void setMimeType(String mimeType) { 59 this.mimeType = mimeType; 60 } 61 62 public String getMimeType(Object obj) { 63 return mimeType; 64 } 65 66 public boolean isFinal(Object obj) { 67 return true; 68 } 69 70 public int getLength(Object obj) { 71 return -1; 72 } 73 74 public void write(Object obj, Device out) 75 throws java.io.IOException { 76 Reader reader = new StringReader ((String ) obj); 77 char[] buffer = new char[2048]; 78 int num; 79 while ((num = reader.read(buffer)) > 0) { 80 out.print(buffer, 0, num); 81 } 82 reader.close(); 83 } 84 85 public Class [] getSupportedClasses() { 86 return SUPPORTED_CLASSES; 87 } 88 89 public String [] getSupportedMimeTypes() { 90 return supportedMimeTypes; 91 } 92 93 public Collection getHeaders(Object obj) { 94 return null; 95 } 96 } 97 98 99 | Popular Tags |