KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jical > SyslogICal


1 /*
2  * Created on 29-Oct-2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.jical;
8
9 import java.io.BufferedReader JavaDoc;
10 import java.io.BufferedWriter JavaDoc;
11 import java.io.FileInputStream JavaDoc;
12 import java.io.FileWriter JavaDoc;
13 import java.io.InputStreamReader JavaDoc;
14 import java.text.SimpleDateFormat JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.LinkedList JavaDoc;
17
18 /**
19  * @author sfg
20  *
21  * TODO To change the template for this generated type comment go to
22  * Window - Preferences - Java - Code Style - Code Templates
23  */

24 public class SyslogICal {
25
26     public static void main(String JavaDoc[] args) {
27         
28         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("yyyy:MM:dd HH:mm:ss");
29         SimpleDateFormat JavaDoc touchformatter = new SimpleDateFormat JavaDoc("yyyyMMddHHmm.ss");
30         SimpleDateFormat JavaDoc syslogformatter = new SimpleDateFormat JavaDoc("yyyy MMM dd HH:mm:ss");
31         
32         // Parameters
33
// 1 - input file - ie syslog
34
// 2 - output cal file.
35
// 3 - keyword to start event.
36
// 4 - keyword to stop event.
37
// 5 - Event Summary Line
38

39         ICalendar iCal = new ICalendar();
40         iCal.icalEventCollection = new LinkedList JavaDoc();
41         iCal.setProdId("JICAL");
42         iCal.setVersion("2.0");
43         int iCtr = 0;
44
45         try
46         {
47             FileInputStream JavaDoc fin = new FileInputStream JavaDoc(args[0]);
48             BufferedReader JavaDoc myInput = null;
49             
50             myInput = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(fin));
51             String JavaDoc buildLine = null;
52             String JavaDoc thisLine = "";
53             Date JavaDoc startDate = null;
54             Date JavaDoc endDate = null;
55             /* Two loops, first joins lines together, second processes lines..
56              */

57             while((thisLine = myInput.readLine()) != null)
58             {
59                 // Parse the syslog. If the right one comes up, create an event.
60
// This is the bit where we create a VEVENT!
61
if (thisLine.indexOf(args[2]) != -1)
62                 {
63                     startDate = syslogformatter.parse("2004 "+thisLine.substring(0,15));
64                     System.out.println(thisLine);
65                 }
66                 
67                 if (thisLine.indexOf(args[3]) != -1
68                     && startDate != null)
69                 {
70                     endDate = syslogformatter.parse("2004 "+thisLine.substring(0,15));
71                     System.out.println(thisLine);
72                     ICalendarVEvent vevent = new ICalendarVEvent();
73                     
74                     Date JavaDoc workDate = new Date JavaDoc();
75                     
76                     vevent.setDateStart(startDate);
77                     vevent.setDateEnd(endDate);
78                     vevent.setSummary(args[4]);
79                     vevent.setDescription("");
80                     vevent.setSequence(0);
81                     vevent.setEventClass("PUBLIC");
82                     vevent.setTransparency("OPAQUE");
83                     vevent.setDateStamp(workDate);
84                     vevent.setCreated(workDate);
85                     vevent.setLastModified(workDate);
86                     //vevent.setAttach(photoFile.toURL().toString());
87
vevent.setOrganizer("MAILTO:sfg@eurekait.com");
88                     iCtr++;
89                     //System.out.println(iCtr);
90
vevent.setUid("jical-"+touchformatter.format(workDate)+"-"+iCtr);
91                     vevent.setPriority(3);
92                     
93                     //System.out.println(vevent.toVEvent());
94

95                     iCal.icalEventCollection.add(vevent);
96                     startDate = null;
97                 }
98             
99             }
100         }
101         catch(Exception JavaDoc e)
102         {
103             e.printStackTrace();
104             System.err.println("SomethingBad Happened:"+e);
105         }
106         
107         
108         try{
109
110         // Now write to string and view as file.
111
//System.out.println(iCal.getVCalendar());
112

113             BufferedWriter JavaDoc out = new BufferedWriter JavaDoc(new FileWriter JavaDoc(args[1]));
114             out.write(iCal.getVCalendar());
115             out.close();
116             
117         }
118         catch (Exception JavaDoc e)
119         {
120             e.printStackTrace();
121             System.err.println("SomethingBad Happened:"+e);
122         }
123         
124         //System.out.println("Rendered new SYSLOGICAL calendar file: "+args[1]);
125

126     }
127 }
128
Popular Tags