10 |
|
/** |
11 |
|
* Provides a feed to the webpage system. |
12 |
|
* |
13 |
+ |
* !! still needs a routine to "maintain" alerts !! |
14 |
+ |
* |
15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
17 |
|
*/ |
41 |
|
|
42 |
|
private WebFeeder() { |
43 |
|
// do something, or nothing.. but must be private |
42 |
– |
// need to clean up all the alerts |
44 |
|
// don't need to cleanup latest data |
45 |
+ |
|
46 |
+ |
// -- cleanup old alerts |
47 |
+ |
// get config proxy |
48 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
49 |
+ |
// get file locations |
50 |
+ |
String rootPath, alertSubDir, alertFileName; |
51 |
+ |
try { |
52 |
+ |
// work out where things are |
53 |
+ |
rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath"); |
54 |
+ |
alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir"); |
55 |
+ |
File alerts = new File(rootPath+"/"+alertSubDir); |
56 |
+ |
File[] contents = alerts.listFiles(); |
57 |
+ |
for(int i=0; i < contents.length; i++) { |
58 |
+ |
contents[i].delete(); |
59 |
+ |
} |
60 |
+ |
// cleanup complete |
61 |
+ |
_logger.write(this.toString(), Logger.DEBUG, "Deleted "+contents.length+" files or directories from: "+rootPath+"/"+alertSubDir); |
62 |
+ |
} catch (PropertyNotFoundException e) { |
63 |
+ |
_logger.write(this.toString(), Logger.ERROR, "Failed to cleanup on construction, due to failing to get config for Alert Data: "+e); |
64 |
+ |
// just leave it at that |
65 |
+ |
} |
66 |
|
} |
67 |
|
|
68 |
|
//---PUBLIC METHODS--- |
158 |
|
String hostname = alert.getSource(); |
159 |
|
// set paths |
160 |
|
String destDir = rootPath+"/"+alertSubDir+"/"+hostname; |
161 |
+ |
File outDir = new File(destDir); |
162 |
|
String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime()); |
163 |
+ |
File outFile; |
164 |
+ |
// check if we're at a special "end case" (OK or FINAL) |
165 |
+ |
if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) { |
166 |
+ |
File oldFile = new File(destFile); |
167 |
+ |
outFile = new File(destFile+Alert.alertLevels[alert.getLevel()]); |
168 |
+ |
if(!oldFile.renameTo(outFile)) { |
169 |
+ |
_logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath()); |
170 |
+ |
} |
171 |
+ |
} else { |
172 |
+ |
outFile = new File(destFile); |
173 |
+ |
} |
174 |
|
// try to create directory |
141 |
– |
File outDir = new File(destDir); |
175 |
|
if(!outDir.exists()) { |
176 |
|
if(!outDir.mkdirs()) { |
177 |
|
// didn't exist, and we couldn't make it |
181 |
|
} |
182 |
|
} |
183 |
|
// directory has been made, check file exists |
151 |
– |
File outFile = new File(destFile); |
184 |
|
if(!outFile.exists()) { |
185 |
|
try { |
186 |
|
outFile.createNewFile(); |