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.DecimalFormat ; 36 37 public class NumberedComicsSystem extends ComicsSystem 38 { 39 public void update(String arguments[]) 40 { 41 try 42 { 43 String 44 prefix = arguments[1], 45 minimumNumberOfDigits = "1", 46 suffix = ""; 47 48 String filetypes[] = new String [] {".gif", ".png", ".jpg"}; 49 50 long endPos = -1; 51 int skipTolerance = 0; 52 53 if (arguments.length >= 3)minimumNumberOfDigits = arguments[2]; 54 if (arguments.length >= 4)suffix = arguments[3].trim(); 55 if (arguments.length >= 5)endPos = Long.parseLong(arguments[4]); 56 if (arguments.length >= 6) 57 { 58 filetypes = getArguments(arguments[5], "\n\r ,"); 59 if (filetypes.length == 0) 60 filetypes = new String [] {""}; 61 } 62 if (arguments.length >= 7)skipTolerance = Integer.parseInt(arguments[6]); 63 64 69 long curr = Long.parseLong(comic.position)+1; 70 71 int count = 0; 72 73 75 URL url; 76 DecimalFormat formatter = new DecimalFormat ("#######################################################"); 77 formatter.setDecimalSeparatorAlwaysShown(false); 78 formatter.setMinimumIntegerDigits(Integer.parseInt(minimumNumberOfDigits)); 80 81 for (int skip = 0; skip <= skipTolerance; curr++) 82 { 84 if (endPos != -1 && curr >= endPos) 85 break; 86 87 skip++; 88 for (int i = 0; i < filetypes.length; i++) 89 { 90 url = new URL (prefix+formatter.format(curr)+suffix+filetypes[i]); 91 92 if (URLExists(url)) 93 { 94 if (!debug) 95 { 96 log("! "); 97 98 cmgr.addStrip(new Strip(comic.ID, url.toString(), new java.sql.Date (curr), Long.toString(curr), Long.toString(curr))); 99 } 100 else 101 logln(url.toString()); 102 103 comic = cmgr.getComic(comic.ID); 104 comic.position = Long.toString(curr); 105 if (!debug) 106 cmgr.changeComic(comic); 107 count++; 108 skip = 0; 109 break; 110 } 111 else 112 log(". "); 113 } 114 } 115 logln(count+" strips added in "+comic.name); 116 } 117 catch (Exception e) 118 { 119 e.printStackTrace(new java.io.PrintWriter (out)); 120 } 121 } 122 } | Popular Tags |