KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mod > plugin > filewriter > FileWriterPlugin


1 package net.javacoding.jspider.mod.plugin.filewriter;
2
3 import net.javacoding.jspider.core.logging.Log;
4 import net.javacoding.jspider.core.logging.LogFactory;
5 import net.javacoding.jspider.core.util.config.ConfigurationFactory;
6 import net.javacoding.jspider.core.util.config.PropertySet;
7 import net.javacoding.jspider.mod.plugin.FlatOutputPlugin;
8
9 import java.io.*;
10 import java.util.Date JavaDoc;
11
12
13 /**
14  *
15  * $Id: FileWriterPlugin.java,v 1.7 2003/04/02 20:55:37 vanrogu Exp $
16  *
17  * @author Günther Van Roey
18  */

19 public class FileWriterPlugin extends FlatOutputPlugin {
20
21     public static final String JavaDoc MODULE_NAME = "File writer JSpider plugin";
22     public static final String JavaDoc MODULE_VERSION = "v1.0";
23     public static final String JavaDoc MODULE_DESCRIPTION = "A simple JSpider module that writes down all jobs carried out by the JSpider in a file";
24     public static final String JavaDoc MODULE_VENDOR = "http://www.javacoding.net";
25
26     public static final String JavaDoc FILENAME = "filename";
27     public static final String JavaDoc DEFAULT_FILENAME = "filewriter.out";
28
29     protected Log log;
30
31     protected String JavaDoc fileName;
32
33     protected PrintWriter pw;
34
35     public FileWriterPlugin ( PropertySet config ) {
36         log = LogFactory.getLog ( FileWriterPlugin.class );
37         fileName = config.getString(FILENAME, DEFAULT_FILENAME );
38         log.info("Writing to file: " + fileName );
39     }
40
41
42     public String JavaDoc getName() {
43         return MODULE_NAME;
44     }
45
46     public String JavaDoc getVersion() {
47         return MODULE_VERSION;
48     }
49
50     public String JavaDoc getDescription() {
51         return MODULE_DESCRIPTION;
52     }
53
54     public String JavaDoc getVendor() {
55         return MODULE_VENDOR;
56     }
57
58     protected void setUp() {
59         try {
60           pw = new PrintWriter ( new OutputStreamWriter ( new FileOutputStream(new File(ConfigurationFactory.getConfiguration().getDefaultOutputFolder(),fileName) ) ) );
61           log.debug("Opened file : " + fileName );
62         } catch (FileNotFoundException e) {
63           log.error("Error opening file " + fileName, e );
64         }
65     }
66
67     protected void println ( Object JavaDoc object ) {
68         pw.println ( "[" + new Date JavaDoc ( ) + "] " + object );
69     }
70
71     protected void tearDown() {
72         log.debug("Closing file...");
73         pw.close ( );
74         log.debug("Shutdown.");
75     }
76 }
77
Popular Tags