1 12 package org.displaytag.export; 13 14 import java.io.OutputStream ; 15 16 import javax.servlet.jsp.JspException ; 17 18 import org.displaytag.Messages; 19 import org.displaytag.exception.BaseNestableJspTagException; 20 import org.displaytag.exception.SeverityEnum; 21 import org.displaytag.model.TableModel; 22 import org.displaytag.render.ItextTableWriter; 23 24 import com.lowagie.text.Document; 25 import com.lowagie.text.DocumentException; 26 import com.lowagie.text.PageSize; 27 import com.lowagie.text.Table; 28 29 30 35 public abstract class DefaultItextExportView implements BinaryExportView 36 { 37 38 41 private TableModel model; 42 43 46 public void setParameters(TableModel tableModel, boolean exportFullList, boolean includeHeader, 47 boolean decorateValues) 48 { 49 this.model = tableModel; 50 } 51 52 56 public String getMimeType() 57 { 58 return null; 59 } 60 61 64 public void doExport(OutputStream out) throws JspException 65 { 66 try 67 { 68 Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40); 69 this.initItextWriter(document, out); 70 document.open(); 71 Table table = new Table(this.model.getNumberOfColumns()); 72 ItextTableWriter writer = new ItextTableWriter(table, document); 73 writer.writeTable(this.model, "-1"); 74 document.add(table); 75 document.close(); 76 } 77 catch (Exception e) 78 { 79 throw new ItextGenerationException(e); 80 } 81 } 82 83 89 protected abstract void initItextWriter(Document document, OutputStream out) throws DocumentException; 90 91 96 static class ItextGenerationException extends BaseNestableJspTagException 97 { 98 99 102 private static final long serialVersionUID = 899149338534L; 103 104 108 public ItextGenerationException(Throwable cause) 109 { 110 super(DefaultItextExportView.class, Messages.getString("DefaultItextExportView.errorexporting"), cause); this.initCause(cause); 112 } 113 114 117 public SeverityEnum getSeverity() 118 { 119 return SeverityEnum.ERROR; 120 } 121 } 122 } 123 | Popular Tags |