1 13 14 19 package org.ejbca.ui.cli; 20 21 import java.io.FileInputStream ; 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.util.Date ; 25 import java.util.Properties ; 26 27 import org.ejbca.core.model.ra.UserDataVO; 28 import org.ejbca.util.PrinterManager; 29 30 36 public class SVGTemplatePrinter { 37 38 39 private static final String USERDATAFILENAME = "src/cli/svgtemplateprinttester.properties"; 40 41 final private UserDataVO userdata; 42 final private String [] pins = new String [2]; 43 final private String [] puks = new String [2]; 44 final private String hardtokensn; 45 final private String copyofhardtokensn; 46 final private int validity; 47 final private String hardtokensnprefix; 48 final private String templatefilename; 49 final private String printername; 50 51 public SVGTemplatePrinter(String templatefilename, String printername) throws FileNotFoundException , IOException { 52 this.templatefilename = templatefilename; 53 this.printername = printername; 54 55 Properties data = new Properties (); 56 data.load(new FileInputStream (USERDATAFILENAME)); 57 58 userdata = new UserDataVO("", data.getProperty("DN"),0,"", data.getProperty("EMAIL"), 59 0,0,0,0, (Date ) null, (Date ) null,0,0 ,null); 60 61 pins[0] = data.getProperty("PIN1"); 62 pins[1] = data.getProperty("PIN2"); 63 64 65 puks[0] = data.getProperty("PUK1"); 66 puks[1] = data.getProperty("PUK2"); 67 68 copyofhardtokensn = data.getProperty("COPYOFHARDTOKENSN"); 69 hardtokensn = data.getProperty("HARDTOKENSN"); 70 71 validity = Integer.parseInt(data.getProperty("VALIDITY")); 72 hardtokensnprefix = data.getProperty("HARDTOKENSNPREFIX"); 73 74 75 } 76 public void print() throws Exception { 77 78 FileInputStream fis = new FileInputStream (templatefilename); 79 byte[] data = new byte[fis.available()]; 80 fis.read(data); 81 String sVGData = new String (data,"UTF8"); 82 83 PrinterManager.print(printername, templatefilename, sVGData, 1, validity, userdata, pins, puks, hardtokensnprefix, hardtokensn, copyofhardtokensn); 84 85 86 } 87 88 89 90 91 public static void main(String [] args) throws Exception { 92 boolean noargmatch = true; 93 94 if(args.length == 1 && args[0].equalsIgnoreCase("listprinters")){ 95 String [] printerNames = PrinterManager.listPrinters(); 96 97 System.out.println("\n Found " + printerNames.length + " printers:"); 98 for(int i=0;i<printerNames.length;i++){ 99 System.out.println(" " + printerNames[i]); 100 } 101 102 noargmatch = false; 103 } 104 105 if(args.length > 0 && args[0].equalsIgnoreCase("print")){ 106 if(args.length != 3 ){ 107 System.out.println("Usage: svgprinttest print <templatefilename> <printername> "); 108 System.out.println("User data is configured in " + USERDATAFILENAME); 109 System.exit(-1); 110 } 111 112 try{ 113 SVGTemplatePrinter printtester = new SVGTemplatePrinter(args[1], args[2]); 114 printtester.print(); 115 }catch(Exception e){ 116 117 System.out.println("Error:" + e.getMessage()); 118 e.printStackTrace(); 119 } 120 121 noargmatch = false; 122 } 123 124 125 if(noargmatch){ 126 System.out.println("Usage: svgprinttest print | listprinters "); 127 System.out.println("User data is configured in " + USERDATAFILENAME); 128 System.exit(-1); 129 } 130 131 } 132 133 134 } 135 | Popular Tags |