Trimming Atom content (except GUID)

This commit is contained in:
ByteHamster 2020-06-24 22:37:41 +02:00
parent 7612f3c5ed
commit 64b9fcd18a
5 changed files with 20 additions and 19 deletions

View File

@ -1,12 +1,9 @@
package de.test.antennapod.handler;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import de.danoeh.antennapod.core.feed.Feed;
import de.test.antennapod.util.syndication.feedgenerator.AtomGenerator;
import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;

View File

@ -1,11 +1,9 @@
package de.test.antennapod.handler;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import de.danoeh.antennapod.core.feed.Feed;
import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
import de.test.antennapod.util.syndication.feedgenerator.Rss2Generator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
@ -20,7 +18,7 @@ public class RssParserTest extends FeedParserTestBase {
@Test
public void testRss2Basic() throws Exception {
Feed f1 = createTestFeed(10, true);
Feed f2 = runFeedTest(f1, new RSS2Generator(), "UTF-8", RSS2Generator.FEATURE_WRITE_GUID);
Feed f2 = runFeedTest(f1, new Rss2Generator(), "UTF-8", Rss2Generator.FEATURE_WRITE_GUID);
feedValid(f1, f2, Feed.TYPE_RSS2);
}
@ -29,7 +27,7 @@ public class RssParserTest extends FeedParserTestBase {
String image = "https://example.com/image.png";
Feed f1 = createTestFeed(0, false);
f1.setImageUrl(null);
Feed f2 = runFeedTest(f1, new RSS2Generator() {
Feed f2 = runFeedTest(f1, new Rss2Generator() {
@Override
protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException {
xml.startTag(null, "image");

View File

@ -9,7 +9,7 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.test.antennapod.util.service.download.HTTPBin;
import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
import de.test.antennapod.util.syndication.feedgenerator.Rss2Generator;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@ -78,7 +78,7 @@ public class UITestUtils {
private String hostFeed(Feed feed) throws IOException {
File feedFile = new File(hostedFeedDir, feed.getTitle());
FileOutputStream out = new FileOutputStream(feedFile);
RSS2Generator generator = new RSS2Generator();
Rss2Generator generator = new Rss2Generator();
generator.writeFeed(feed, out, "UTF-8", 0);
out.close();
int id = server.serveFile(feedFile);

View File

@ -14,15 +14,19 @@ import de.danoeh.antennapod.core.util.DateUtils;
/**
* Creates RSS 2.0 feeds. See FeedGenerator for more information.
*/
public class RSS2Generator implements FeedGenerator {
public class Rss2Generator implements FeedGenerator {
public static final long FEATURE_WRITE_GUID = 1;
@Override
public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException {
if (feed == null) throw new IllegalArgumentException("feed = null");
if (outputStream == null) throw new IllegalArgumentException("outputStream = null");
if (encoding == null) throw new IllegalArgumentException("encoding = null");
if (feed == null) {
throw new IllegalArgumentException("feed = null");
} else if (outputStream == null) {
throw new IllegalArgumentException("outputStream = null");
} else if (encoding == null) {
throw new IllegalArgumentException("encoding = null");
}
XmlSerializer xml = Xml.newSerializer();
xml.setOutput(outputStream, encoding);

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.syndication.namespace.atom;
import android.text.TextUtils;
import android.util.Log;
import de.danoeh.antennapod.core.syndication.util.SyndStringUtils;
import org.xml.sax.Attributes;
import de.danoeh.antennapod.core.feed.FeedItem;
@ -163,12 +164,13 @@ public class NSAtom extends Namespace {
if (state.getTagstack().size() >= 2) {
AtomText textElement = null;
String content;
String contentRaw;
if (state.getContentBuf() != null) {
content = state.getContentBuf().toString();
contentRaw = state.getContentBuf().toString();
} else {
content = "";
contentRaw = "";
}
String content = SyndStringUtils.trimAllWhitespace(contentRaw);
SyndElement topElement = state.getTagstack().peek();
String top = topElement.getName();
SyndElement secondElement = state.getSecondTag();
@ -181,9 +183,9 @@ public class NSAtom extends Namespace {
if (ID.equals(top)) {
if (FEED.equals(second) && state.getFeed() != null) {
state.getFeed().setFeedIdentifier(content);
state.getFeed().setFeedIdentifier(contentRaw);
} else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setItemIdentifier(content);
state.getCurrentItem().setItemIdentifier(contentRaw);
}
} else if (TITLE.equals(top) && textElement != null) {
if (FEED.equals(second) && state.getFeed() != null) {