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 TangDateComicsSystem extends ComicsSystem 40 { 41 static String filetypes[] = new String [] {".gif", ".png", ".jpg"}; 42 static String suffixes[] = new String [] {"", "a", "b", "c", "d", "e", "f", "g", "h", "i"}; 43 static SimpleDateFormat currFormatter = new SimpleDateFormat ("yyyy-MM-dd"); 44 45 public void update(String arguments[]) 46 { 47 try 48 { 49 String 50 prefix = arguments[1], 51 dateFormat = "", 52 suffix = ""; 53 54 if (arguments.length >= 3)dateFormat = arguments[2]; 55 if (arguments.length >= 4)suffix = arguments[3]; 56 57 SimpleDateFormat formatter = new SimpleDateFormat (dateFormat); 58 59 64 Calendar c = Calendar.getInstance(); 65 { 66 int 68 y = c.get(Calendar.YEAR), 69 m = c.get(Calendar.MONTH), 70 d = c.get(Calendar.DATE); 71 c.clear(); 72 c.add(Calendar.DATE, 1); 73 c.set(y, m, d); 74 } 75 Date 76 today = c.getTime(), 77 curr; 78 79 curr = currFormatter.parse(comic.position); 80 c.setTime(curr); 81 c.add(Calendar.DATE, 1); 82 curr = c.getTime(); 83 84 int count = 0; 85 86 while (curr.getTime() < today.getTime()) 88 { 89 suffixes: for (int j = 0; j < suffixes.length; j++) 90 { 91 for (int i = 0; i < filetypes.length; i++) 92 { 93 URL url = new URL (prefix+formatter.format(curr)+suffix+suffixes[j]+filetypes[i]); 94 95 if (URLExists(url)) 96 { 97 if (!debug) 98 { 99 log("! "); 100 cmgr.addStrip(new Strip(comic.ID, url.toString(), new java.sql.Date (curr.getTime()), formatter.format(curr)+suffixes[j], formatter.format(curr)+suffixes[j])); 101 } 102 else 103 logln(url.toString()); 104 105 count++; 106 comic = cmgr.getComic(comic.ID); 107 comic.position = currFormatter.format(curr); 108 109 if (!debug) 110 cmgr.changeComic(comic); 111 112 if (j == 0) 113 break suffixes; 114 115 break; 116 } 117 else 118 { 119 log(". "); 120 121 if (j == 1 && i == filetypes.length-1) break suffixes; 123 } 124 } 125 } 126 127 c.add(Calendar.DATE, 1); 128 curr = c.getTime(); 129 } 130 131 log(count+" strips added in "+comic.name); 132 } 133 catch (Exception e) 134 { 135 e.printStackTrace(new java.io.PrintWriter (out)); 136 } 137 } 138 } | Popular Tags |