CCM NG: More classes for the new page model

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5061 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-10-19 12:59:58 +00:00
parent 5de1dcf43f
commit 13cf0784f5
11 changed files with 770 additions and 11 deletions

View File

@ -39,7 +39,6 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import static org.librecms.CmsConstants.*; import static org.librecms.CmsConstants.*;

View File

@ -20,13 +20,10 @@ package org.librecms.pagemodel;
import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.UnexpectedErrorException; import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.pagemodel.ComponentBuilder; import org.libreccm.pagemodel.ComponentBuilder;
import org.libreccm.pagemodel.ComponentModel;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemL10NManager; import org.librecms.contentsection.ContentItemL10NManager;
@ -40,12 +37,16 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -195,7 +196,7 @@ public abstract class AbstractContentItemComponentBuilder<T extends ContentItemC
final List<Map<String, Object>> associatedObjs = new ArrayList<>(); final List<Map<String, Object>> associatedObjs = new ArrayList<>();
for (final Object obj : collection) { for (final Object obj : collection) {
associatedObjs.add(generateAssociatedObject(obj)); associatedObjs.add(generateAssociatedObject(obj, language));
} }
result.put(propertyName, associatedObjs); result.put(propertyName, associatedObjs);
@ -219,17 +220,115 @@ public abstract class AbstractContentItemComponentBuilder<T extends ContentItemC
} else { } else {
final Map<String, Object> associatedObj; final Map<String, Object> associatedObj;
try { try {
associatedObj associatedObj = generateAssociatedObject(
= generateAssociatedObject(readMethod.invoke(item)); readMethod.invoke(item), language);
} catch (IllegalAccessException | InvocationTargetException ex) { } catch (IllegalAccessException | InvocationTargetException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
result.put(propertyName, associatedObj); result.put(propertyName, associatedObj);
} }
final Set<String> includedPropertyPaths = componentModel
.getIncludedPropertyPaths();
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(item.getClass());
} catch (IntrospectionException ex) {
throw new UnexpectedErrorException(ex);
}
final Map<String, PropertyDescriptor> propertyDescriptors = Arrays
.stream(beanInfo.getPropertyDescriptors())
.collect(Collectors.toMap(PropertyDescriptor::getName,
descriptor -> descriptor));
for (final String propertyPath : includedPropertyPaths) {
final String[] pathTokens = propertyPath.split(".");
if (pathTokens.length < 3) {
continue;
}
if (!propertyDescriptors.containsKey(pathTokens[0])) {
continue;
}
final Object propResult = renderPropertyPath(
propertyDescriptors.get(pathTokens[0]),
Arrays.copyOfRange(pathTokens, 1, pathTokens.length),
language,
item);
if (propResult != null) {
result.put(propertyPath, propResult);
}
}
} }
protected Map<String, Object> generateAssociatedObject(final Object obj) { protected Object renderPropertyPath(
final PropertyDescriptor propertyDescriptor,
final String[] propertyPath,
final Locale language,
final Object item) {
if (propertyPath.length == 1) {
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(item.getClass());
} catch (IntrospectionException ex) {
throw new UnexpectedErrorException(ex);
}
final Map<String, PropertyDescriptor> propertyDescriptors = Arrays
.stream(beanInfo.getPropertyDescriptors())
.collect(Collectors.toMap(PropertyDescriptor::getName,
descriptor -> descriptor));
if (propertyDescriptors.containsKey(propertyPath[0])) {
final Method readMethod = propertyDescriptors
.get(propertyPath[0])
.getReadMethod();
try {
return readMethod.invoke(item);
} catch(IllegalAccessException | InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
} else {
return null;
}
} else {
final Method readMethod = propertyDescriptor.getReadMethod();
final Object obj;
try {
obj = readMethod.invoke(item);
} catch (IllegalAccessException | InvocationTargetException ex) {
throw new UnexpectedErrorException(ex);
}
if (isValueType(obj.getClass())) {
return null;
}
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(obj.getClass());
} catch (IntrospectionException ex) {
throw new UnexpectedErrorException(ex);
}
final Map<String, PropertyDescriptor> propertyDescriptors = Arrays
.stream(beanInfo.getPropertyDescriptors())
.collect(Collectors.toMap(PropertyDescriptor::getName,
descriptor -> descriptor));
if (propertyDescriptors.containsKey(propertyPath[0])) {
return renderPropertyPath(
propertyDescriptors.get(propertyPath[0]),
Arrays.copyOfRange(propertyPath, 1, propertyPath.length),
language,
item);
} else {
return null;
}
}
}
protected Map<String, Object> generateAssociatedObject(
final Object obj, final Locale language) {
final BeanInfo beanInfo; final BeanInfo beanInfo;
try { try {
@ -249,8 +348,17 @@ public abstract class AbstractContentItemComponentBuilder<T extends ContentItemC
try { try {
result.put(propertyDescriptor.getName(), result.put(propertyDescriptor.getName(),
readMethod.invoke(obj)); readMethod.invoke(obj));
} catch (IllegalAccessException } catch (IllegalAccessException | InvocationTargetException ex) {
| InvocationTargetException ex) { throw new UnexpectedErrorException(ex);
}
} else if (LocalizedString.class.isAssignableFrom(type)) {
final Method readMethod = propertyDescriptor.getReadMethod();
try {
final LocalizedString str = (LocalizedString) readMethod
.invoke(obj);
result.put(propertyDescriptor.getName(),
str.getValue(language));
} catch (IllegalAccessException | InvocationTargetException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
} }

View File

@ -0,0 +1,176 @@
/*
* Copyright (C) 2017 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.pagemodel;
import org.libreccm.pagemodel.ComponentModel;
import org.librecms.contentsection.ContentItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import static org.librecms.CmsConstants.*;
/**
* A component for displaying the list of {@link ContentItem}s assigned to a
* Category.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "ITEM_LIST_COMPONENTS", schema = DB_SCHEMA)
public class ItemListComponent extends ComponentModel {
private static final long serialVersionUID = -8058080493341203684L;
/**
* Should the list show also items assigned to sub categories?
*/
@Column(name = "DESCINDING")
private boolean descending;
/**
* Include only the types listed here into the list
*/
@ElementCollection
@CollectionTable(name = "ITEM_LIST_LIMIT_TO_TYPES",
schema = DB_SCHEMA,
joinColumns = {
@JoinColumn(name = "ITEM_LIST_ID")
})
private Set<String> limitToTypes;
/**
* Order the list by this properties. Warning: All items must have the
* properties listed here, otherwise an error will occur!
*/
@ElementCollection
@CollectionTable(name = "ITEM_LIST_ORDER",
schema = DB_SCHEMA,
joinColumns = {
@JoinColumn(name = "ITEM_LIST_ID")
})
private List<String> listOrder;
public boolean isDescending() {
return descending;
}
public void setDescending(final boolean descending) {
this.descending = descending;
}
public Set<String> getLimitToTypes() {
return Collections.unmodifiableSet(limitToTypes);
}
public void addLimitToTypes(final String type) {
limitToTypes.add(type);
}
public void removeLimitToType(final String type) {
limitToTypes.remove(type);
}
public void setLimitToTypes(final Set<String> limitToTypes) {
this.limitToTypes = new HashSet<>(limitToTypes);
}
public List<String> getListOrder() {
return Collections.unmodifiableList(listOrder);
}
public void addListOrder(final String order) {
listOrder.add(order);
}
public void removeListOrder(final String order) {
listOrder.remove(order);
}
public void setListOrder(final List<String> listOrder) {
this.listOrder = new ArrayList<>(listOrder);
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 41 * hash + (descending ? 1 : 0);
hash = 41 * hash + Objects.hashCode(limitToTypes);
hash = 41 * hash + Objects.hashCode(listOrder);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ItemListComponent)) {
return false;
}
final ItemListComponent other = (ItemListComponent) obj;
if (!other.canEqual(this)) {
return false;
}
if (descending != other.isDescending()) {
return false;
}
if (!Objects.equals(limitToTypes, other.getLimitToTypes())) {
return false;
}
return Objects.equals(listOrder, other.getListOrder());
}
@Override
public boolean canEqual(final Object obj) {
return obj instanceof ItemListComponent;
}
@Override
public String toString(final String data) {
return super.toString(String.format(", descending = %b, "
+ "limitToTypes = %s, "
+ "listOrder = %s%s",
descending,
Objects.toString(limitToTypes),
Objects.toString(listOrder),
data));
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentType;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <T>
*/
public abstract class AbstractContentItemRenderer<T extends ContentItem> {
public Map<String, Object> render(final T item, final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("objectId", item.getObjectId());
result.put("uuid", item.getUuid());
result.put("displayName", item.getDisplayName());
result.put("itemUuid", item.getItemUuid());
result.put("name", item.getName().getValue(language));
result.put("title", item.getTitle().getValue(language));
result.put("contentType", renderContentType(item.getContentType(),
language));
result.put("description", item.getDescription().getValue(language));
result.put("creationDate", item.getCreationDate());
result.put("lastModified", item.getLastModified());
result.put("creationUserName", item.getCreationUserName());
result.put("lastModifyingUserName", item.getLastModifyingUserName());
renderItem(item, language, result);
return result;
}
public abstract void renderItem(final T item,
final Locale language,
final Map<String, Object> result);
protected Map<String, Object> renderContentType(
final ContentType contentType, final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("objectId", contentType.getObjectId());
result.put("uuid", contentType.getUuid());
result.put("displayName", contentType.getDisplayName());
result.put("label", contentType.getLabel().getValue(language));
return result;
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contenttypes.Article;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ContentItemRenderer(renders = Article.class)
@RequestScoped
public class ArticleRenderer extends AbstractContentItemRenderer<Article> {
@Override
public void renderItem(final Article article,
final Locale language,
final Map<String, Object> result) {
result.put("text", article.getText().getValue(language));
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contentsection.ContentItem;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Qualifier annotation for implementations of
* {@link AbstractContentItemRenderer}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ContentItemRenderer {
/**
* The type of Item which can be rendered by the annotated content item
* renderer.
*
* @return
*/
Class<? extends ContentItem> renders();
String mode() default "--DEFAULT--";
}

View File

@ -0,0 +1,135 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.librecms.contentsection.ContentItem;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class ContentItemRenderers {
private static final Logger LOGGER = LogManager
.getLogger(ContentItemRenderers.class);
@Inject
private Instance<AbstractContentItemRenderer<?>> renderers;
public <T extends ContentItem> AbstractContentItemRenderer<T> findRenderer(
final Class<T> itemType) {
LOGGER.debug("Trying to find default renderer for item type \"{}\"...",
itemType.getName());
return findRenderer(itemType, "--DEFAULT--");
}
public <T extends ContentItem> AbstractContentItemRenderer<T> findRenderer(
final Class<T> itemType, final String mode) {
LOGGER.debug("Trying to find default renderer for item type \"{}\""
+ "and mode \"{}\"...",
itemType.getName(),
mode);
final ContentItemRendererLiteral literal
= new ContentItemRendererLiteral(
itemType, mode);
final Instance<AbstractContentItemRenderer<?>> instance = renderers
.select(literal);
if (instance.isUnsatisfied()) {
if ("--DEFAULT--".equals(mode)) {
LOGGER.warn("No renderer for item type \"{}\" and mode "
+ "\"--DEFAULT--\". Returning default renderer.",
itemType.getName());
return new AbstractContentItemRenderer<T>() {
@Override
public void renderItem(final T item,
final Locale language,
final Map<String, Object> result) {
//Nothing here.
}
};
} else {
LOGGER.warn("No renderer for item type \"{}\" and mode "
+ "\"{}\". Trying to find renderer for "
+ "mode \"--DEFAULT--\".",
itemType.getName(),
mode);
return findRenderer(itemType);
}
} else {
final AbstractContentItemRenderer<?> renderer = instance
.iterator()
.next();
@SuppressWarnings("unchecked")
final AbstractContentItemRenderer<T> result
= (AbstractContentItemRenderer<T>) renderer;
return result;
}
}
private class ContentItemRendererLiteral
extends AnnotationLiteral<ContentItemRenderer>
implements ContentItemRenderer {
private static final long serialVersionUID = 6104170621944116228L;
private final Class<? extends ContentItem> renders;
private final String mode;
public ContentItemRendererLiteral(
final Class<? extends ContentItem> renders,
final String mode) {
this.renders = renders;
this.mode = mode;
}
@Override
public Class<? extends ContentItem> renders() {
return renders;
}
@Override
public String mode() {
return mode;
}
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contenttypes.Event;
import java.util.Locale;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ContentItemRenderer(renders = Event.class)
public class EventRenderer extends AbstractContentItemRenderer<Event> {
@Override
public void renderItem(final Event event,
final Locale language,
final Map<String, Object> result) {
result.put("text", event.getText().getValue(language));
result.put("startDate", event.getStartDate());
result.put("endDate", event.getEndDate());
result.put("eventDate", event.getEventDate().getValue(language));
result.put("location", event.getLocation().getValue(language));
result.put("mainContributor",
event.getMainContributor().getValue(language));
result.put("eventType", event.getEventType().getValue(language));
result.put("mapLink", event.getMapLink());
result.put("cost", event.getCost().getValue(language));
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contenttypes.MultiPartArticle;
import org.librecms.contenttypes.MultiPartArticleSection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ContentItemRenderer(renders = MultiPartArticle.class)
public class MultiPartArticleRenderer
extends AbstractContentItemRenderer<MultiPartArticle> {
@Override
public void renderItem(final MultiPartArticle article,
final Locale language,
final Map<String, Object> result) {
result.put("summary", article.getSummary().getValue(language));
result.put("sections",
article
.getSections()
.stream()
.map(section -> renderSection(section, language))
.collect(Collectors.toList()));
}
protected Map<String, Object> renderSection(
final MultiPartArticleSection section, final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("sectionId", section.getSectionId());
result.put("title", section.getTitle().getValue(language));
result.put("rank", section.getRank());
result.put("pageBreak", section.isPageBreak());
result.put("text", section.getText().getValue(language));
return result;
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2017 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.pagemodel.contentitems;
import org.librecms.contenttypes.News;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ContentItemRenderer(renders = News.class)
@RequestScoped
public class NewsRenderer extends AbstractContentItemRenderer<News> {
@Override
public void renderItem(final News news,
final Locale language,
final Map<String, Object> result) {
result.put("text", news.getText().getValue(language));
result.put("releaseDate", news.getReleaseDate());
}
}

View File

@ -27,10 +27,10 @@ import org.libreccm.categorization.DomainOwnership;
import org.libreccm.core.Resource; import org.libreccm.core.Resource;
import org.libreccm.portation.Portable; import org.libreccm.portation.Portable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -40,6 +40,16 @@ import java.util.Objects;
import static org.libreccm.core.CoreConstants.DB_SCHEMA; import static org.libreccm.core.CoreConstants.DB_SCHEMA;
import static org.libreccm.web.WebConstants.WEB_XML_NS; import static org.libreccm.web.WebConstants.WEB_XML_NS;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>