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.1 by tdb, Wed Mar 7 01:55:51 2001 UTC vs.
Revision 1.4 by tdb, Thu Mar 8 21:37:39 2001 UTC

# Line 5 | Line 5 | package uk.ac.ukc.iscream.client;
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.
# Line 52 | Line 53 | public class WebFeeder {
53      // that to a file.
54      
55      public void receiveXMLPacket(XMLPacket packet) {
56 <        // process and save
56 >        String packetType = packet.getParam("packet.attributes.type");
57 >        if(packetType == null || !packetType.equals("data")) {
58 >            // bail out, without warning
59 >            // this is probably a heartbeat or similar
60 >            return;
61 >        }
62 >        // get config proxy
63 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
64 >        // get file locations
65 >        String rootPath, latestSubDir, latestFileName;
66 >        try {
67 >            rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath");
68 >            latestSubDir = cp.getProperty("WebFeeder", "WebFeeder.latestSubDir");
69 >            latestFileName = cp.getProperty("WebFeeder", "WebFeeder.latestFileName");
70 >        } catch (PropertyNotFoundException e) {
71 >            _logger.write(this.toString(), Logger.ERROR, "Failed to get config for Latest Data: "+e);
72 >            // bail out
73 >            return;
74 >        }
75 >        // get raw data
76 >        String data = packet.printAll();
77 >        String hostname = packet.getParam("packet.attributes.machine_name");
78 >        // set paths
79 >        String destDir = rootPath+"/"+latestSubDir+"/"+hostname;
80 >        String destFile = destDir+"/"+latestFileName;
81 >        // try to create directory
82 >        File outDir = new File(destDir);
83 >        if(!outDir.exists()) {
84 >            if(!outDir.mkdirs()) {
85 >                // didn't exist, and we couldn't make it
86 >                _logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath());
87 >                // bail out
88 >                return;
89 >            }
90 >        }
91 >        // directory has been made, check file exists
92 >        File outFile = new File(destFile);
93 >        if(!outFile.exists()) {
94 >            try {
95 >                outFile.createNewFile();
96 >            } catch (IOException e) {
97 >                _logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e);
98 >                // bail out
99 >                return;
100 >            }
101 >        }
102 >        // file should now exist
103 >        if(outFile.canWrite()) {
104 >            PrintWriter out;
105 >            try {
106 >                out = new PrintWriter(new FileWriter(outFile));
107 >                out.println(data);
108 >                out.close();
109 >            } catch (IOException e) {
110 >                _logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e);
111 >            }
112 >        }
113 >        else {
114 >            _logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath());
115 >        }
116      }
117      
118      public void receiveAlert(Alert alert) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines