still under construction
This commit is contained in:
@@ -20,17 +20,13 @@ import java.io.StringWriter;
|
||||
* @link https://www.sitemaps.org/ko/protocol.html
|
||||
*/
|
||||
public abstract class BaseSitemapService {
|
||||
private final Mustache template;
|
||||
|
||||
protected BaseSitemapService() {
|
||||
MustacheFactory factory = new DefaultMustacheFactory();
|
||||
template = factory.compile("sitemap/sitemap.mustache");
|
||||
}
|
||||
|
||||
protected abstract Sitemap sitemap();
|
||||
|
||||
public String getSitemap() {
|
||||
StringWriter writer = new StringWriter();
|
||||
final MustacheFactory factory = new DefaultMustacheFactory();
|
||||
final Mustache template = factory.compile("sitemap/sitemap.mustache");
|
||||
final StringWriter writer = new StringWriter();
|
||||
template.execute(writer, sitemap());
|
||||
return writer.toString()
|
||||
.replaceAll("[\n\t]", "")
|
||||
|
||||
@@ -27,8 +27,6 @@ import java.time.format.DateTimeFormatter;
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SitemapItem {
|
||||
private static final ZoneId defaultZone = ZoneOffset.ofHours(0).normalized();
|
||||
|
||||
private String loc;
|
||||
private LocalDateTime lastMod;
|
||||
private Frequency changeFreq;
|
||||
@@ -36,7 +34,5 @@ public class SitemapItem {
|
||||
|
||||
public String getLastModIso(){
|
||||
return Formatter.formatIso(lastMod);
|
||||
/*return lastMod.atZone(ZoneId.systemDefault())
|
||||
.format(DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(defaultZone));*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,31 +13,29 @@ import com.github.mustachejava.MustacheFactory;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
//@Service
|
||||
public abstract class BaseSyndicationService {
|
||||
private final Mustache templateRss, templateAtom;
|
||||
|
||||
public BaseSyndicationService(){
|
||||
MustacheFactory factory = new DefaultMustacheFactory();
|
||||
templateRss = factory.compile("syndication/rss2.mustache");
|
||||
templateAtom = factory.compile("syndication/atom.mustache");
|
||||
}
|
||||
|
||||
protected abstract Syndication syndication();
|
||||
|
||||
public String getRssSyndication() {
|
||||
StringWriter writer = new StringWriter();
|
||||
templateRss.execute(writer, syndication());
|
||||
public String getSyndication(final SyndicationType type) {
|
||||
final MustacheFactory factory = new DefaultMustacheFactory();
|
||||
final Mustache template;
|
||||
final StringWriter writer = new StringWriter();
|
||||
switch (type) {
|
||||
case ATOM:
|
||||
template = factory.compile("syndication/rss2.mustache");
|
||||
break;
|
||||
case RSS_2:
|
||||
template = factory.compile("syndication/atom.mustache");
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown Syndication Type.");
|
||||
}
|
||||
template.execute(writer, syndication());
|
||||
|
||||
return writer.toString()
|
||||
.replaceAll("[\n\t]","")
|
||||
.replaceAll("[\n\t]", "")
|
||||
.replaceAll("\\s{2,}", " ");
|
||||
}
|
||||
|
||||
public String getAtomSyndication() {
|
||||
StringWriter writer = new StringWriter();
|
||||
templateAtom.execute(writer, syndication());
|
||||
return writer.toString()
|
||||
.replaceAll("[\n\t]","")
|
||||
.replaceAll("\\s{2,}", " ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,26 @@
|
||||
|
||||
package com.elex_project.asgard.syndication;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public interface Formatter {
|
||||
public abstract class Formatter {
|
||||
|
||||
static final ZoneId defaultZone = ZoneOffset.ofHours(0).normalized();
|
||||
private static final ZoneId defaultZone = ZoneOffset.ofHours(0).normalized();
|
||||
|
||||
static String formatIso(final LocalDateTime time){
|
||||
private Formatter(){}
|
||||
|
||||
public static @NotNull String formatIso(final @NotNull LocalDateTime time){
|
||||
return time.atZone(ZoneId.systemDefault())
|
||||
.format(DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(defaultZone));
|
||||
}
|
||||
|
||||
static String formatRfc(final LocalDateTime time){
|
||||
public static @NotNull String formatRfc(final @NotNull LocalDateTime time){
|
||||
return time.atZone(ZoneOffset.systemDefault())
|
||||
.format(DateTimeFormatter.RFC_1123_DATE_TIME.withZone(defaultZone));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Project Asgard
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package com.elex_project.asgard.syndication;
|
||||
|
||||
public enum SyndicationType {
|
||||
RSS_2, ATOM;
|
||||
}
|
||||
Reference in New Issue
Block a user