Added reference to negotiated locale to models, used to format dates.
parent
47e26b5878
commit
2f8abff8f4
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A simplified representation of a content item for use in a list of content
|
||||
* items.Base class for other more specific models.
|
||||
|
|
@ -26,6 +28,12 @@ package org.librecms.pages.models;
|
|||
*/
|
||||
public abstract class AbstractContentItemListItemModel {
|
||||
|
||||
/**
|
||||
* The locale negotiated with the user agent. Useful for example for
|
||||
* formatting date. Only for internal use.
|
||||
*/
|
||||
private Locale locale;
|
||||
|
||||
private String uuid;
|
||||
|
||||
private String displayName;
|
||||
|
|
@ -35,6 +43,14 @@ public abstract class AbstractContentItemListItemModel {
|
|||
private String title;
|
||||
|
||||
private String description;
|
||||
|
||||
protected Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
protected void setLocale(final Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ public abstract class AbstractContentItemListItemModelBuilder<T extends ContentI
|
|||
@SuppressWarnings("unchecked")
|
||||
public M buildListItemModel(final ContentItem contentItem) {
|
||||
final M model = buildModel();
|
||||
model.setLocale(globalizationHelper.getNegotiatedLocale());
|
||||
|
||||
model.setDescription(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
contentItem.getDescription()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ package org.librecms.pages.models;
|
|||
import org.librecms.contenttypes.Event;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -43,6 +45,13 @@ public class EventListItemModel extends AbstractContentItemListItemModel {
|
|||
return startDate;
|
||||
}
|
||||
|
||||
public String getStartDate(final String pattern) {
|
||||
return DateTimeFormatter
|
||||
.ofPattern(pattern)
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(startDate);
|
||||
}
|
||||
|
||||
public void setStartDate(final LocalDateTime startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
|
@ -50,6 +59,13 @@ public class EventListItemModel extends AbstractContentItemListItemModel {
|
|||
public LocalDateTime getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public String getEndDate(final String pattern) {
|
||||
return DateTimeFormatter
|
||||
.ofPattern(pattern)
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(endDate);
|
||||
}
|
||||
|
||||
public void setEndDate(final LocalDateTime endDate) {
|
||||
this.endDate = endDate;
|
||||
|
|
|
|||
|
|
@ -186,7 +186,8 @@ public class ItemListModel {
|
|||
public List<? extends AbstractContentItemListItemModel> getItems(
|
||||
final String listName
|
||||
) {
|
||||
return Collections.unmodifiableList(
|
||||
final List<? extends AbstractContentItemListItemModel> items
|
||||
= Collections.unmodifiableList(
|
||||
buildList(
|
||||
buildLimitToType(getLimitToTypeSetting(listName)),
|
||||
collectCategories(
|
||||
|
|
@ -208,6 +209,8 @@ public class ItemListModel {
|
|||
getOffset(listName, getPageSizeSetting(listName))
|
||||
)
|
||||
);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<? extends AbstractContentItemListItemModel> buildList(
|
||||
|
|
|
|||
|
|
@ -36,6 +36,22 @@ public class NewsListItemModel extends AbstractContentItemListItemModel {
|
|||
return releaseDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the release date of the news represeted by this model formatted
|
||||
* using the provided pattern. The pattern MUST be a valid pattern for
|
||||
* {@link DateTimeFormatter#ofPattern(java.lang.String) }.
|
||||
*
|
||||
* @param pattern The pattern to use for formatting the release date.
|
||||
*
|
||||
* @return The formatted release date.
|
||||
*/
|
||||
public String getReleaseDate(final String pattern) {
|
||||
return DateTimeFormatter
|
||||
.ofPattern(pattern, getLocale())
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(releaseDate);
|
||||
}
|
||||
|
||||
public String getReleaseDateAsString() {
|
||||
return DateTimeFormatter.ISO_DATE_TIME
|
||||
.withZone(ZoneId.systemDefault())
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
|
|
|||
Loading…
Reference in New Issue