- add syndication

This commit is contained in:
2024-02-21 01:50:47 +09:00
parent 51a85cbcfc
commit 805816491a
3 changed files with 31 additions and 7 deletions

View File

@@ -5,9 +5,7 @@
package kr.pe.elex.example;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.feed.synd.*;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.SyndFeedOutput;
@@ -16,10 +14,16 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
public class FeedService {
public static List<String> getSupportedTypes() {
final SyndFeed feed = new SyndFeedImpl();
return feed.getSupportedFeedTypes();
}
public static SyndFeed read(final Reader reader) throws FeedException {
return new SyndFeedInput().build(reader);
@@ -36,6 +40,18 @@ public class FeedService {
return feed;
}
public static @NotNull SyndEntry createEntry() throws ParseException {
final SyndEntry entry = new SyndEntryImpl();
entry.setTitle("Rome v1.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
entry.setPublishedDate(SimpleDateFormat.getDateInstance().parse("2004-06-08"));
final SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of Rome");
entry.setDescription(description);
return entry;
}
public static String write(final SyndFeed feed) throws FeedException, IOException {
try (final StringWriter writer = new StringWriter()) {
new SyndFeedOutput().output(feed, writer);

View File

@@ -11,13 +11,14 @@ import lombok.Getter;
public enum FeedType {
RSS_1_0("rss_1.0"),
RSS_2_0("rss_2.0"),
RSS("rss_2.0"),
ATOM_0_3("atom_0.3"),
ATOM("atom_0.3");
ATOM_1_0("atom_1.0"),
ATOM("atom_1.0");
private final String value;
FeedType(final String value){
FeedType(final String value) {
this.value = value;
}

View File

@@ -22,4 +22,11 @@ class FeedServiceTest {
System.out.println(FeedService.write(feed));
}
@Test
public void getTypesTest(){
for(String s : FeedService.getSupportedTypes()){
System.out.println(s);
}
}
}