summaryrefslogtreecommitdiff
path: root/src/de/podfetcher
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r--src/de/podfetcher/feed/Feed.java1
-rw-r--r--src/de/podfetcher/syndication/namespace/atom/AtomLink.java15
-rw-r--r--src/de/podfetcher/syndication/namespace/atom/AtomText.java46
-rw-r--r--src/de/podfetcher/syndication/namespace/atom/NSAtom.java51
-rw-r--r--src/de/podfetcher/syndication/util/HtmlUnescaper.java25
5 files changed, 135 insertions, 3 deletions
diff --git a/src/de/podfetcher/feed/Feed.java b/src/de/podfetcher/feed/Feed.java
index 05ae4bcda..c4ab4924d 100644
--- a/src/de/podfetcher/feed/Feed.java
+++ b/src/de/podfetcher/feed/Feed.java
@@ -12,6 +12,7 @@ import java.util.ArrayList;
*/
public class Feed extends FeedFile{
private String title;
+ /** Link to the website. */
private String link;
private String description;
private FeedImage image;
diff --git a/src/de/podfetcher/syndication/namespace/atom/AtomLink.java b/src/de/podfetcher/syndication/namespace/atom/AtomLink.java
new file mode 100644
index 000000000..1d02e4f6a
--- /dev/null
+++ b/src/de/podfetcher/syndication/namespace/atom/AtomLink.java
@@ -0,0 +1,15 @@
+package de.podfetcher.syndication.namespace.atom;
+
+import de.podfetcher.syndication.namespace.Namespace;
+import de.podfetcher.syndication.namespace.SyndElement;
+
+/** Represents a "link" - Element in an Atom Feed. */
+public class AtomLink extends SyndElement {
+ private String href, rel, title, type, length;
+
+ public AtomLink(String name, Namespace namespace) {
+ super(name, namespace);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/src/de/podfetcher/syndication/namespace/atom/AtomText.java b/src/de/podfetcher/syndication/namespace/atom/AtomText.java
new file mode 100644
index 000000000..a80b48412
--- /dev/null
+++ b/src/de/podfetcher/syndication/namespace/atom/AtomText.java
@@ -0,0 +1,46 @@
+package de.podfetcher.syndication.namespace.atom;
+
+import de.podfetcher.syndication.namespace.Namespace;
+import de.podfetcher.syndication.namespace.SyndElement;
+import de.podfetcher.syndication.util.HtmlUnescaper;
+
+/** Represents Atom Element which contains text (content, title, summary). */
+public class AtomText extends SyndElement {
+ public static final String TYPE_TEXT = "text";
+ public static final String TYPE_HTML = "html";
+ public static final String TYPE_XHTML = "xhtml";
+
+ private String type;
+ private String content;
+
+ public AtomText(String name, Namespace namespace, String type) {
+ super(name, namespace);
+ this.type = type;
+ }
+
+ /** Processes the content according to the type and returns it. */
+ public String getProcessedContent() {
+ if (type.equals(TYPE_HTML)) {
+ return HtmlUnescaper.unescape(content);
+ } else if (type.equals(TYPE_XHTML)) {
+ return content;
+ } else { // Handle as text by default
+ return content;
+ }
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+
+
+}
diff --git a/src/de/podfetcher/syndication/namespace/atom/NSAtom.java b/src/de/podfetcher/syndication/namespace/atom/NSAtom.java
index 7406e77d0..7aa01de80 100644
--- a/src/de/podfetcher/syndication/namespace/atom/NSAtom.java
+++ b/src/de/podfetcher/syndication/namespace/atom/NSAtom.java
@@ -3,6 +3,8 @@ package de.podfetcher.syndication.namespace.atom;
import org.xml.sax.Attributes;
import de.podfetcher.feed.Feed;
+import de.podfetcher.feed.FeedItem;
+import de.podfetcher.feed.FeedMedia;
import de.podfetcher.syndication.handler.HandlerState;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
@@ -11,18 +13,61 @@ public class NSAtom extends Namespace {
public static final String NSTAG = "atom";
public static final String NSURI = "http://www.w3.org/2005/Atom";
+ private static final String FEED = "feed";
private static final String TITLE = "title";
+ private static final String ENTRY = "entry";
private static final String LINK = "link";
private static final String UPDATED = "updated";
private static final String AUTHOR = "author";
+ private static final String CONTENT = "content";
+
+ private static final String TEXT_TYPE = "type";
+ // Link
+ private static final String LINK_HREF = "href";
+ private static final String LINK_REL = "rel";
+ private static final String LINK_TYPE = "type";
+ private static final String LINK_TITLE = "title";
+ private static final String LINK_LENGTH = "length";
+ // rel-values
+ private static final String LINK_REL_ALTERNATE = "alternate";
+ private static final String LINK_REL_ENCLOSURE = "enclosure";
+ private static final String LINK_REL_RELATED = "related";
+ private static final String LINK_REL_SELF = "self";
@Override
public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) {
- if (localName.equals(TITLE)) {
-
+ if (localName.equals(ENTRY)) {
+ state.setCurrentItem(new FeedItem());
+ state.getFeed().getItems().add(state.getCurrentItem());
+ state.getCurrentItem().setFeed(state.getFeed());
+ } else if (localName.equals(TITLE) || localName.equals(CONTENT)) {
+ String type = attributes.getValue(null, TEXT_TYPE);
+ return new AtomText(localName, this, type);
+ } else if (localName.equals(LINK)) {
+ String href = attributes.getValue(null, LINK_HREF);
+ String rel = attributes.getValue(null, LINK_REL);
+ SyndElement parent = state.getTagstack().peek();
+ if (parent.getName().equals(ENTRY)) {
+ if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
+ state.getCurrentItem().setLink(href);
+ } else if (rel.equals(LINK_REL_ENCLOSURE)) {
+ long size = Long.parseLong(attributes.getValue(null,
+ LINK_LENGTH));
+ String type = attributes.getValue(null, LINK_TYPE);
+ String download_url = attributes.getValue(null,
+ LINK_REL_ENCLOSURE);
+ state.getCurrentItem().setMedia(
+ new FeedMedia(state.getCurrentItem(), download_url,
+ size, type));
+ }
+ } else if (parent.getName().equals(FEED)) {
+ if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
+ state.getCurrentItem().setLink(href);
+ }
+ }
}
- return null;
+ return new SyndElement(localName, this);
}
@Override
diff --git a/src/de/podfetcher/syndication/util/HtmlUnescaper.java b/src/de/podfetcher/syndication/util/HtmlUnescaper.java
new file mode 100644
index 000000000..8b2bc9b1d
--- /dev/null
+++ b/src/de/podfetcher/syndication/util/HtmlUnescaper.java
@@ -0,0 +1,25 @@
+package de.podfetcher.syndication.util;
+
+import java.util.HashMap;
+
+/** Unescapes HTML */
+public class HtmlUnescaper {
+ private static HashMap<String, String> symbols;
+
+ static {
+ symbols.put("&nbsp", " ");
+ symbols.put("&quot", "\"");
+ symbols.put("&amp", "&");
+ symbols.put("&lt", "<");
+ symbols.put("&gt", ">");
+
+ }
+
+ public static String unescape(final String source) {
+ String result = source;
+ for (String key : symbols.keySet()) {
+ result = result.replaceAll(key, symbols.get(key));
+ }
+ return result;
+ }
+}