001: /*
002: * Created on 29-Oct-2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.jical;
008:
009: import java.io.BufferedReader;
010: import java.io.BufferedWriter;
011: import java.io.FileInputStream;
012: import java.io.FileWriter;
013: import java.io.InputStreamReader;
014: import java.text.SimpleDateFormat;
015: import java.util.Date;
016: import java.util.LinkedList;
017:
018: /**
019: * @author sfg
020: *
021: * TODO To change the template for this generated type comment go to
022: * Window - Preferences - Java - Code Style - Code Templates
023: */
024: public class SyslogICal {
025:
026: public static void main(String[] args) {
027:
028: SimpleDateFormat formatter = new SimpleDateFormat(
029: "yyyy:MM:dd HH:mm:ss");
030: SimpleDateFormat touchformatter = new SimpleDateFormat(
031: "yyyyMMddHHmm.ss");
032: SimpleDateFormat syslogformatter = new SimpleDateFormat(
033: "yyyy MMM dd HH:mm:ss");
034:
035: // Parameters
036: // 1 - input file - ie syslog
037: // 2 - output cal file.
038: // 3 - keyword to start event.
039: // 4 - keyword to stop event.
040: // 5 - Event Summary Line
041:
042: ICalendar iCal = new ICalendar();
043: iCal.icalEventCollection = new LinkedList();
044: iCal.setProdId("JICAL");
045: iCal.setVersion("2.0");
046: int iCtr = 0;
047:
048: try {
049: FileInputStream fin = new FileInputStream(args[0]);
050: BufferedReader myInput = null;
051:
052: myInput = new BufferedReader(new InputStreamReader(fin));
053: String buildLine = null;
054: String this Line = "";
055: Date startDate = null;
056: Date endDate = null;
057: /* Two loops, first joins lines together, second processes lines..
058: */
059: while ((this Line = myInput.readLine()) != null) {
060: // Parse the syslog. If the right one comes up, create an event.
061: // This is the bit where we create a VEVENT!
062: if (this Line.indexOf(args[2]) != -1) {
063: startDate = syslogformatter.parse("2004 "
064: + this Line.substring(0, 15));
065: System.out.println(this Line);
066: }
067:
068: if (this Line.indexOf(args[3]) != -1
069: && startDate != null) {
070: endDate = syslogformatter.parse("2004 "
071: + this Line.substring(0, 15));
072: System.out.println(this Line);
073: ICalendarVEvent vevent = new ICalendarVEvent();
074:
075: Date workDate = new Date();
076:
077: vevent.setDateStart(startDate);
078: vevent.setDateEnd(endDate);
079: vevent.setSummary(args[4]);
080: vevent.setDescription("");
081: vevent.setSequence(0);
082: vevent.setEventClass("PUBLIC");
083: vevent.setTransparency("OPAQUE");
084: vevent.setDateStamp(workDate);
085: vevent.setCreated(workDate);
086: vevent.setLastModified(workDate);
087: //vevent.setAttach(photoFile.toURL().toString());
088: vevent.setOrganizer("MAILTO:sfg@eurekait.com");
089: iCtr++;
090: //System.out.println(iCtr);
091: vevent.setUid("jical-"
092: + touchformatter.format(workDate) + "-"
093: + iCtr);
094: vevent.setPriority(3);
095:
096: //System.out.println(vevent.toVEvent());
097:
098: iCal.icalEventCollection.add(vevent);
099: startDate = null;
100: }
101:
102: }
103: } catch (Exception e) {
104: e.printStackTrace();
105: System.err.println("SomethingBad Happened:" + e);
106: }
107:
108: try {
109:
110: // Now write to string and view as file.
111: //System.out.println(iCal.getVCalendar());
112:
113: BufferedWriter out = new BufferedWriter(new FileWriter(
114: args[1]));
115: out.write(iCal.getVCalendar());
116: out.close();
117:
118: } catch (Exception e) {
119: e.printStackTrace();
120: System.err.println("SomethingBad Happened:" + e);
121: }
122:
123: //System.out.println("Rendered new SYSLOGICAL calendar file: "+args[1]);
124:
125: }
126: }
|