1 package org.jical; 2 import java.io.ByteArrayInputStream ; 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.InputStream ; 6 7 import javax.xml.transform.Result ; 8 import javax.xml.transform.Source ; 9 import javax.xml.transform.Transformer ; 10 import javax.xml.transform.TransformerFactory ; 11 import javax.xml.transform.stream.StreamResult ; 12 import javax.xml.transform.stream.StreamSource ; 13 18 public class ShellRun { 19 20 public static final String VERSION = "1.4"; 21 22 public static void main(String args[]) { 23 29 if (args.length == 0 30 || args[0].equalsIgnoreCase("-help")) { 31 System.out.println( 32 "================================================================================\n"+ 33 "JICAL v"+VERSION+" SHELL INTERFACE. GDAY - GOOD START! YOU FOUND ME!\n"+ 34 "\n"+ 35 "Your Options:\n"+ 36 " -ical2fburl <calendarLocation> <fburl> <Organiser> <Email> <DaysForward>\n"+ 37 " -ical2jicalxml <calendarLocation> <Organiser> <Email> <DaysForward>\n"+ 38 " -ical2jicaldisplayxml <calendarLocation> <Organiser> <Email> <DaysForward> <timerange>\n"+ 39 " -xslt <calendarLocation> <Organiser> <Email> <xsl document> <DaysForward>\n"+ 40 " -xsltonly <xsl document> <xml document>\n"+ 41 "\n"+ 42 "Parameters explained:\n"+ 43 "<calendarLocation> - your iCal location\n"+ 44 " eg /home/sfg/evolution/local/Calendar/calendar.ics\n"+ 45 "<fburl> - the internet URL for this FBURL before the username.ifb file\n"+ 46 " eg http://www.eurekait.com/\n"+ 47 "<Organiser> - this is used to name the free busy file. (sfg.ifb)\n"+ 48 " eg sfg\n"+ 49 "<Email> - the organisers email address\n"+ 50 " eg sfg@eurekait.com\n"+ 51 "<DaysForwardOrDateRange> - how far into the future do we project repeat events\n"+ 52 " eg1: 180\n"+ 53 " eg2: 20021215153500-20021215164500 Date formats are reverse ccyyMMddHHMMss\n"+ 54 " in the form fromdate-todate with the dash showing the start of the new date.\n"+ 55 "<timerange> - If required, will only show events that fall within the time range\n"+ 56 " eg: 0730-1800 for 7:30am to 6:00pm \n"+ 57 "<xsl document> - The Stylesheet to translate the XML to something else\n"+ 58 " eg HTML\n"+ 59 "<xml document> - The xml to translate with the Stylesheet.\n"+ 60 "\n"+ 61 "Learn by example:\n"+ 62 "java -jar jical.jar -ical2fburl /home/sfg/evolution/local/Calendar/calendar.ics http://www.eurekait.com/ sfg sfg@eurekait.com 180 > /www/website.live/sfg.ifb\n"+ 63 "java -jar jical.jar -ical2jicalxml /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com 180 > /www/website.live/sfg.xml\n"+ 64 "java -jar jical.jar -xslt /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com xsl/htmllist.xsl 180 > /www/website.live/sfg-yag.html\n"+ 65 "java -jar jical.jar -xsltonly fred.xsl jicaldisplayonyl.xml > /www/website.live/sfg.svg\n"+ 66 "java -jar jical.jar -ical2jicaldisplayxml /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com 180 0630-2230 > /www/website.live/jicaldisplay.xml\n"+ 67 "================================================================================"); 68 } 69 else if (args[0].equalsIgnoreCase("-ical2fburl")) { 70 71 if (args.length != 6) { 72 System.err.println( 73 "Syntax is: -ical2fburl <calendarLocation> <FBURL> <Organiser> <Email> <DaysForwardOrDateRange>\n"+ 74 "Example:\n"+ 75 "java -jar jical.jar -ical2FBURL /home/sfg/evolution/local/Calendar/calendar.ics http://www.eurekait.com/ sfg sfg@eurekait.com 180 > /www/website.live/sfg.ifb"); 76 return; 77 } 78 ICalendarParser icp = new ICalendarParser(); 79 ICalendar ical = icp.parse(args[1]); 80 ical.setFBUrl(args[2]); 81 ical.setOrganizer(args[3]); 82 ical.setOrganizerEmail(args[4]); 83 try { 86 System.out.println(ical.getFBString(args[5])); 87 } 88 catch (Exception e) { 89 System.err.println(e); 90 e.printStackTrace(); 91 } 92 } 93 else if (args[0].equalsIgnoreCase("-ical2jicalxml")) { 94 95 if (args.length < 5) { 96 System.err.println( 97 "Syntax is: -ical2jicalxml <calendarLocation> <Organiser> <Email> <DaysForwardOrDateRange>\n"+ 98 "Example:\n"+ 99 "java -jar jical.jar -ical2jicalxml /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com 180 0630-2000 > /www/website.live/sfg.xml"); 100 return; 101 } 102 ICalendarParser icp = new ICalendarParser(); 103 ICalendar ical = icp.parse(args[1]); 104 ical.setOrganizer(args[2]); 105 ical.setOrganizerEmail(args[3]); 106 try { 109 if (args.length == 5) 110 System.out.println(ical.getJiCalXML(args[4], null )); 111 else 112 System.out.println(ical.getJiCalXML(args[4], args[5])); 113 } 114 catch (Exception e) { 115 System.err.println(e); 116 e.printStackTrace(); 117 } 118 } 119 else if (args[0].equalsIgnoreCase("-ical2jicaldisplayxml")) { 120 124 if (args.length < 5) { 125 System.err.println( 126 "Syntax is: -ical2jicaldisplayxml <calendarLocation> <Organiser> <Email> <DaysForwardOrDateRange> <timerange>\n"+ 127 "Example:\n"+ 128 "java -jar jical.jar -ical2jicaldisplayxml /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com 180 0630-1800 > /www/website.live/sfg-jicaldisplay.xml\n"+ 129 "Note - timerange is optional."); 130 return; 131 } 132 133 ICalendarParser icp = new ICalendarParser(); 134 ICalendar ical = icp.parse(args[1]); 135 ical.setOrganizer(args[2]); 136 ical.setOrganizerEmail(args[3]); 137 139 try { 140 if (args.length == 5) 141 System.out.println(ical.getJiCaldisplayXML(args[4], null )); 142 else 143 System.out.println(ical.getJiCaldisplayXML(args[4], args[5])); 144 145 } 146 catch (Exception e) { 147 System.err.println(e); 148 e.printStackTrace(); 149 } 150 } 151 else if (args[0].equalsIgnoreCase("-xslt")) { 152 153 if (args.length != 6) { 154 System.err.println( 155 "Syntax is: -xslt <calendarLocation> <Organiser> <Email> <DaysForwardOrDateRange> <xsl document>\n"+ 156 "Example:\n"+ 157 "java -jar jical.jar -xslt /home/sfg/evolution/local/Calendar/calendar.ics sfg sfg@eurekait.com 180 xsl/yag.xsl > /www/website.live/sfg-yag.html"); 158 return; 159 } 160 ICalendarParser icp = new ICalendarParser(); 161 ICalendar ical = icp.parse(args[1]); 162 ical.setOrganizer(args[2]); 163 ical.setOrganizerEmail(args[3]); 164 String xmlCalString = null; 167 try { 168 xmlCalString = ical.getJiCalXML(args[5], null); 169 } 170 catch (Exception e) { 171 System.err.println(e); 172 e.printStackTrace(); 173 } 174 try { 176 177 javax.xml.transform.TransformerFactory tFactory = 179 javax.xml.transform.TransformerFactory.newInstance(); 180 181 184 javax.xml.transform.Transformer transformer = tFactory.newTransformer 185 (new javax.xml.transform.stream.StreamSource (args[4])); 187 ByteArrayInputStream bais = new ByteArrayInputStream (xmlCalString.getBytes()); 190 transformer.transform 191 (new javax.xml.transform.stream.StreamSource (bais), new javax.xml.transform.stream.StreamResult (System.out) 194 ); 195 } 196 catch (Exception e) { 197 System.err.println("JiCal -xsl error in translation: " + e); 198 e.printStackTrace(); 199 } 200 } 201 else if (args[0].equalsIgnoreCase("-xsltonly")) { 202 203 if (args.length != 3) { 204 System.err.println( 205 "Syntax is: -xsltonly <xsl document> <xml input document>\n"+ 206 "Example:\n"+ 207 "java -jar jical.jar -xslt /www/website.live/jicaldisplay.xml xsl/svg.xsl > /www/website.live/sfg-yag.svg"); 208 return; 209 } 210 File styleFile = new File (args[1]); File dataFile = new File (args[2]); try { 213 InputStream dataStream = new FileInputStream (dataFile); 214 InputStream styleStream = new FileInputStream (styleFile); 215 Source data = new StreamSource (dataStream); 217 Source style = new StreamSource (styleStream); 218 Result output = new StreamResult (System.out); 219 Transformer xslt = TransformerFactory.newInstance().newTransformer(style); 221 xslt.transform(data, output); 222 } 223 catch (Exception e) { 224 System.err.println("JiCal -xsltonly error in translation: " + e); 225 e.printStackTrace(); 226 } 227 } 228 else { 229 System.out.println( 230 "================================================================================\n"+ 231 "JICAL v"+VERSION+" SHELL INTERFACE. GDAY - GOOD START! YOU FOUND ME!\n"+ 232 "Unfortunately, you got the option wrong. try -help for a list\n"+ 233 "================================================================================"); 234 } 235 } 236 } 237 238 | Popular Tags |