1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import org.objectweb.jac.core.rtti.FieldItem; 21 import org.objectweb.jac.lib.Attachment; 22 import org.objectweb.jac.util.Streams; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 26 public class AttachmentEditor extends AbstractFieldEditor 27 implements HTMLEditor 28 { 29 public AttachmentEditor(Object substance, FieldItem field) { 30 super(substance,field); 31 } 32 33 35 protected boolean doReadValue(Object parameter) { 36 RequestPart part = (RequestPart)parameter; 37 if(part.getFilename()==null || part.getFilename().equals("")) { 38 return false; 39 } 40 try { 41 byte[] data = Streams.readStream(part.getData()); 42 Attachment attachment = 43 new Attachment(data, 44 (String )part.getHeaders().get("content-type"), 45 part.getFilename()); 46 setValue(attachment); 47 return true; 48 } catch (IOException e) { 49 logger.error("Failed to read data for parameters "+part.getName(),e); 50 return false; 51 } 52 } 53 54 public void genHTML(PrintWriter out) { 55 out.print("<input name=\""+label+"\" type=\"file\">"); 56 } 57 } 58 | Popular Tags |