From 8fcad6268257e43090f0f44a90a8f654bec93937 Mon Sep 17 00:00:00 2001 From: KukyMan Date: Tue, 23 Apr 2019 19:15:38 +0200 Subject: [PATCH 1/2] Update RssHandler.java Update: RSSHandler.java to not be special character sensitive. --- .../com/shirwa/simplistic_rss/RssHandler.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/library/src/com/shirwa/simplistic_rss/RssHandler.java b/library/src/com/shirwa/simplistic_rss/RssHandler.java index 179bb00..a28fd38 100644 --- a/library/src/com/shirwa/simplistic_rss/RssHandler.java +++ b/library/src/com/shirwa/simplistic_rss/RssHandler.java @@ -1,6 +1,8 @@ package com.shirwa.simplistic_rss; +import android.util.Log; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -31,7 +33,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(); @@ -45,6 +48,8 @@ public List getRssItemList() { //Called when an opening tag is reached, such as or @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + tmpValue = ""; + Log.i("Debugg","start "+qName); if (qName.equals("item")) currentItem = new RssItem(); else if (qName.equals("title")) @@ -52,7 +57,7 @@ else if (qName.equals("title")) 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")); @@ -62,6 +67,17 @@ else if (qName.equals("media:thumbnail") || qName.equals("media:content") || qNa //Called when a closing tag is reached, such as </item> or @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 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); @@ -71,23 +87,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); } } From fc565b8c8362c51986281c401f5631dfc0a1bdcd Mon Sep 17 00:00:00 2001 From: KukyMan <kukys410@gmail.com> Date: Sun, 28 Apr 2019 13:03:28 +0200 Subject: [PATCH 2/2] Update RssHandler.java deleted some debug garbagge --- library/src/com/shirwa/simplistic_rss/RssHandler.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/src/com/shirwa/simplistic_rss/RssHandler.java b/library/src/com/shirwa/simplistic_rss/RssHandler.java index a28fd38..21a0da2 100644 --- a/library/src/com/shirwa/simplistic_rss/RssHandler.java +++ b/library/src/com/shirwa/simplistic_rss/RssHandler.java @@ -1,8 +1,5 @@ package com.shirwa.simplistic_rss; - -import android.util.Log; - import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -49,7 +46,6 @@ public List<RssItem> getRssItemList() { @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { tmpValue = ""; - Log.i("Debugg","start "+qName); if (qName.equals("item")) currentItem = new RssItem(); else if (qName.equals("title"))