Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions library/src/com/shirwa/simplistic_rss/RssHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shirwa.simplistic_rss;


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
Expand Down Expand Up @@ -31,7 +30,8 @@ public class RssHandler extends DefaultHandler {
private boolean parsingTitle;
private boolean parsingLink;
private boolean parsingDescription;


private String tmpValue="";
public RssHandler() {
//Initializes a new ArrayList that will hold all the generated RSS items.
rssItemList = new ArrayList<RssItem>();
Expand All @@ -45,14 +45,15 @@ public List<RssItem> getRssItemList() {
//Called when an opening tag is reached, such as <item> or <title>
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
tmpValue = "";
if (qName.equals("item"))
currentItem = new RssItem();
else if (qName.equals("title"))
parsingTitle = true;
else if (qName.equals("link"))
parsingLink = true;
else if (qName.equals("description"))
parsingDescription = true;
parsingDescription=true;
else if (qName.equals("media:thumbnail") || qName.equals("media:content") || qName.equals("image")) {
if (attributes.getValue("url") != null)
currentItem.setImageUrl(attributes.getValue("url"));
Expand All @@ -62,6 +63,17 @@ else if (qName.equals("media:thumbnail") || qName.equals("media:content") || qNa
//Called when a closing tag is reached, such as </item> or </title>
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (currentItem != null) {
//If parsingTitle is true, then that means we are inside a <title> tag so the text is the title of an item.
if (parsingTitle)
currentItem.setTitle(tmpValue);
//If parsingLink is true, then that means we are inside a <link> tag so the text is the link of an item.
else if (parsingLink)
currentItem.setLink(tmpValue);
//If parsingDescription is true, then that means we are inside a <description> tag so the text is the description of an item.
else if (parsingDescription)
currentItem.setDescription(tmpValue);
}
if (qName.equals("item")) {
//End of an item so add the currentItem to the list of items.
rssItemList.add(currentItem);
Expand All @@ -71,23 +83,15 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
else if (qName.equals("link"))
parsingLink = false;
else if (qName.equals("description"))
parsingDescription = false;
parsingDescription=false;


}

//Goes through character by character when parsing whats inside of a tag.
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (currentItem != null) {
//If parsingTitle is true, then that means we are inside a <title> tag so the text is the title of an item.
if (parsingTitle)
currentItem.setTitle(new String(ch, start, length));
//If parsingLink is true, then that means we are inside a <link> tag so the text is the link of an item.
else if (parsingLink)
currentItem.setLink(new String(ch, start, length));
//If parsingDescription is true, then that means we are inside a <description> tag so the text is the description of an item.
else if (parsingDescription)
currentItem.setDescription(new String(ch, start, length));
}
tmpValue += new String(ch, start, length);
}
}

Expand Down