Exporter for NewsItems
git-svn-id: https://svn.libreccm.org/ccm/trunk@5734 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
256fcdba3d
commit
471ebd7672
|
|
@ -21,6 +21,7 @@ public class ArticlesExporter extends AbstractContentItemsExporter<Article> {
|
||||||
final Article contentItem, final JsonGenerator jsonGenerator)
|
final Article contentItem, final JsonGenerator jsonGenerator)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
package com.arsdigita.cms.contenttypes;
|
package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.libreccm.export.ExportManager;
|
||||||
|
import org.librecms.contenttypes.NewsExporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes at each system startup and initializes the NewsItem content type.
|
* Executes at each system startup and initializes the NewsItem content type.
|
||||||
|
|
@ -43,6 +45,8 @@ public class NewsItemInitializer extends ContentTypeInitializer {
|
||||||
*/
|
*/
|
||||||
public NewsItemInitializer() {
|
public NewsItemInitializer() {
|
||||||
super("ccm-cms-types-newsitem.pdl.mf", NewsItem.BASE_DATA_OBJECT_TYPE);
|
super("ccm-cms-types-newsitem.pdl.mf", NewsItem.BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
||||||
|
ExportManager.getInstance().registerExporter(new NewsExporter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ItemCollection;
|
||||||
|
import com.arsdigita.cms.contenttypes.NewsItem;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.librecms.contentsection.AbstractContentItemsExporter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class NewsExporter extends AbstractContentItemsExporter<NewsItem> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void exportContentItemProperties(
|
||||||
|
final NewsItem newsItem, final JsonGenerator jsonGenerator)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
final DateTimeFormatter dateTimeFormatter
|
||||||
|
= DateTimeFormatter.ISO_DATE_TIME;
|
||||||
|
if (newsItem.getNewsDate() != null) {
|
||||||
|
final LocalDateTime newsDate = LocalDateTime
|
||||||
|
.ofInstant(newsItem.getNewsDate().toInstant(),
|
||||||
|
ZoneId.systemDefault());
|
||||||
|
jsonGenerator.writeStringField(
|
||||||
|
"releaseDate", dateTimeFormatter.format(newsDate));
|
||||||
|
}
|
||||||
|
jsonGenerator.writeBooleanField("homepage", newsItem.isHomepage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Map<Locale, String>> collectLocalizedValues(
|
||||||
|
final ItemCollection instances) {
|
||||||
|
|
||||||
|
final Map<Locale, String> leadPropertyValues = new HashMap<>();
|
||||||
|
final Map<Locale, String> textPropertyValues = new HashMap<>();
|
||||||
|
|
||||||
|
while (instances.next()) {
|
||||||
|
|
||||||
|
final NewsItem news = (NewsItem) instances.getContentItem();
|
||||||
|
final String lang = news.getLanguage();
|
||||||
|
final Locale locale = new Locale(lang);
|
||||||
|
final String lead = news.getLead();
|
||||||
|
final String text;
|
||||||
|
if (news.getTextAsset() == null) {
|
||||||
|
text = "";
|
||||||
|
} else {
|
||||||
|
text = news.getTextAsset().getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
leadPropertyValues.put(locale, lead);
|
||||||
|
textPropertyValues.put(locale, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
instances.rewind();
|
||||||
|
|
||||||
|
final Map<String, Map<Locale, String>> properties = new HashMap<>();
|
||||||
|
properties.put("description", leadPropertyValues);
|
||||||
|
properties.put("text", textPropertyValues);
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<NewsItem> exportsType() {
|
||||||
|
|
||||||
|
return NewsItem.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String exportsBaseDataObjectType() {
|
||||||
|
|
||||||
|
return NewsItem.BASE_DATA_OBJECT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertsToType() {
|
||||||
|
|
||||||
|
return "org.librecms.contenttypes.News";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue