Added JavaDoc
This commit is contained in:
parent
cc410b4848
commit
1ebd171c1b
9 changed files with 403 additions and 127 deletions
34
pom.xml
34
pom.xml
|
@ -8,7 +8,7 @@
|
|||
<artifactId>RSS-hf-maven</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
|
||||
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
|
@ -24,6 +24,13 @@
|
|||
<artifactId>plexus-utils</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
@ -54,13 +61,24 @@
|
|||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>eu.toldi.rss.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>eu.toldi.rss.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -12,15 +12,36 @@ import java.net.URISyntaxException;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Egy RSS hírcsatornán található cikk reprezentálására hsznált osztály.
|
||||
*/
|
||||
@XStreamAlias("article")
|
||||
public class Article {
|
||||
/**
|
||||
* A Cikk címe
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* A cíkk elérési útvonala
|
||||
*/
|
||||
@XStreamAlias("link")
|
||||
private String URL;
|
||||
/**
|
||||
* A cikkhez tartozó leírás
|
||||
*/
|
||||
@XStreamAlias("description")
|
||||
private String Description;
|
||||
/**
|
||||
* Cikkhez tartozó kép elérési útvonala
|
||||
*/
|
||||
private String imageURL;
|
||||
/**
|
||||
* A cikk szerzője
|
||||
*/
|
||||
private String author;
|
||||
/**
|
||||
* A cikk kiadásának dátuma
|
||||
*/
|
||||
private LocalDateTime pubDate;
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -35,7 +56,12 @@ public class Article {
|
|||
}
|
||||
|
||||
public Article(){}
|
||||
public Article(Node article,DateTimeFormatter formatter){
|
||||
|
||||
/**
|
||||
* Cikk beolvasása egy megadott Node objektumból. Egy hírcsatorna beolvasásakor könnyedén alkalmazható egy "item" Node-ra
|
||||
* @param article Egy "item" Node egy RSS hírcsatornáról
|
||||
*/
|
||||
public Article(Node article){
|
||||
NodeList properties = article.getChildNodes();
|
||||
for (int j = 0; j < properties.getLength(); j++) {
|
||||
Node node = properties.item(j);
|
||||
|
@ -49,7 +75,7 @@ public class Article {
|
|||
this.setAuthor(node.getTextContent());
|
||||
break;
|
||||
case "pubDate":
|
||||
this.setPubDate(LocalDateTime.parse(node.getTextContent(), formatter));
|
||||
this.setPubDate(LocalDateTime.parse(node.getTextContent(), DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
break;
|
||||
case "link":
|
||||
this.setURL(node.getTextContent());
|
||||
|
@ -67,55 +93,105 @@ public class Article {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cikk címének lekérése
|
||||
* @return a cikk címe
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cikk címének beállítása
|
||||
* @param title a cikk új címe
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikkre mutató link lekérése
|
||||
* @return a cikkre mutató link
|
||||
*/
|
||||
public String getURL() {
|
||||
return URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikkre mutató link beállítása
|
||||
* @param URL a cikkre mutató link
|
||||
*/
|
||||
public void setURL(String URL) {
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cikk leírásának lekérése
|
||||
* @return a cikk leírása
|
||||
*/
|
||||
public String getDescription() {
|
||||
return Description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cikk leírásának beállítása
|
||||
* @param description a cikk leírása
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
Description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikkhez tartózó kép címének lekérése
|
||||
* @return a cikkhez tartózó kép címe
|
||||
*/
|
||||
public String getImageURL() {
|
||||
return imageURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikkhez tartózó kép címének beállítása
|
||||
* @param imageURL a cikkhez tartózó kép címe
|
||||
*/
|
||||
public void setImageURL(String imageURL) {
|
||||
this.imageURL = imageURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikk írójának lekérése
|
||||
* @return a cikk írója
|
||||
*/
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikk írójának beállítása
|
||||
* @param author a cikk írója
|
||||
*/
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikk kiadásának dátumának lekérése
|
||||
* @return a cikk kiadásának dátuma
|
||||
*/
|
||||
public LocalDateTime getPubDate() {
|
||||
return pubDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* A cikk kiadási dátumának beállítása
|
||||
* @param pubDate acikk kiadási dátuma
|
||||
*/
|
||||
public void setPubDate(LocalDateTime pubDate) {
|
||||
this.pubDate = pubDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A cikk megnyitása böngészőben (ha ez lehetséges)
|
||||
*/
|
||||
public void open(){
|
||||
if(getURL() == null) return;
|
||||
Desktop desktop;
|
||||
|
|
|
@ -17,40 +17,75 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Egy RSS hírcsatorna reprezentálására használt osztály.
|
||||
*/
|
||||
@XStreamAlias("feed")
|
||||
public class Feed {
|
||||
/**
|
||||
* A hírcsatorna elérési útvonala
|
||||
*/
|
||||
private URL link;
|
||||
/**
|
||||
* A hírcsatorna neve
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* A hírcsatornához tartozó cikkek listája
|
||||
*/
|
||||
@XStreamAlias("articleList")
|
||||
private List<Article> articleList = null;
|
||||
private List<Article> articleList = new ArrayList<>();;
|
||||
|
||||
/**
|
||||
* A hírcsatorna nevének lekérése
|
||||
*
|
||||
* @return a hírcsatorna neve
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Feed(URL url) {
|
||||
/**
|
||||
* Hírcsatorna lézrehozása elérési útvonal alapján
|
||||
* @param url a hírcsatorna elérési útvonala
|
||||
* @throws IOException
|
||||
*/
|
||||
public Feed(URL url) throws IOException {
|
||||
articleList = new ArrayList<>();
|
||||
try {
|
||||
link = url;
|
||||
updateFeed();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
link = url;
|
||||
updateFeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna létrehozása név alapján
|
||||
* @param name a hírcsatorna neve
|
||||
*/
|
||||
public Feed(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* A hírcsatornán található cikkek számának lekérése
|
||||
* @return a hírcsatorna található cikkek száma
|
||||
*/
|
||||
public int getArticleCount() {
|
||||
return articleList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy adott helyen található cikk lekérése
|
||||
* @param i a cikk indexe
|
||||
* @return Az i. helyen található cikk
|
||||
*/
|
||||
public Article get(int i) {
|
||||
return articleList.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna frissítése.
|
||||
* Lekéri a hírcsatorna elérési útvonalán található összes új cikket és hozzáadja a cikkek listájához.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void updateFeed() throws IOException {
|
||||
URLConnection con = link.openConnection();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newDefaultInstance();
|
||||
|
@ -62,7 +97,7 @@ public class Feed {
|
|||
NodeList items = doc.getElementsByTagName("item");
|
||||
for (int i = 0; i < items.getLength(); i++) {
|
||||
Node article = items.item(i);
|
||||
Article a = new Article(article,DateTimeFormatter.RFC_1123_DATE_TIME);
|
||||
Article a = new Article(article);
|
||||
addArticle(a);
|
||||
}
|
||||
} catch (ParserConfigurationException | SAXException e) {
|
||||
|
@ -71,32 +106,58 @@ public class Feed {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna nevének beállítása
|
||||
* @param name a hírcsatorna új neve
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean hasAricle(Article a){
|
||||
for (Article art:articleList) {
|
||||
if(art.getURL() != null && art.getURL().equals(a.getURL()))
|
||||
/**
|
||||
* Megnézi hogy egy magadott cikk megtalálható-e a hírcsatornán
|
||||
* @param a a keresett cikk
|
||||
* @return logikai érték az alapján,hogy a megadott cikk meg lett-e találva
|
||||
* Megjegyzés: Ez egy lineáris keresést hajt végre
|
||||
*/
|
||||
public boolean hasAricle(Article a) {
|
||||
for (Article art : articleList) {
|
||||
if (art.getURL() != null && art.getURL().equals(a.getURL()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addArticle(Article a)
|
||||
{
|
||||
if(!hasAricle(a))
|
||||
articleList.add(a);
|
||||
/**
|
||||
* Új cikk felvétele a listába.
|
||||
* @param a új cikk
|
||||
* Megjegyzés: cikket csak akkor veszi fel,ha az még nem található a listájában
|
||||
*/
|
||||
public void addArticle(Article a) {
|
||||
if (!hasAricle(a))
|
||||
articleList.add(a);
|
||||
}
|
||||
|
||||
public DefaultMutableTreeNode getTreeNode(){
|
||||
/**
|
||||
* TreeNode készítése a hírcsatornáról
|
||||
* @return
|
||||
*/
|
||||
public DefaultMutableTreeNode getTreeNode() {
|
||||
return new DefaultMutableTreeNode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna elérési útvonalának lekérése
|
||||
* @return a hírcsatorna elérési útvonala
|
||||
*/
|
||||
public String getLink() {
|
||||
return link.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A hírcsatornához tartozó cikkek listájának lekérése
|
||||
* @return A hírcsatorna tartozó cikkek listája
|
||||
*/
|
||||
public List<Article> getArticleList() {
|
||||
return articleList;
|
||||
}
|
||||
|
|
|
@ -1,33 +1,37 @@
|
|||
package eu.toldi.rss;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.security.NoTypePermission;
|
||||
import com.thoughtworks.xstream.security.NullPermission;
|
||||
import com.thoughtworks.xstream.security.PrimitiveTypePermission;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.beans.XMLDecoder;
|
||||
import java.beans.XMLEncoder;
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A hírcsatornákat és a hozzájuk tartozó cikkeket tárolásáért,valamint azok táblázatban való megjelenítésért felelős objektum.
|
||||
*
|
||||
*/
|
||||
public class FeedData extends AbstractTableModel {
|
||||
|
||||
private FeedList feeds = new FeedList();
|
||||
private List<Article> articleList = new ArrayList<Article>();
|
||||
|
||||
public FeedData() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* FeedData előállítása fájlból
|
||||
* @param filename A fájl elérési útvonala
|
||||
* A megadott fájlnak egy XML fájlnak kell lennie,amit a FeedData.save() metódus állított elő
|
||||
* @see FeedData#save(String)
|
||||
*/
|
||||
public FeedData(String filename) {
|
||||
super();
|
||||
XStream xStream = new XStream();
|
||||
xStream.processAnnotations(Article.class);
|
||||
xStream.processAnnotations(Feed.class);
|
||||
xStream.alias("feedGroup", FeedGroup.class);
|
||||
xStream.addImplicitArray(FeedList.class, "list", Feed.class);
|
||||
XStream xStream = initXstream();
|
||||
try {
|
||||
feeds = new FeedList((ArrayList<Feed>) xStream.fromXML(new FileInputStream(filename)));
|
||||
for (int i = 0; i < feeds.size(); i++) {
|
||||
|
@ -46,6 +50,11 @@ public class FeedData extends AbstractTableModel {
|
|||
|
||||
private Feed limit = null;
|
||||
|
||||
/**
|
||||
* Hírcsatorna hozzáadása a listához
|
||||
* @param f A hozzáadandó hírcsatorna
|
||||
* Megjegyzés: A hozzáadás során a hírcsatornán található összes cikket kimeti
|
||||
*/
|
||||
public synchronized void addFeed(Feed f) {
|
||||
feeds.add(f);
|
||||
for (int i = 0; i < f.getArticleCount(); i++) {
|
||||
|
@ -53,16 +62,25 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractTableModel#getRowCount()
|
||||
*/
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return (limit == null) ? articleList.size() : limit.getArticleCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractTableModel#getColumnCount()
|
||||
*/
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractTableModel#getColumnName(int)
|
||||
*/
|
||||
@Override
|
||||
public String getColumnName(int oszlop) {
|
||||
switch (oszlop) {
|
||||
|
@ -77,6 +95,9 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractTableModel#getColumnName(int)
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getColumnClass(int oszlop) {
|
||||
switch (oszlop) {
|
||||
|
@ -89,6 +110,9 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractTableModel#getValueAt(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
|
||||
|
@ -105,18 +129,37 @@ public class FeedData extends AbstractTableModel {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Megkeres egy megadott helyen található cikket és visszatér vele
|
||||
* @param i Az cikk helye(sora)
|
||||
* @return Az adott helyen található cikk
|
||||
*/
|
||||
public Article get(int i) {
|
||||
return (limit == null) ? articleList.get(i) : limit.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy sor elemére kattintva ez a metódus hívódik meg. Ez megnyitja az adott helyen található cikket (Amennyiben ez lehetséges)
|
||||
* @param row
|
||||
*/
|
||||
public void clicked(int row) {
|
||||
get(row).open();
|
||||
}
|
||||
|
||||
/**
|
||||
* A hírcsatornák körének szűkítése egy hírcsatornára vagy egy hírcsatorna csoportra
|
||||
* @param feed A hírcsatorna, amely cikkjeit szeretnénk megtekinteni
|
||||
*/
|
||||
public void limitTo(Feed feed) {
|
||||
limit = feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ezt a metódust egy JTree felépítésere lehet használni.
|
||||
* @return egy JTree-hez használhato TreeNode
|
||||
* @see javax.swing.JTree
|
||||
* @see DefaultMutableTreeNode
|
||||
*/
|
||||
public DefaultMutableTreeNode getRootNode() {
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Feeds");
|
||||
for (int i = 0; i < feeds.size(); i++) {
|
||||
|
@ -125,10 +168,20 @@ public class FeedData extends AbstractTableModel {
|
|||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* A hírcsatornák listájának lekérése
|
||||
* @return Hírcsatornák listája
|
||||
* @see FeedList
|
||||
*/
|
||||
public synchronized FeedList getFeeds() {
|
||||
return feeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy hírcsatorna törlése a listából
|
||||
* @param feed az eltávolítandó hírcsatorna
|
||||
* Megjegyzés: Ez törli az összes cikket,ami ehhez a csatornához tartozott
|
||||
*/
|
||||
public synchronized void removeFeed(Feed feed) {
|
||||
boolean found = false;
|
||||
for (int i = 0; i < feeds.size(); i++) {
|
||||
|
@ -152,6 +205,11 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy hírcsatorna áthelyezése a listában. Átrendezésre használatos.
|
||||
* @param f az áthelyezendő hírcsatorna
|
||||
* @param index a hírcsatorna új helye
|
||||
*/
|
||||
public synchronized void setLocation(Feed f, int index) {
|
||||
feeds.remove(f);
|
||||
feeds.add(index, f);
|
||||
|
@ -164,26 +222,24 @@ public class FeedData extends AbstractTableModel {
|
|||
'}';
|
||||
}
|
||||
|
||||
public synchronized void updateAll(){
|
||||
/**
|
||||
* A listában található összes hírcsatorna frissítése
|
||||
*/
|
||||
public synchronized void updateAll() throws IOException {
|
||||
for (int i = 0; i < feeds.size(); i++) {
|
||||
try {
|
||||
feeds.get(i).updateFeed();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int j = 0; j < feeds.get(i).getArticleCount(); j++) {
|
||||
articleList.add(feeds.get(i).get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A hírcsatornák listájának kimentése egy XML fájlba.
|
||||
* @param filename A fájl ahová menteni szeretné az adatokat
|
||||
*/
|
||||
public synchronized void save(String filename) {
|
||||
XStream xStream = new XStream();
|
||||
xStream.processAnnotations(Article.class);
|
||||
xStream.processAnnotations(Feed.class);
|
||||
xStream.processAnnotations(FeedGroup.class);
|
||||
xStream.alias("feeds", FeedList.class);
|
||||
xStream.addImplicitArray(FeedList.class, "list", Feed.class);
|
||||
XStream xStream = initXstream();
|
||||
String xml = xStream.toXML(feeds.getList());
|
||||
BufferedWriter writer;
|
||||
try {
|
||||
|
@ -196,5 +252,26 @@ public class FeedData extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XStream inicializálására használt metódus.
|
||||
* @return XStream objektum
|
||||
* Megjegyzés: XML-be írásra van használva
|
||||
*/
|
||||
private XStream initXstream(){
|
||||
XStream xStream = new XStream();
|
||||
xStream.addPermission(NoTypePermission.NONE);
|
||||
xStream.addPermission(NullPermission.NULL);
|
||||
xStream.addPermission(PrimitiveTypePermission.PRIMITIVES);
|
||||
xStream.allowTypeHierarchy(Collection.class);
|
||||
xStream.allowTypesByWildcard(new String[] {
|
||||
"eu.toldi.rss.**"
|
||||
});
|
||||
xStream.processAnnotations(Article.class);
|
||||
xStream.processAnnotations(Feed.class);
|
||||
xStream.alias("feedGroup", FeedGroup.class);
|
||||
xStream.addImplicitArray(FeedList.class, "list", Feed.class);
|
||||
return xStream;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.awt.datatransfer.DataFlavor;
|
|||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
@ -224,7 +225,7 @@ public class FeedFrame extends JFrame {
|
|||
Feed f = null;
|
||||
try {
|
||||
f = new Feed(new URL(feedURL.getText()));
|
||||
} catch (MalformedURLException malformedURLException) {
|
||||
} catch (IOException malformedURLException) {
|
||||
JOptionPane.showInternalMessageDialog(null,"An error has occurred!","Error",JOptionPane.ERROR_MESSAGE);
|
||||
malformedURLException.printStackTrace();
|
||||
}
|
||||
|
@ -237,6 +238,9 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adatok kimentésére használt ActionListener
|
||||
*/
|
||||
private class SaveFeeds implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -244,15 +248,26 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Össes hírcsatorna frissítésére használt ActionListener
|
||||
*/
|
||||
private class UpdateAll implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
data.updateAll();
|
||||
try {
|
||||
data.updateAll();
|
||||
} catch (IOException ioException) {
|
||||
JOptionPane.showInternalMessageDialog(null,"An error has occurred!","Error",JOptionPane.ERROR_MESSAGE);
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
updateTable();
|
||||
data.save(saveFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kilépésre használt ActionListener
|
||||
*/
|
||||
private class Exit implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -261,6 +276,9 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Névjegy megjelenítésére használt ActionListener
|
||||
*/
|
||||
private class About implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -271,6 +289,9 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatornák közötti váltásra használt MouseAdapter
|
||||
*/
|
||||
private class SwitchFeed extends MouseAdapter {
|
||||
|
||||
@Override
|
||||
|
@ -290,6 +311,10 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A JTree átrendezésére használt TransferHandler
|
||||
* @see javax.swing.TransferHandler
|
||||
*/
|
||||
class TreeTransferHandler extends TransferHandler {
|
||||
DataFlavor nodesFlavor;
|
||||
DataFlavor[] flavors = new DataFlavor[1];
|
||||
|
@ -532,6 +557,9 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy hírcsatornára jobb egérgombal kattintva, ez a menü jelenik meg. Ezzel lehet a hírcsatornákat törölni.
|
||||
*/
|
||||
private class FeedPopUpMenu extends JPopupMenu {
|
||||
Feed f = null;
|
||||
|
||||
|
@ -563,6 +591,10 @@ public class FeedFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy hírcsatorna csoportra jobb egérgombal kattintva ez a menü jelenik meg.
|
||||
* Itt lehet a csoportot eltávolítani,valamint átnevezni.
|
||||
*/
|
||||
private class FeedGroupPopUpMenu extends FeedPopUpMenu {
|
||||
|
||||
public FeedGroupPopUpMenu(Feed feed, FeedGroup feedGroup, DefaultMutableTreeNode node) {
|
||||
|
|
|
@ -8,10 +8,18 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Ez egy olyan hírcsatorna,amelyet több hírcsatorna összessége képez.
|
||||
*/
|
||||
@XStreamAlias("feedGroup")
|
||||
public class FeedGroup extends Feed {
|
||||
|
||||
/**
|
||||
* A hírcsatornák listája
|
||||
*/
|
||||
List<Feed> feedList = new ArrayList<Feed>();
|
||||
/**
|
||||
* A csoport cikkjeinek listája
|
||||
*/
|
||||
@XStreamOmitField
|
||||
List<Article> articleList = new ArrayList<Article>();
|
||||
|
||||
|
@ -19,16 +27,26 @@ public class FeedGroup extends Feed {
|
|||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna hozzáadása a csoporthoz
|
||||
* @param feed hozzáadandó hírcsatorna
|
||||
* Megjegyzés: Meglévő csatorna nem adható hozzá mégegyszer
|
||||
*/
|
||||
public void addFeed(Feed feed){
|
||||
if(!feedExists(feed)) {
|
||||
feedList.add(feed);
|
||||
for (int i = 0; i < feed.getArticleCount(); i++) {
|
||||
articleList.add(feed.get(i));
|
||||
}
|
||||
}else
|
||||
System.out.println("Feed exists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ellenőrzi,hogy a megadott hírcsatorna metalálható-e benne
|
||||
* @param f az ellenőrizendő csatorna
|
||||
* @return logikai érték az alapján,hogy a csatorna megtalálható-e a csoportban
|
||||
* Megjegyzés: Csak abban az esetben tér vissza igazzal,ha a két objektum megegyezik egy a csoportban találhatóval
|
||||
*/
|
||||
public boolean feedExists(Feed f){
|
||||
for (int i = 0; i < feedList.size(); i++) {
|
||||
if(f == feedList.get(i))
|
||||
|
@ -37,11 +55,18 @@ public class FeedGroup extends Feed {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Feed#get(int)
|
||||
*/
|
||||
@Override
|
||||
public Article get(int i) {
|
||||
return articleList.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Feed#updateFeed()
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void updateFeed() throws IOException {
|
||||
if(articleList == null)
|
||||
|
@ -54,6 +79,10 @@ public class FeedGroup extends Feed {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Feed#getArticleCount()
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getArticleCount() {
|
||||
int result = 0;
|
||||
|
@ -63,6 +92,10 @@ public class FeedGroup extends Feed {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Feed#getTreeNode()
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DefaultMutableTreeNode getTreeNode() {
|
||||
DefaultMutableTreeNode folder = super.getTreeNode();
|
||||
|
@ -72,6 +105,11 @@ public class FeedGroup extends Feed {
|
|||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna törlése a csoportból
|
||||
* @param feed a törlendő hírcsatorna
|
||||
* Megjegyzés: Ez törli az össze a csatornához tartozó cikket.
|
||||
*/
|
||||
public void removeFeed(Feed feed){
|
||||
boolean found = false;
|
||||
for (int i = 0; i < feedList.size(); i++) {
|
||||
|
@ -93,6 +131,11 @@ public class FeedGroup extends Feed {
|
|||
articleList = different;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Egy hírcsatorna áthelyezése a listában. Átrendezésre használatos.
|
||||
* @param f az áthelyezendő hírcsatorna
|
||||
* @param index a hírcsatorna új helye
|
||||
*/
|
||||
public void setLocation(Feed f,int index){
|
||||
feedList.remove(f);
|
||||
feedList.add(index,f);
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package eu.toldi.rss;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FeedList {
|
||||
|
||||
|
@ -18,29 +15,61 @@ public class FeedList {
|
|||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna hozzáadása a listához
|
||||
* @param f
|
||||
*/
|
||||
public void add(Feed f) {
|
||||
list.add(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* A lista mérete,azaz a benne található hírcsatornák száma
|
||||
* @return a lista mérete
|
||||
*/
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista egy elemének lekérése.
|
||||
* @param i A keresett hírcsatorna listán belül található helye
|
||||
* @return A keresett hírcsatorna
|
||||
*/
|
||||
public Feed get(int i) {
|
||||
return list.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna eltávolítása a listából
|
||||
* @param i Az eltábolítandó hírcsatorna indexe
|
||||
* @return Az eltávolított hírcsatonra
|
||||
*/
|
||||
public Feed remove(int i) {
|
||||
return list.remove(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Egy megadott hírcsatorna törlése a listából
|
||||
* @param f az eltávolítandó hírcsatorna
|
||||
*/
|
||||
public void remove(Feed f) {
|
||||
list.remove(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatorna hozzáadása egy megadott helyer
|
||||
* @param index a hely ahova a hírcsatorna kerüljön
|
||||
* @param f a hozzáadandó hírcsatorna
|
||||
*/
|
||||
public void add(int index, Feed f) {
|
||||
list.add(index, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírcsatornák listéjának lekérése
|
||||
* @return a hírcsatornák listéja
|
||||
*/
|
||||
public List<Feed> getList(){
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package eu.toldi.rss;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FeedLoader {
|
||||
|
||||
private FeedData data;
|
||||
|
||||
|
||||
private Feed getFeed(NodeList feedProperties) throws MalformedURLException {
|
||||
List<Article> articleList = new ArrayList<Article>();
|
||||
String url = null;
|
||||
for (int j = 1; j < feedProperties.getLength(); j+=2) {
|
||||
Node node = feedProperties.item(j);
|
||||
String tagName = node.getNodeName();
|
||||
|
||||
|
||||
switch (tagName){
|
||||
case "link":
|
||||
url = node.getTextContent();
|
||||
break;
|
||||
case "articleList":
|
||||
NodeList articles = node.getChildNodes();
|
||||
for (int k = 0; k < articles.getLength(); k++) {
|
||||
Node article = articles.item(k);
|
||||
Article a = new Article(article, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
if(a.getURL() != null)
|
||||
articleList.add(a);
|
||||
}
|
||||
}
|
||||
if(url == null) return null;
|
||||
}
|
||||
Feed feed = new Feed(new URL(url));
|
||||
for (int k = 0; k < articleList.size(); k++) {
|
||||
feed.addArticle(articleList.get(k));
|
||||
}
|
||||
return feed;
|
||||
}
|
||||
|
||||
|
||||
public void setData(FeedData data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,16 @@
|
|||
package eu.toldi.rss;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Hírcsatornákat periodikusan frissítő szál.
|
||||
* Megjegyzés: A hírcsatornákat 10 percenként frissíti.
|
||||
*/
|
||||
public class UpdaterThread extends Thread{
|
||||
FeedData data;
|
||||
FeedFrame frame;
|
||||
private static long updateInterval = 60*1000;
|
||||
//Tíz perc várakozás
|
||||
private static long updateInterval = 10*60*1000;
|
||||
|
||||
public UpdaterThread(FeedData data,FeedFrame frame){
|
||||
this.data = data;
|
||||
|
@ -19,15 +22,11 @@ public class UpdaterThread extends Thread{
|
|||
while (true) {
|
||||
try {
|
||||
sleep(updateInterval);
|
||||
} catch (InterruptedException e) {
|
||||
data.updateAll();
|
||||
} catch (InterruptedException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
data.updateAll();
|
||||
frame.updateTable();
|
||||
/*TableRowSorter<FeedData> sorter = (TableRowSorter<FeedData>) table.getRowSorter();
|
||||
table.setModel(data);
|
||||
table.setRowSorter(sorter);
|
||||
table.updateUI();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue