--- projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java 2001/03/08 21:37:39 1.4 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java 2001/03/08 23:20:06 1.5 @@ -11,7 +11,7 @@ import java.io.*; * Provides a feed to the webpage system. * * @author $Author: tdb $ - * @version $Id: WebFeeder.java,v 1.4 2001/03/08 21:37:39 tdb Exp $ + * @version $Id: WebFeeder.java,v 1.5 2001/03/08 23:20:06 tdb Exp $ */ public class WebFeeder { @@ -20,7 +20,7 @@ public class WebFeeder { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.4 $"; + public static final String REVISION = "$Revision: 1.5 $"; //---STATIC METHODS--- @@ -116,7 +116,60 @@ public class WebFeeder { } public void receiveAlert(Alert alert) { - // process and save + // get config proxy + ConfigurationProxy cp = ConfigurationProxy.getInstance(); + // get file locations + String rootPath, alertSubDir, alertFileName; + try { + rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath"); + alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir"); + alertFileName = cp.getProperty("WebFeeder", "WebFeeder.alertFileName"); + } catch (PropertyNotFoundException e) { + _logger.write(this.toString(), Logger.ERROR, "Failed to get config for Alert Data: "+e); + // bail out + return; + } + // get raw data + String data = alert.printAll(); + String hostname = alert.getSource(); + // set paths + String destDir = rootPath+"/"+alertSubDir+"/"+hostname; + String destFile = destDir+"/"+alertFileName; + // try to create directory + File outDir = new File(destDir); + if(!outDir.exists()) { + if(!outDir.mkdirs()) { + // didn't exist, and we couldn't make it + _logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); + // bail out + return; + } + } + // directory has been made, check file exists + File outFile = new File(destFile); + if(!outFile.exists()) { + try { + outFile.createNewFile(); + } catch (IOException e) { + _logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e); + // bail out + return; + } + } + // file should now exist + if(outFile.canWrite()) { + PrintWriter out; + try { + out = new PrintWriter(new FileWriter(outFile)); + out.println(data); + out.close(); + } catch (IOException e) { + _logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); + } + } + else { + _logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath()); + } } /**