1 25 26 30 package net.killingar.forum.comics; 31 32 import net.killingar.forum.internal.Strip; 33 34 import java.net.URL ; 35 import java.text.SimpleDateFormat ; 36 import java.util.Calendar ; 37 import java.util.Date ; 38 39 public class DateComicsSystem extends ComicsSystem 40 { 41 static String filetypes[] = new String [] {".gif", ".png", ".jpg"}; 42 static SimpleDateFormat currFormatter = new SimpleDateFormat ("yyyy-MM-dd"); 43 44 public void update(String arguments[]) 45 { 46 try 47 { 48 String 49 prefix = arguments[1], 50 dateFormat = "", 51 suffix = ""; 52 53 if (arguments.length >= 3)dateFormat = arguments[2]; 54 if (arguments.length >= 4)suffix = arguments[3]; 55 56 SimpleDateFormat formatter = new SimpleDateFormat (dateFormat); 57 58 63 Calendar c = Calendar.getInstance(); 64 { 65 int 67 y = c.get(Calendar.YEAR), 68 m = c.get(Calendar.MONTH), 69 d = c.get(Calendar.DATE); 70 c.clear(); 71 c.add(Calendar.DATE, 1); 72 c.set(y, m, d); 73 } 74 Date 75 today = c.getTime(), 76 curr; 77 78 curr = currFormatter.parse(comic.position); 79 c.setTime(curr); 80 c.add(Calendar.DATE, 1); 81 curr = c.getTime(); 82 83 int count = 0; 84 85 87 while (curr.before(today)) 88 { 89 for (int i = 0; i < filetypes.length; i++) 90 { 91 URL url = new URL (prefix+formatter.format(curr)+suffix+filetypes[i]); 92 93 if (URLExists(url)) 94 { 95 if (!debug) 96 { 97 log("! "); 98 cmgr.addStrip(new Strip(comic.ID, url.toString(), new java.sql.Date (curr.getTime()), formatter.format(curr), formatter.format(curr))); 99 } 100 else 101 logln(url.toString()); 102 103 count++; 104 comic = cmgr.getComic(comic.ID); 105 comic.position = currFormatter.format(curr); 106 if (!debug) 107 cmgr.changeComic(comic); 108 break; 109 } 110 else 111 log(". "); 112 } 113 114 115 c.add(Calendar.DATE, 1); 116 curr = c.getTime(); 117 } 118 119 log(count+" strips added in "+comic.name); 120 } 121 catch (Exception e) 122 { 123 e.printStackTrace(new java.io.PrintWriter (out)); 124 } 125 } 126 } | Popular Tags |