KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > SVGTemplatePrinter


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 /*
15  * Created on 2004-jan-26
16  *
17  * Class used as a help tool when creating hard token visual layout templates
18  */

19 package org.ejbca.ui.cli;
20
21 import java.io.FileInputStream JavaDoc;
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import org.ejbca.core.model.ra.UserDataVO;
28 import org.ejbca.util.PrinterManager;
29
30 /**
31  * @author philip
32  *
33  * Class used as a help tool when creating hard token visual layout templates
34  * @version $Id: SVGTemplatePrinter.java,v 1.5 2006/11/02 08:03:22 anatom Exp $
35  */

36 public class SVGTemplatePrinter {
37
38     
39     private static final String JavaDoc USERDATAFILENAME = "src/cli/svgtemplateprinttester.properties";
40     
41     final private UserDataVO userdata;
42     final private String JavaDoc[] pins = new String JavaDoc[2];
43     final private String JavaDoc[] puks = new String JavaDoc[2];
44     final private String JavaDoc hardtokensn;
45     final private String JavaDoc copyofhardtokensn;
46     final private int validity;
47     final private String JavaDoc hardtokensnprefix;
48     final private String JavaDoc templatefilename;
49     final private String JavaDoc printername;
50     
51     public SVGTemplatePrinter(String JavaDoc templatefilename, String JavaDoc printername) throws FileNotFoundException JavaDoc, IOException JavaDoc{
52         this.templatefilename = templatefilename;
53         this.printername = printername;
54         
55         Properties JavaDoc data = new Properties JavaDoc();
56         data.load(new FileInputStream JavaDoc(USERDATAFILENAME));
57                         
58         userdata = new UserDataVO("", data.getProperty("DN"),0,"", data.getProperty("EMAIL"),
59                                                            0,0,0,0, (Date JavaDoc) null, (Date JavaDoc) 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 JavaDoc{
77         
78         FileInputStream JavaDoc fis = new FileInputStream JavaDoc(templatefilename);
79         byte[] data = new byte[fis.available()];
80         fis.read(data);
81         String JavaDoc sVGData = new String JavaDoc(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 JavaDoc[] args) throws Exception JavaDoc {
92         boolean noargmatch = true;
93                 
94         if(args.length == 1 && args[0].equalsIgnoreCase("listprinters")){
95             String JavaDoc[] 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 JavaDoc 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