public void onDataSave(File dir) { ArrayList<String> lines = new ArrayList<String>(); for (Feed feed : feeds) { lines.add(feed.getURL().toString()); lines.add(Long.toString((feed.getDate() != null) ? feed.getDate().getTime() : 0L)); lines.add(Long.toString(feed.getInterval())); lines.add(StringTools.implode(feed.channels.toArray(new String[feed.channels.size()]), " ")); } FileLine.write(new File(dir, "rss.cfg"), lines); }
public void doCommand(Parameters params, CommandCallback callback) { String action = null; URL url = null; long interval = (5 * 60 * 1000); Channel c = null; callback.type = EType.Notice; try { if (params.type == EType.Channel) { if (params.tokenCount == 0) { c = params.channel; } else if (params.tokenCount == 1) { c = Shocky.getChannel(params.nextParam()); } else if (params.tokenCount == 2) { action = params.nextParam(); c = params.channel; url = new URL(params.nextParam()); } else if (params.tokenCount == 3) { action = params.nextParam(); String s = params.nextParam(); if (s.startsWith("#")) c = Shocky.getChannel(s); else { interval = Utils.parseInterval(s); c = params.channel; } url = new URL(params.nextParam()); } else if (params.tokenCount == 4) { action = params.nextParam(); interval = Utils.parseInterval(params.nextParam()); c = Shocky.getChannel(params.nextParam()); url = new URL(params.nextParam()); } if (c == null) { callback.append("No such channel"); return; } } else { if (params.tokenCount == 1) { c = Shocky.getChannel(params.nextParam()); } else if (params.tokenCount == 3) { action = params.nextParam(); c = Shocky.getChannel(params.nextParam()); url = new URL(params.nextParam()); } if (c == null) { callback.append("No such channel"); return; } } } catch (MalformedURLException e) { callback.append("Malformed URL"); return; } if (action != null) params.checkOp(); if (action == null) { StringBuffer sb = new StringBuffer(); for (Feed feed : feeds) { if (!feed.channels.contains(c.getName())) continue; if (sb.length() != 0) sb.append("\n"); sb.append(feed.getURL()).append(' ').append(Utils.timeAgo(feed.getInterval() / 1000)); } callback.append(sb); } else if (action.equals("add")) { for (Feed feed : feeds) { if (feed.getURL().equals(url)) { if (feed.channels.contains(c.getName())) { callback.append("Feed already on channel's list"); } else { feed.channels.add(c.getName()); callback.append("Added"); } return; } } if (interval < 300) interval = 300; interval *= 1000; feeds.add(new Feed(url, interval, null, c.getName())); callback.append("Added"); startUpdater(); } else if (action.equals("remove")) { Iterator<Feed> iter = feeds.iterator(); boolean modified = false; try { while (iter.hasNext()) { Feed feed = iter.next(); if (feed.getURL().equals(url)) { if (feed.channels.contains(c.getName())) { feed.channels.remove(feed.channels.indexOf(c.getName())); if (feed.channels.isEmpty()) { iter.remove(); modified = true; } callback.append("Removed"); } else callback.append("Feed isn't on channel's list"); return; } } callback.append("Feed isn't on channel's list"); } finally { if (modified) startUpdater(); } } }