1 17 18 package org.objectweb.jac.lib; 19 20 import org.objectweb.jac.core.rtti.ClassRepository; 21 import org.objectweb.jac.core.rtti.FieldItem; 22 import org.objectweb.jac.core.rtti.MetaItem; 23 import org.objectweb.jac.util.MimeTypes; 24 25 29 public class Attachment { 30 34 public Attachment(byte[] data, String mimeType, String name) { 35 this.data = data; 36 this.mimeType = mimeType; 37 this.name = name; 38 if (mimeType==null) { 39 guessMimeType(); 40 } 41 } 42 43 static MimeTypes mimeTypes; 44 45 public void guessMimeType() { 46 try { 47 if (mimeTypes==null) { 48 mimeTypes = new MimeTypes(); 49 mimeTypes.readDefaults(); 50 } 51 this.mimeType = mimeTypes.getMimeType(name); 52 } catch (Exception e) { 53 e.printStackTrace(); 54 } 55 } 56 57 byte[] data; 58 63 public byte[] getData() { 64 return data; 65 } 66 71 public void setData(byte[] data) { 72 this.data = data; 73 } 74 75 String mimeType; 76 81 public String getMimeType() { 82 return mimeType; 83 } 84 89 public void setMimeType(String mimeType) { 90 this.mimeType = mimeType; 91 } 92 93 String name; 94 98 public String getName() { 99 return name; 100 } 101 105 public void setName(String name) { 106 this.name = name; 107 } 108 109 public static Object getType(FieldItem field, Attachment attachment) { 110 String type = attachment.getMimeType(); 111 if (type!=null) { 112 if (type.startsWith("text/")) { 113 return "text"; 114 } else if (type.startsWith("image/")) { 115 return "image"; 116 } 117 } 118 return field.getTypeItem(); 119 } 120 } 121 | Popular Tags |