Uh oh!
There was an error while loading. Please reload this page.
forked from gihanjayatilaka/Motify
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSSHandling.java
More file actions
Latest commit
84 lines (73 loc) · 3.15 KB
/
Copy pathRSSHandling.java
File metadata and controls
84 lines (73 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
importjavax.xml.parsers.DocumentBuilderFactory;
importjavax.xml.parsers.ParserConfigurationException;
importjavax.xml.parsers.DocumentBuilder;
importorg.w3c.dom.Document;
importorg.w3c.dom.NodeList;
importorg.w3c.dom.Node;
importorg.w3c.dom.Element;
importjava.io.File;
importjava.io.FileOutputStream;
importjava.net.URL;
importjava.nio.channels.Channels;
importjava.nio.channels.ReadableByteChannel;
importjava.util.ArrayList;
importjava.util.Collections;
publicclassRSSHandling {
publicstaticNodeListgetNodeList(FilefileName,StringtagName) throwsException{
DocumentBuilderFactorydbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderdBuilder=dbFactory.newDocumentBuilder();
Documentdoc=dBuilder.parse(fileName);
doc.getDocumentElement().normalize();
NodeListnodeList=doc.getElementsByTagName(tagName);
returnnodeList;
}
publicstaticArrayList<NotificationUpdate> getNotificationArrayList(NodeListnodeList){
ArrayList<NotificationUpdate> listOfNotifications=newArrayList<NotificationUpdate>();
for(intx=0;x<nodeList.getLength();x++){
NodethisNode=nodeList.item(x);
if(thisNode.getNodeType()==javax.xml.soap.Node.ELEMENT_NODE){
ElementthisElement=(Element) thisNode;
NotificationUpdatethisNotification=newNotificationUpdate(thisElement.getElementsByTagName("pubDate").item(0).getTextContent(),thisElement.getElementsByTagName("title").item(0).getTextContent(),thisElement.getElementsByTagName("link").item(0).getTextContent(),thisElement.getElementsByTagName("description").item(0).getTextContent());
listOfNotifications.add(thisNotification);
}
}
returnlistOfNotifications;
}
publicstaticArrayList<NotificationUpdate> mergeTwoArrayLists(ArrayList<NotificationUpdate> arrayList1,ArrayList<NotificationUpdate> arrayList2){
ArrayList<NotificationUpdate> newArrayList=newArrayList<NotificationUpdate>();
newArrayList.addAll(arrayList1);
newArrayList.addAll(arrayList2);
Collections.sort(newArrayList);
returnnewArrayList;
}
publicstaticvoiddownloadRSS(String[] urlArray){
for(intx=0;x<urlArray.length;x++){
try{
URLurlToDownload=newURL(urlArray[x]);
ReadableByteChannelin=Channels.newChannel(urlToDownload.openStream());
FileOutputStreamout=newFileOutputStream("rssFile"+x+".xml");
out.getChannel().transferFrom(in, 0, Long.MAX_VALUE);
}
catch(Exceptione){
//
};
}
}
publicstaticArrayList<NotificationUpdate> getArrayForAllRSSLinks(String[] rssLinks) throwsException{
ArrayList<NotificationUpdate> answer=newArrayList<NotificationUpdate>();
downloadRSS(rssLinks);
for(intx=0;x<rssLinks.length;x++){
Filefile=newFile("rssFile"+x+".xml");
ArrayList<NotificationUpdate> thisRSSUpdateSet=getNotificationArrayList(getNodeList(file,"item"));
answer=mergeTwoArrayLists(answer,thisRSSUpdateSet);
}
returnanswer;
}
publicstaticArrayList<NotificationUpdate> getArrayForAllRSSLinks(ArrayList<String> rsslinksArrayList) throwsException{
String[] rssLinks=newString[rsslinksArrayList.size()];
for(intx=0;x<rsslinksArrayList.size();x++){
rssLinks[x]=rsslinksArrayList.get(x);
}
returngetArrayForAllRSSLinks(rssLinks);
}
}