1 package com.lowagie.text.pdf.collection; 2 3 import java.util.Calendar ; 4 5 import com.lowagie.text.pdf.PdfDate; 6 import com.lowagie.text.pdf.PdfDictionary; 7 import com.lowagie.text.pdf.PdfName; 8 import com.lowagie.text.pdf.PdfNumber; 9 import com.lowagie.text.pdf.PdfObject; 10 import com.lowagie.text.pdf.PdfString; 11 12 public class PdfCollectionItem extends PdfDictionary { 13 14 15 PdfCollectionSchema schema; 16 17 20 public PdfCollectionItem(PdfCollectionSchema schema) { 21 super(PdfName.COLLECTIONITEM); 22 this.schema = schema; 23 } 24 25 29 public void addItem(String key, String value) { 30 PdfName fieldname = new PdfName(key); 31 PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); 32 put(fieldname, field.getValue(value)); 33 } 34 35 39 public void addItem(String key, PdfString value) { 40 PdfName fieldname = new PdfName(key); 41 PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); 42 if (field.type == PdfCollectionField.TEXT) { 43 put(fieldname, value); 44 } 45 } 46 47 51 public void addItem(String key, PdfDate d) { 52 PdfName fieldname = new PdfName(key); 53 PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); 54 if (field.type == PdfCollectionField.DATE) { 55 put(fieldname, d); 56 } 57 } 58 59 63 public void addItem(String key, PdfNumber n) { 64 PdfName fieldname = new PdfName(key); 65 PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); 66 if (field.type == PdfCollectionField.NUMBER) { 67 put(fieldname, n); 68 } 69 } 70 71 75 public void addItem(String key, Calendar c) { 76 addItem(key, new PdfDate(c)); 77 } 78 79 83 public void addItem(String key, int i) { 84 addItem(key, new PdfNumber(i)); 85 } 86 87 91 public void addItem(String key, float f) { 92 addItem(key, new PdfNumber(f)); 93 } 94 95 99 public void addItem(String key, double d) { 100 addItem(key, new PdfNumber(d)); 101 } 102 103 108 public void setPrefix(String key, String prefix) { 109 PdfName fieldname = new PdfName(key); 110 PdfObject o = get(fieldname); 111 if (o == null) 112 throw new IllegalArgumentException ("You must set a value before adding a prefix."); 113 PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM); 114 dict.put(PdfName.D, o); 115 dict.put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE)); 116 put(fieldname, dict); 117 } 118 } | Popular Tags |