1 13 14 package org.ejbca.core.model.hardtoken.profiles; 15 16 17 import java.awt.print.Printable ; 18 import java.awt.print.PrinterException ; 19 import java.io.IOException ; 20 import java.io.StringReader ; 21 22 import org.ejbca.core.model.ra.UserDataVO; 23 24 25 26 27 28 34 public abstract class HardTokenProfileWithReceipt extends HardTokenProfileWithVisualLayout implements IReceiptSettings{ 35 36 37 protected static final String RECEIPTTYPE = "receipttype"; 39 protected static final String RECEIPTFILENAME = "receiptfilename"; 40 protected static final String RECEIPTDATA = "receiptdata"; 41 protected static final String RECEIPTCOPIES = "receiptcopies"; 42 43 44 private SVGImageManipulator receiptsvgimagemanipulator = null; 45 46 public HardTokenProfileWithReceipt() { 48 super(); 49 50 setReceiptType(IReceiptSettings.RECEIPTTYPE_GENERAL); 51 setReceiptTemplateFilename(""); 52 setNumberOfReceiptCopies(1); 53 54 55 } 56 57 59 60 public void upgrade(){ 61 63 if(data.get(RECEIPTTYPE) == null){ 64 setReceiptType(IReceiptSettings.RECEIPTTYPE_GENERAL); 65 } 66 if(data.get(RECEIPTFILENAME) == null){ 67 setReceiptTemplateFilename(""); 68 } 69 if(data.get(RECEIPTCOPIES) == null){ 70 setNumberOfReceiptCopies(1); 71 } 72 73 super.upgrade(); 74 } 75 76 77 78 81 public int getNumberOfReceiptCopies() { 82 return ((Integer ) data.get(RECEIPTCOPIES)).intValue(); 83 } 84 87 public String getReceiptData() { 88 return (String ) data.get(RECEIPTDATA); 89 } 90 93 public String getReceiptTemplateFilename() { 94 return (String ) data.get(RECEIPTFILENAME); 95 } 96 99 public int getReceiptType() { 100 return ((Integer ) data.get(RECEIPTTYPE)).intValue(); 101 } 102 105 public Printable printReceipt(UserDataVO userdata, String [] pincodes, 106 String [] pukcodes, String hardtokensn, String copyoftokensn) 107 throws IOException , PrinterException { 108 Printable returnval = null; 109 110 if(getReceiptData() != null){ 111 if(receiptsvgimagemanipulator == null) 112 receiptsvgimagemanipulator = new SVGImageManipulator(new StringReader (getReceiptData()), 113 getVisualValidity(), 114 getHardTokenSNPrefix()); 115 116 returnval = receiptsvgimagemanipulator.print(userdata, pincodes, pukcodes, hardtokensn, copyoftokensn); 117 } 118 119 120 return returnval; 121 } 122 125 public void setNumberOfReceiptCopies(int copies) { 126 data.put(RECEIPTCOPIES, new Integer (copies)); 127 } 128 131 public void setReceiptData(String templatedata) { 132 data.put(RECEIPTDATA, templatedata); 133 } 134 137 public void setReceiptTemplateFilename(String filename) { 138 data.put(RECEIPTFILENAME, filename); 139 } 140 143 public void setReceiptType(int type) { 144 data.put(RECEIPTTYPE, new Integer (type)); 145 } 146 } 147 | Popular Tags |