- add synd-feed

This commit is contained in:
2024-02-21 01:13:13 +09:00
parent 0efdfb1085
commit 51a85cbcfc
7 changed files with 141 additions and 0 deletions

5
feed/README.md Normal file
View File

@@ -0,0 +1,5 @@
# Feed
RSS and ATOM feed
powered by ROME

16
feed/build.gradle.kts Normal file
View File

@@ -0,0 +1,16 @@
/*
* Examples for Java
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
plugins {
id("elex-java")
}
dependencies {
// https://mvnrepository.com/artifact/com.rometools/rome
implementation("com.rometools:rome:2.1.0")
}

20
feed/logback.xml Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Examples for Java
~
~ Copyright (c) 2021. Elex. All Rights Reserved.
~ https://www.elex-project.com/
-->
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024. Elex. All Rights Reesrved.
* https://www.elex-project.com/
*/
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.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.SyndFeedOutput;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.util.List;
public class FeedService {
public static SyndFeed read(final Reader reader) throws FeedException {
return new SyndFeedInput().build(reader);
}
public static @NotNull SyndFeed create(final List<SyndEntry> entries) {
final SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FeedType.RSS.getValue());
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://rome.dev.java.net");
feed.setDescription("This feed has been created using ROME (Java syndication utilities");
feed.setEntries(entries);
return feed;
}
public static String write(final SyndFeed feed) throws FeedException, IOException {
try (final StringWriter writer = new StringWriter()) {
new SyndFeedOutput().output(feed, writer);
return writer.toString();
}
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024. Elex. All Rights Reesrved.
* https://www.elex-project.com/
*/
package kr.pe.elex.example;
import lombok.Getter;
@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");
private final String value;
FeedType(final String value){
this.value = value;
}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024. Elex. All Rights Reesrved.
* https://www.elex-project.com/
*/
package kr.pe.elex.example;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;
class FeedServiceTest {
@Test
public void createTest() throws FeedException, IOException {
SyndFeed feed = FeedService.create(Collections.emptyList());
System.out.println(FeedService.write(feed));
}
}

View File

@@ -17,3 +17,4 @@ include(
"mustache", "thymeleaf", "locale", "quartz", "sysinfo", "mustache", "thymeleaf", "locale", "quartz", "sysinfo",
"imaging", "stream", "sound", "midi", "gson", "security" "imaging", "stream", "sound", "midi", "gson", "security"
) )
include("feed")