diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContentItemListModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContentItemListModelBuilder.java
new file mode 100644
index 000000000..a63aef0a5
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/AbstractContentItemListModelBuilder.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2021 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.pages.models;
+
+import org.libreccm.l10n.GlobalizationHelper;
+import org.librecms.contentsection.ContentItem;
+
+import javax.inject.Inject;
+
+/**
+ *
+ * @author Jens Pelzetter
+ * @param
+ * @param
+ */
+public abstract class AbstractContentItemListModelBuilder
+ implements ContentItemListItemModelBuilder {
+
+ @Inject
+ private GlobalizationHelper globalizationHelper;
+
+ @Override
+ public M buildListItemModel(final T contentItem) {
+ final M model = buildModel();
+ model.setDescription(
+ globalizationHelper.getValueFromLocalizedString(
+ contentItem.getDescription()
+ )
+ );
+ globalizationHelper.getValueFromLocalizedString(
+ contentItem.getName()
+ );
+ model.setDisplayName(contentItem.getDisplayName());
+ model.setTitle(
+ globalizationHelper.getValueFromLocalizedString(
+ contentItem.getTitle()
+ )
+ );
+
+ addProperties(contentItem, model);
+
+ return model;
+ }
+
+ protected abstract M buildModel();
+
+ protected void addProperties(final T contentItem, final M model) {
+ // Nothing in the default implementation.
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModel.java
index b4d82a222..f328840e8 100644
--- a/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModel.java
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModel.java
@@ -26,16 +26,7 @@ import org.librecms.contenttypes.Article;
*/
public class ArticleListItemModel extends AbstractContentItemListItemModel {
- private String text;
-
- public String getText() {
- return text;
- }
-
- public void setText(final String text) {
- this.text = text;
- }
-
+ @Override
public String getType() {
return Article.class.getName();
}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModelBuilder.java
index 8b68a8b10..4802590de 100644
--- a/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModelBuilder.java
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/ArticleListItemModelBuilder.java
@@ -18,53 +18,21 @@
*/
package org.librecms.pages.models;
-import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contenttypes.Article;
-import java.util.Objects;
-
import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
/**
*
* @author Jens Pelzetter
*/
@RequestScoped
-public class ArticleListItemModelBuilder
- implements ContentItemListItemModelBuilder {
-
- @Inject
- private GlobalizationHelper globalizationHelper;
+public class ArticleListItemModelBuilder
+ extends AbstractContentItemListModelBuilder {
@Override
- public ArticleListItemModel buildListItemModel(final Article article) {
- Objects.requireNonNull(article);
-
- final ArticleListItemModel model = new ArticleListItemModel();
- model.setDescription(
- globalizationHelper.getValueFromLocalizedString(
- article.getDescription()
- )
- );
- model.setName(
- globalizationHelper.getValueFromLocalizedString(
- article.getName()
- )
- );
- model.setDisplayName(article.getDisplayName());
- model.setText(
- globalizationHelper.getValueFromLocalizedString(
- article.getText()
- )
- );
- model.setTitle(
- globalizationHelper.getValueFromLocalizedString(
- article.getTitle()
- )
- );
-
- return model;
+ protected ArticleListItemModel buildModel() {
+ return new ArticleListItemModel();
}
@Override
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModel.java
new file mode 100644
index 000000000..fa2f31f5b
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModel.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.pages.models;
+
+import org.librecms.contenttypes.Event;
+
+import java.time.LocalDateTime;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class EventListItemModel extends AbstractContentItemListItemModel {
+
+ private LocalDateTime startDate;
+
+ private LocalDateTime endDate;
+
+ private String location;
+
+ @Override
+ public String getType() {
+ return Event.class.getName();
+ }
+
+ public LocalDateTime getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(final LocalDateTime startDate) {
+ this.startDate = startDate;
+ }
+
+ public LocalDateTime getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(final LocalDateTime endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(final String location) {
+ this.location = location;
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModelBuilder.java
new file mode 100644
index 000000000..65d603b2d
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/EventListItemModelBuilder.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.pages.models;
+
+import org.libreccm.l10n.GlobalizationHelper;
+import org.librecms.contenttypes.Event;
+
+import java.time.LocalDateTime;
+
+import javax.inject.Inject;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class EventListItemModelBuilder
+ extends AbstractContentItemListModelBuilder {
+
+ @Inject
+ private GlobalizationHelper globalizationHelper;
+
+ @Override
+ public Class buildsListItemModelFor() {
+ return Event.class;
+ }
+
+ @Override
+ protected EventListItemModel buildModel() {
+ return new EventListItemModel();
+ }
+
+ @Override
+ protected void addProperties(
+ final Event event, final EventListItemModel model
+ ) {
+ super.addProperties(event, model);
+ model.setEndDate(LocalDateTime.from(event.getEndDate().toInstant()));
+ model.setLocation(
+ globalizationHelper.getValueFromLocalizedString(
+ event.getLocation()
+ )
+ );
+ model.setStartDate(LocalDateTime.from(event.getStartDate().toInstant()));
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModel.java
new file mode 100644
index 000000000..b61ddac57
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModel.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2021 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.pages.models;
+
+import org.librecms.contenttypes.News;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class NewsListItemModel extends AbstractContentItemListItemModel {
+
+ private LocalDateTime releaseDate;
+
+ public LocalDateTime getReleaseDate() {
+ return releaseDate;
+ }
+
+ public String getReleaseDateAsString() {
+ return DateTimeFormatter.ISO_DATE_TIME
+ .withZone(ZoneId.systemDefault())
+ .format(releaseDate);
+ }
+
+ public void setReleaseDate(final LocalDateTime releaseDate) {
+ this.releaseDate = releaseDate;
+ }
+
+ @Override
+ public String getType() {
+ return News.class.getName();
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModelBuilder.java
new file mode 100644
index 000000000..2eb43cba4
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/NewsListItemModelBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.pages.models;
+
+import org.librecms.contenttypes.News;
+
+import java.time.LocalDateTime;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class NewsListItemModelBuilder
+ extends AbstractContentItemListModelBuilder {
+
+ @Override
+ public Class buildsListItemModelFor() {
+ return News.class;
+ }
+
+ @Override
+ protected NewsListItemModel buildModel() {
+ return new NewsListItemModel();
+ }
+
+ @Override
+ protected void addProperties(
+ final News news, final NewsListItemModel model
+ ) {
+ super.addProperties(news, model);
+ model.setReleaseDate(
+ LocalDateTime.from(news.getReleaseDate().toInstant())
+ );
+ }
+
+}