| 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 ; 11 12 13 19 public class FileWriterPlugin extends FlatOutputPlugin { 20 21 public static final String MODULE_NAME = "File writer JSpider plugin"; 22 public static final String MODULE_VERSION = "v1.0"; 23 public static final String MODULE_DESCRIPTION = "A simple JSpider module that writes down all jobs carried out by the JSpider in a file"; 24 public static final String MODULE_VENDOR = "http://www.javacoding.net"; 25 26 public static final String FILENAME = "filename"; 27 public static final String DEFAULT_FILENAME = "filewriter.out"; 28 29 protected Log log; 30 31 protected String 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 getName() { 43 return MODULE_NAME; 44 } 45 46 public String getVersion() { 47 return MODULE_VERSION; 48 } 49 50 public String getDescription() { 51 return MODULE_DESCRIPTION; 52 } 53 54 public String 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 object ) { 68 pw.println ( "[" + new Date ( ) + "] " + object ); 69 } 70 71 protected void tearDown() { 72 log.debug("Closing file..."); 73 pw.close ( ); 74 log.debug("Shutdown."); 75 } 76 } 77 | Popular Tags |