ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java (file contents):
Revision 1.3 by tdb, Thu Mar 8 21:22:28 2001 UTC vs.
Revision 1.8 by tdb, Thu Mar 15 03:26:43 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client;
2 > package uk.org.iscream.client;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.componentmanager.*;
6 < import uk.ac.ukc.iscream.core.*;
7 < import uk.ac.ukc.iscream.util.*;
5 > import uk.org.iscream.componentmanager.*;
6 > import uk.org.iscream.core.*;
7 > import uk.org.iscream.util.*;
8   import java.io.*;
9  
10   /**
# Line 39 | Line 39 | public class WebFeeder {
39  
40      private WebFeeder() {
41          // do something, or nothing.. but must be private
42 +        // need to clean up all the alerts
43 +        // don't need to cleanup latest data
44      }
45  
46   //---PUBLIC METHODS---
# Line 53 | Line 55 | public class WebFeeder {
55      // that to a file.
56      
57      public void receiveXMLPacket(XMLPacket packet) {
58 +        String packetType = packet.getParam("packet.attributes.type");
59 +        if(packetType == null || !packetType.equals("data")) {
60 +            // bail out, without warning
61 +            // this is probably a heartbeat or similar
62 +            return;
63 +        }
64          // get config proxy
65          ConfigurationProxy cp = ConfigurationProxy.getInstance();
66          // get file locations
# Line 110 | Line 118 | public class WebFeeder {
118      }
119      
120      public void receiveAlert(Alert alert) {
121 <        // process and save
121 >        // get config proxy
122 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
123 >        // get file locations
124 >        String rootPath, alertSubDir, alertFileName;
125 >        try {
126 >            rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath");
127 >            alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir");
128 >            alertFileName = cp.getProperty("WebFeeder", "WebFeeder.alertFileName");
129 >        } catch (PropertyNotFoundException e) {
130 >            _logger.write(this.toString(), Logger.ERROR, "Failed to get config for Alert Data: "+e);
131 >            // bail out
132 >            return;
133 >        }
134 >        // get raw data
135 >        String data = alert.printAll();
136 >        String hostname = alert.getSource();
137 >        // set paths
138 >        String destDir = rootPath+"/"+alertSubDir+"/"+hostname;
139 >        String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
140 >        // try to create directory
141 >        File outDir = new File(destDir);
142 >        if(!outDir.exists()) {
143 >            if(!outDir.mkdirs()) {
144 >                // didn't exist, and we couldn't make it
145 >                _logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath());
146 >                // bail out
147 >                return;
148 >            }
149 >        }
150 >        // directory has been made, check file exists
151 >        File outFile = new File(destFile);
152 >        if(!outFile.exists()) {
153 >            try {
154 >                outFile.createNewFile();
155 >            } catch (IOException e) {
156 >                _logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e);
157 >                // bail out
158 >                return;
159 >            }
160 >        }
161 >        // file should now exist
162 >        if(outFile.canWrite()) {
163 >            PrintWriter out;
164 >            try {
165 >                out = new PrintWriter(new FileWriter(outFile));
166 >                out.println(data);
167 >                out.close();
168 >            } catch (IOException e) {
169 >                _logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e);
170 >            }
171 >        }
172 >        else {
173 >            _logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath());
174 >        }
175      }
176      
177      /**
178       * Overrides the {@link java.lang.Object#toString() Object.toString()}
179       * method to provide clean logging (every class should have this).
180       *
181 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
181 >     * This uses the uk.org.iscream.util.FormatName class
182       * to format the toString()
183       *
184       * @return the name of this class and its CVS revision

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines