KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > hardtoken > profiles > HardTokenProfileWithReceipt


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 package org.ejbca.core.model.hardtoken.profiles;
15
16
17 import java.awt.print.Printable JavaDoc;
18 import java.awt.print.PrinterException JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.StringReader JavaDoc;
21
22 import org.ejbca.core.model.ra.UserDataVO;
23
24
25
26
27
28 /**
29  * HardTokenProfileWithReceipt is a basic class that should be inherited by all types
30  * of hardtokenprofiles that should have receipt functionality.
31  *
32  * @version $Id: HardTokenProfileWithReceipt.java,v 1.2 2006/01/26 14:17:58 anatom Exp $
33  */

34 public abstract class HardTokenProfileWithReceipt extends HardTokenProfileWithVisualLayout implements IReceiptSettings{
35         
36     
37     // Protected Constants
38
protected static final String JavaDoc RECEIPTTYPE = "receipttype";
39     protected static final String JavaDoc RECEIPTFILENAME = "receiptfilename";
40     protected static final String JavaDoc RECEIPTDATA = "receiptdata";
41     protected static final String JavaDoc RECEIPTCOPIES = "receiptcopies";
42     
43
44     private SVGImageManipulator receiptsvgimagemanipulator = null;
45             
46     // Default Values
47
public HardTokenProfileWithReceipt() {
48       super();
49       
50       setReceiptType(IReceiptSettings.RECEIPTTYPE_GENERAL);
51       setReceiptTemplateFilename("");
52       setNumberOfReceiptCopies(1);
53          
54       
55     }
56
57     // Public Methods mostly used by PrimeCard
58

59     
60     public void upgrade(){
61       // Perform upgrade functionality
62

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     /* (non-Javadoc)
79      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#getNumberOfReceiptCopies()
80      */

81     public int getNumberOfReceiptCopies() {
82         return ((Integer JavaDoc) data.get(RECEIPTCOPIES)).intValue();
83     }
84     /* (non-Javadoc)
85      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#getReceiptData()
86      */

87     public String JavaDoc getReceiptData() {
88         return (String JavaDoc) data.get(RECEIPTDATA);
89     }
90     /* (non-Javadoc)
91      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#getReceiptTemplateFilename()
92      */

93     public String JavaDoc getReceiptTemplateFilename() {
94         return (String JavaDoc) data.get(RECEIPTFILENAME);
95     }
96     /* (non-Javadoc)
97      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#getReceipttype()
98      */

99     public int getReceiptType() {
100         return ((Integer JavaDoc) data.get(RECEIPTTYPE)).intValue();
101     }
102     /* (non-Javadoc)
103      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#printReceipt(org.ejbca.core.model.ra.UserDataVO, java.lang.String[], java.lang.String[], java.lang.String, java.lang.String)
104      */

105     public Printable JavaDoc printReceipt(UserDataVO userdata, String JavaDoc[] pincodes,
106             String JavaDoc[] pukcodes, String JavaDoc hardtokensn, String JavaDoc copyoftokensn)
107             throws IOException JavaDoc, PrinterException JavaDoc {
108         Printable JavaDoc returnval = null;
109           
110             if(getReceiptData() != null){
111                 if(receiptsvgimagemanipulator == null)
112                     receiptsvgimagemanipulator = new SVGImageManipulator(new StringReader JavaDoc(getReceiptData()),
113                                                               getVisualValidity(),
114                                                               getHardTokenSNPrefix());
115                                                             
116               returnval = receiptsvgimagemanipulator.print(userdata, pincodes, pukcodes, hardtokensn, copyoftokensn);
117             }
118           
119           
120             return returnval;
121     }
122     /* (non-Javadoc)
123      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#setNumberOfReceiptCopies(int)
124      */

125     public void setNumberOfReceiptCopies(int copies) {
126           data.put(RECEIPTCOPIES, new Integer JavaDoc(copies));
127     }
128     /* (non-Javadoc)
129      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#setReceiptData(java.lang.String)
130      */

131     public void setReceiptData(String JavaDoc templatedata) {
132         data.put(RECEIPTDATA, templatedata);
133     }
134     /* (non-Javadoc)
135      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#setReceiptTemplateFilename(java.lang.String)
136      */

137     public void setReceiptTemplateFilename(String JavaDoc filename) {
138           data.put(RECEIPTFILENAME, filename);
139     }
140     /* (non-Javadoc)
141      * @see org.ejbca.core.model.hardtoken.hardtokenprofiles.IReceiptSettings#setReceipttype(int)
142      */

143     public void setReceiptType(int type) {
144         data.put(RECEIPTTYPE, new Integer JavaDoc(type));
145     }
146 }
147
Popular Tags