01: /*************************************************************************
02: * *
03: * EJBCA: The OpenSource Certificate Authority *
04: * *
05: * This software is free software; you can redistribute it and/or *
06: * modify it under the terms of the GNU Lesser General Public *
07: * License as published by the Free Software Foundation; either *
08: * version 2.1 of the License, or any later version. *
09: * *
10: * See terms of license at gnu.org. *
11: * *
12: *************************************************************************/package org.ejbca.ui.cli.hardtoken.importer;
13:
14: import java.io.BufferedReader;
15: import java.io.FileReader;
16: import java.io.IOException;
17: import java.util.Properties;
18:
19: import org.ejbca.core.model.hardtoken.HardTokenData;
20:
21: /**
22: * A abstract base class that should be used by all
23: * File based hard token data importers
24: *
25: * It have a protected field fileReader that can be used by
26: * the implementation of readHardTokenData()
27: *
28: * @author Philip Vendil 2007 apr 23
29: *
30: * @version $Id: FileReadHardTokenImporter.java,v 1.1 2007/04/24 13:03:21 herrvendil Exp $
31: */
32:
33: public abstract class FileReadHardTokenImporter implements
34: IHardTokenImporter {
35:
36: protected BufferedReader bufferedReader = null;
37:
38: /**
39: * Open up a text file and expecting the property "file" to point to
40: * the location of the input file.
41: * @see org.ejbca.ui.cli.hardtoken.importer.IHardTokenImporter#startImport(java.util.Properties)
42: * @throws IOException if file doesn't exist of the property FILE isnät set.
43: */
44: public void startImport(Properties props) throws IOException {
45: if (props.getProperty("file") == null) {
46: throw new IOException(
47: "Error: the property file pointing to the file to import isn't set.");
48: }
49:
50: bufferedReader = new BufferedReader(new FileReader(props
51: .getProperty("file")));
52: }
53:
54: /**
55: * @see org.ejbca.ui.cli.hardtoken.importer.IHardTokenImporter#readHardTokenData()
56: */
57: public abstract HardTokenData readHardTokenData()
58: throws IOException;
59:
60: /**
61: * Closes the file after completion.
62: *
63: * @see org.ejbca.ui.cli.hardtoken.importer.IHardTokenImporter#endImport()
64: */
65: public void endImport() throws IOException {
66: if (bufferedReader != null) {
67: bufferedReader.close();
68: }
69: }
70:
71: }
|