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