summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util/News.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-09-15 16:16:06 +0200
committerJonathan Bauer2014-09-15 16:16:06 +0200
commit2e809307cc058db06e6bda91f0b68129625501ae (patch)
treefc4dd7cc37e6360c5f2a10d137142fd40bed62c3 /dozentenmodul/src/main/java/util/News.java
parent[client] News class for getting news from the satellite (diff)
downloadtutor-module-2e809307cc058db06e6bda91f0b68129625501ae.tar.gz
tutor-module-2e809307cc058db06e6bda91f0b68129625501ae.tar.xz
tutor-module-2e809307cc058db06e6bda91f0b68129625501ae.zip
[client] javadoced News class
Diffstat (limited to 'dozentenmodul/src/main/java/util/News.java')
-rw-r--r--dozentenmodul/src/main/java/util/News.java94
1 files changed, 67 insertions, 27 deletions
diff --git a/dozentenmodul/src/main/java/util/News.java b/dozentenmodul/src/main/java/util/News.java
index 239d06e3..38afe047 100644
--- a/dozentenmodul/src/main/java/util/News.java
+++ b/dozentenmodul/src/main/java/util/News.java
@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import java.sql.Date;
import javax.swing.JOptionPane;
@@ -19,12 +20,16 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-// Class representing the news given by the satellite
-// Makes use of the News-API of the webservice slx-admin:
-// http://satellite.ip/slx-admin/api.php?do=news
-//
-// Access the 'headline', 'content' and 'date' by their public getters:
-// String newsContent = News.getContent();
+/**
+ * Class representing the news given by the satellite
+ * Makes use of the News-API of the webservice slx-admin:
+ * http://satellite.ip/slx-admin/api.php?do=news
+ *
+ * Access the data through the public getters:
+ * String newsHeadline = News.getHeadline();
+ * String newsContent = News.getContent();
+ * Date newsLatestDate = News.getDate();
+ */
public class News {
@@ -32,8 +37,12 @@ public class News {
private static String headline = null;
private static String content = null;
private static Date date = null;
-
- // Public getters
+
+ /**
+ * Gets the headline as String.
+ *
+ * @return String Contains the headline text.
+ */
public static String getHeadline() {
if (headline != null)
return headline;
@@ -46,6 +55,12 @@ public class News {
return null;
}
}
+
+ /**
+ * Gets the content as String.
+ *
+ * @return String Contains the content text.
+ */
public static String getContent() {
if (content != null)
return content;
@@ -57,6 +72,12 @@ public class News {
return null;
}
}
+
+ /**
+ * Gets the date of the latest news as Date.
+ *
+ * @return Date Represent last modification date.
+ */
public static Date getDate() {
if (date != null)
return date;
@@ -68,33 +89,50 @@ public class News {
return null;
}
}
-
- // Private setters
+
+ /**
+ * Sets the headline of the news.
+ *
+ * @param s headline as String
+ */
private static void setHeadline(String s) {
if (s != null) headline = s;
}
+
+ /**
+ * Sets the content of the news.
+ *
+ * @param s content as String
+ */
private static void setContent(String s) {
if (s != null) content = s;
}
+
+ /**
+ * Sets the date of the news.
+ *
+ * @param d date as Date
+ */
private static void setDate(Date d) {
if (d != null) date = d;
}
-
-
- // Private 'init' function doing the main work.
- // It is called by getters if their object is null.
- //
- // Follows these steps:
- // - Opens URL as stream
- // - Parse stream as (XML-)Document
- // - Check validity of the news format:
- // <news>
- // <headline>...</headline>
- // <content>...</content>
- // <date>...</date>
- // </news>
- //
- // - Sets private members
+
+ /**
+ * Private 'init' function doing the main work.
+ * It is called by getters if their object is null.
+ * Follows these steps:
+ * - Opens URL as stream
+ * - Parse stream as (XML-)Document
+ * - Check validity of the news format:
+ * <news>
+ * <headline>...</headline>
+ * <content>...</content>
+ * <date>...</date>
+ * </news>
+ *
+ * - Sets private members
+ */
+
private static void init(){
// Document representing the XML
Document doc = null;
@@ -120,7 +158,9 @@ public class News {
return;
}
- // prepare stream
+ // set timeout for URLConnection
+ URLConnection urlCon = url.openConnection();
+
InputStream is = null;
try {
is = url.openStream();