Exporter for Articles

git-svn-id: https://svn.libreccm.org/ccm/trunk@5716 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2018-10-29 18:55:25 +00:00
parent 7bb93b2a46
commit fc2bcc18bd
2 changed files with 77 additions and 0 deletions

View File

@ -19,6 +19,7 @@
package com.arsdigita.cms.contenttypes;
import org.apache.log4j.Logger;
import org.libreccm.export.ExportManager;
/**
* Executes at each system startup and initializes the Article content type.
@ -41,6 +42,8 @@ public class ArticleInitializer extends ContentTypeInitializer {
*/
public ArticleInitializer() {
super("ccm-cms-types-article.pdl.mf", Article.BASE_DATA_OBJECT_TYPE);
ExportManager.getInstance().registerExporter(new ArticlesExporter());
}
/**

View File

@ -0,0 +1,74 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ItemCollection;
import com.fasterxml.jackson.core.JsonGenerator;
import org.librecms.contentsection.AbstractContentItemsExporter;
import java.io.IOException;
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 ArticlesExporter extends AbstractContentItemsExporter<Article> {
@Override
protected void exportContentItemProperties(
final Article contentItem, final JsonGenerator jsonGenerator)
throws IOException {
}
@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 Article article = (Article) instances.getContentItem();
final String lang = article.getLanguage();
final Locale locale = new Locale(lang);
final String lead = article.getLead();
final String text;
if (article.getTextAsset() == null) {
text = "";
} else {
text = article.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<Article> exportsType() {
return Article.class;
}
@Override
public String exportsBaseDataObjectType() {
return Article.BASE_DATA_OBJECT_TYPE;
}
@Override
public String convertsToType() {
return "org.librecms.contenttypes.Article";
}
}