FileWriterPlugin.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.plugin.filewriter;
  2. import net.javacoding.jspider.core.logging.Log;
  3. import net.javacoding.jspider.core.logging.LogFactory;
  4. import net.javacoding.jspider.core.util.config.ConfigurationFactory;
  5. import net.javacoding.jspider.core.util.config.PropertySet;
  6. import net.javacoding.jspider.mod.plugin.FlatOutputPlugin;
  7. import java.io.*;
  8. import java.util.Date;
  9. /**
  10.  *
  11.  * $Id: FileWriterPlugin.java,v 1.7 2003/04/02 20:55:37 vanrogu Exp $
  12.  *
  13.  * @author G黱ther Van Roey
  14.  */
  15. public class FileWriterPlugin extends FlatOutputPlugin {
  16.     public static final String MODULE_NAME = "File writer JSpider plugin";
  17.     public static final String MODULE_VERSION = "v1.0";
  18.     public static final String MODULE_DESCRIPTION = "A simple JSpider module that writes down all jobs carried out by the JSpider in a file";
  19.     public static final String MODULE_VENDOR = "http://www.javacoding.net";
  20.     public static final String FILENAME = "filename";
  21.     public static final String DEFAULT_FILENAME = "filewriter.out";
  22.     protected Log log;
  23.     protected String fileName;
  24.     protected PrintWriter pw;
  25.     public FileWriterPlugin ( PropertySet config ) {
  26.         log = LogFactory.getLog ( FileWriterPlugin.class );
  27.         fileName = config.getString(FILENAME, DEFAULT_FILENAME );
  28.         log.info("Writing to file: " + fileName );
  29.     }
  30.     public String getName() {
  31.         return MODULE_NAME;
  32.     }
  33.     public String getVersion() {
  34.         return MODULE_VERSION;
  35.     }
  36.     public String getDescription() {
  37.         return MODULE_DESCRIPTION;
  38.     }
  39.     public String getVendor() {
  40.         return MODULE_VENDOR;
  41.     }
  42.     protected void setUp() {
  43.         try {
  44.           pw = new PrintWriter ( new OutputStreamWriter ( new FileOutputStream(new File(ConfigurationFactory.getConfiguration().getDefaultOutputFolder(),fileName) ) ) );
  45.           log.debug("Opened file : " + fileName );
  46.         } catch (FileNotFoundException e) {
  47.           log.error("Error opening file " + fileName, e );
  48.         }
  49.     }
  50.     protected void println ( Object object ) {
  51.         pw.println ( "[" + new Date ( ) + "] " + object );
  52.     }
  53.     protected void tearDown() {
  54.         log.debug("Closing file...");
  55.         pw.close ( );
  56.         log.debug("Shutdown.");
  57.     }
  58. }