|
@@ -11,16 +11,20 @@ import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
|
import org.w3c.dom.DOMException;
|
|
|
import org.w3c.dom.Document;
|
|
|
-import org.w3c.dom.NamedNodeMap;
|
|
|
import org.w3c.dom.Node;
|
|
|
import org.w3c.dom.NodeList;
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
|
-import data.ISPDAO;
|
|
|
import main.Bot;
|
|
|
import main.Main;
|
|
|
|
|
|
+/**
|
|
|
+ * Cette classe verifie si il y a de nouveaux articles sur le flux RSS.
|
|
|
+ * Dans ce cas, il les affiche et les met en mémoire pour l'action +RSS
|
|
|
+ * @author marmat
|
|
|
+ */
|
|
|
public class RSSChecker implements Runnable {
|
|
|
+
|
|
|
|
|
|
private Thread thread;
|
|
|
private final String threadName="RssChecker";
|
|
@@ -31,14 +35,16 @@ public class RSSChecker implements Runnable {
|
|
|
private Date lastarticle = new Date(); //last info
|
|
|
public static final SimpleDateFormat DATE_FORMATIN = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
|
|
private Bot b;
|
|
|
+ private volatile RssDataRemainder remainder;
|
|
|
|
|
|
public RSSChecker() {
|
|
|
- this.rssaddr="";
|
|
|
+ this("",null);
|
|
|
}
|
|
|
|
|
|
public RSSChecker(String address, Bot b) {
|
|
|
this.rssaddr = address;
|
|
|
this.b=b;
|
|
|
+ this.remainder = b.getRssdata();
|
|
|
}
|
|
|
|
|
|
public void start() {
|
|
@@ -50,8 +56,8 @@ public class RSSChecker implements Runnable {
|
|
|
|
|
|
|
|
|
private void afficheArticle(Node article, String date) {
|
|
|
- NodeList nl = article.getChildNodes();
|
|
|
RssData rssdata = new RssData(article);
|
|
|
+ remainder.push(rssdata);
|
|
|
rssdata.setDate(date);
|
|
|
b.sendMessagesOnAllChannels(rssdata.toStringIRC());
|
|
|
|
|
@@ -79,8 +85,10 @@ public class RSSChecker implements Runnable {
|
|
|
if(!istherenews) {
|
|
|
istherenews=true;
|
|
|
b.sendMessageOnAllChannels("Nouveautée sur planet.ffdn.org:");
|
|
|
+
|
|
|
}
|
|
|
afficheArticle(article,Main.DATE_FORMAT_OUT.format(date));
|
|
|
+ remainder.push(new RssData(article));
|
|
|
lastarticle = date;
|
|
|
}
|
|
|
} catch (DOMException | ParseException e) {
|
|
@@ -91,11 +99,20 @@ public class RSSChecker implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public RssDataRemainder getRemainder() {
|
|
|
+ return remainder;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRemainder(RssDataRemainder remainder) {
|
|
|
+ this.remainder = remainder;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void run() {
|
|
|
if(Main.isDebug()) {
|
|
|
System.out.println(this.threadName+" lancé sur "+rssaddr);
|
|
|
}
|
|
|
+ boolean firstRun = true;
|
|
|
do {
|
|
|
if(Main.isDebug()) {
|
|
|
System.out.println("Parsing du RSS "+rssaddr);
|
|
@@ -105,10 +122,9 @@ public class RSSChecker implements Runnable {
|
|
|
try {
|
|
|
db = docbfact.newDocumentBuilder();
|
|
|
} catch (ParserConfigurationException e1) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
+ b.sendMessageToAdmins("Erreur lors de la creation du document Builder dans RSSChecker.run()");
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
- ISPDAO idao = ISPDAO.getInstance();
|
|
|
try {
|
|
|
doc = db.parse(rssaddr);
|
|
|
} catch (SAXException | IOException e1) {
|
|
@@ -116,7 +132,12 @@ public class RSSChecker implements Runnable {
|
|
|
}
|
|
|
if(doc!=null) {
|
|
|
NodeList nl = doc.getElementsByTagName("entry");
|
|
|
+ if(firstRun) {
|
|
|
+ initRemainder(nl);
|
|
|
+ }
|
|
|
workOnEntry(nl);
|
|
|
+ }else {
|
|
|
+ b.sendMessageToAdmins("Erreur au parsing du RSS");
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -124,11 +145,20 @@ public class RSSChecker implements Runnable {
|
|
|
} catch (InterruptedException e) {
|
|
|
System.err.println(this.threadName+" à été arrété");
|
|
|
}
|
|
|
+ firstRun=false;
|
|
|
}while(!end);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void initRemainder(NodeList nl) {
|
|
|
+ int len = nl.getLength();
|
|
|
+ for(int i=len-1; i>=0;--i) {
|
|
|
+ RssData data = new RssData(nl.item(i));
|
|
|
+ remainder.push(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public String getRssaddr() {
|
|
|
return rssaddr;
|