5 |
|
import uk.ac.ukc.iscream.componentmanager.*; |
6 |
|
import uk.ac.ukc.iscream.core.*; |
7 |
|
import uk.ac.ukc.iscream.util.*; |
8 |
+ |
import java.io.*; |
9 |
|
|
10 |
|
/** |
11 |
|
* Provides a feed to the webpage system. |
53 |
|
// that to a file. |
54 |
|
|
55 |
|
public void receiveXMLPacket(XMLPacket packet) { |
56 |
< |
// process and save |
56 |
> |
// get config proxy |
57 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
58 |
> |
// get file locations |
59 |
> |
String rootPath, latestSubDir, latestFileName; |
60 |
> |
try { |
61 |
> |
rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath"); |
62 |
> |
latestSubDir = cp.getProperty("WebFeeder", "WebFeeder.latestSubDir"); |
63 |
> |
latestFileName = cp.getProperty("WebFeeder", "WebFeeder.latestFileName"); |
64 |
> |
} catch (PropertyNotFoundException e) { |
65 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to get config for Latest Data: "+e); |
66 |
> |
// bail out |
67 |
> |
return; |
68 |
> |
} |
69 |
> |
// get raw data |
70 |
> |
String data = packet.printAll(); |
71 |
> |
String hostname = packet.getParam("packet.attributes.host_name"); |
72 |
> |
// set paths |
73 |
> |
String destDir = rootPath+"/"+latestSubDir+"/"+hostname; |
74 |
> |
String destFile = destDir+"/"+latestFileName; |
75 |
> |
// write data |
76 |
> |
File outDir = new File(destDir); |
77 |
> |
if(outDir.mkdirs()) { |
78 |
> |
File outFile = new File(destFile); |
79 |
> |
if(outFile.canWrite()) { |
80 |
> |
PrintWriter out; |
81 |
> |
try { |
82 |
> |
out = new PrintWriter(new FileWriter(outFile)); |
83 |
> |
out.println(data); |
84 |
> |
out.close(); |
85 |
> |
} catch (IOException e) { |
86 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); |
87 |
> |
} |
88 |
> |
} |
89 |
> |
else { |
90 |
> |
_logger.write(this.toString(), Logger.ERROR, "File not readable: "+outFile.getPath()); |
91 |
> |
} |
92 |
> |
} |
93 |
> |
else { |
94 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
95 |
> |
} |
96 |
|
} |
97 |
|
|
98 |
|
public void receiveAlert(Alert alert) { |