CCM NG: Renamed classes ending with "Builder" in in the pagemodel packages to end with "Renderer" to avoid confusion. Classes with a name ending with "Builder" are usually classes which implement the Builder pattern. The classes rendering a page model and its components do not implemement this pattern.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5071 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: cac7214f83
pull/2/head
jensp 2017-10-23 05:57:40 +00:00
parent 9dac93e17a
commit 3b971b3682
16 changed files with 107 additions and 118 deletions

View File

@ -21,7 +21,6 @@ package org.librecms.pagemodel;
import com.arsdigita.kernel.KernelConfig;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.pagemodel.ComponentBuilder;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemL10NManager;
@ -42,13 +41,15 @@ import javax.ws.rs.core.Response;
import static org.librecms.pages.PagesConstants.*;
import org.libreccm.pagemodel.ComponentRenderer;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <T>
*/
public abstract class AbstractContentItemComponentBuilder<T extends ContentItemComponent>
implements ComponentBuilder<T> {
public abstract class AbstractContentItemComponentRenderer<T extends ContentItemComponent>
implements ComponentRenderer<T> {
@Inject
private ConfigurationManager confManager;
@ -70,7 +71,7 @@ public abstract class AbstractContentItemComponentBuilder<T extends ContentItemC
@Transactional(Transactional.TxType.REQUIRED)
@Override
public Map<String, Object> buildComponent(
public Map<String, Object> renderComponent(
final T componentModel,
final Map<String, Object> parameters) {

View File

@ -48,8 +48,8 @@ import static org.librecms.pages.PagesConstants.*;
*/
@RequestScoped
@ComponentModelType(componentModel = CategorizedItemComponent.class)
public class CategorizedItemComponentBuilder
extends AbstractContentItemComponentBuilder<CategorizedItemComponent> {
public class CategorizedItemComponentRenderer
extends AbstractContentItemComponentRenderer<CategorizedItemComponent> {
@Inject
private CategoryRepository categoryRepo;

View File

@ -27,7 +27,6 @@ import org.libreccm.categorization.DomainRepository;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.CcmObject;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.pagemodel.ComponentBuilder;
import org.libreccm.pagemodel.ComponentModelType;
import java.util.HashMap;
@ -43,17 +42,16 @@ import javax.transaction.Transactional;
import static org.librecms.pages.PagesConstants.*;
import org.libreccm.pagemodel.ComponentRenderer;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@ComponentModelType(componentModel = CategoryTreeComponent.class)
public class CategoryTreeComponentBuilder
implements ComponentBuilder<CategoryTreeComponent> {
@Inject
private DomainRepository domainRepo;
public class CategoryTreeComponentRenderer
implements ComponentRenderer<CategoryTreeComponent> {
@Inject
private CategoryManager categoryManager;
@ -64,12 +62,9 @@ public class CategoryTreeComponentBuilder
@Inject
private ConfigurationManager confManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Transactional(Transactional.TxType.REQUIRED)
@Override
public Map<String, Object> buildComponent(
public Map<String, Object> renderComponent(
final CategoryTreeComponent componentModel,
final Map<String, Object> parameters) {

View File

@ -21,16 +21,10 @@ package org.librecms.pagemodel;
import org.libreccm.pagemodel.ComponentModel;
import org.libreccm.pagemodel.PageModel;
import java.util.Collections;
import java.util.HashSet;
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.*;

View File

@ -35,8 +35,8 @@ import javax.ws.rs.NotFoundException;
*/
@RequestScoped
@ComponentModelType(componentModel = FixedContentItemComponent.class)
public class FixedContentItemComponentBuilder
extends AbstractContentItemComponentBuilder<FixedContentItemComponent> {
public class FixedContentItemComponentRenderer
extends AbstractContentItemComponentRenderer<FixedContentItemComponent> {
@Inject
private ContentItemRepository itemRepo;

View File

@ -41,8 +41,8 @@ import static org.librecms.pages.PagesConstants.*;
*/
@RequestScoped
@ComponentModelType(componentModel = GreetingItemComponent.class)
public class GreetingItemComponentBuilder
extends AbstractContentItemComponentBuilder<GreetingItemComponent> {
public class GreetingItemComponentRenderer
extends AbstractContentItemComponentRenderer<GreetingItemComponent> {
@Inject
private CategoryRepository categoryRepo;

View File

@ -76,6 +76,7 @@ public class ItemListComponent extends ComponentModel {
joinColumns = {
@JoinColumn(name = "ITEM_LIST_ID")
})
@Column(name = "LIST_ORDER")
private List<String> listOrder;
public boolean isDescending() {

View File

@ -18,7 +18,7 @@
*/
package org.librecms.pages;
import org.libreccm.pagemodel.AbstractPageBuilder;
import org.libreccm.pagemodel.AbstractPageRenderer;
import java.util.HashMap;
import java.util.Map;
@ -30,10 +30,10 @@ import javax.enterprise.context.RequestScoped;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class CmsPageBuilder extends AbstractPageBuilder {
public class CmsPageBuilder extends AbstractPageRenderer {
@Override
public Map<String, Object> buildPage(final Map<String, Object> parameters) {
public Map<String, Object> renderPage(final Map<String, Object> parameters) {
final Map<String, Object> result = new HashMap<>();

View File

@ -444,9 +444,9 @@ public class PagesRouter {
final Map<String, Object> result;
if (pageModel == null) {
result = pageBuilder.buildPage(parameters);
result = pageBuilder.renderPage(parameters);
} else {
result = pageBuilder.buildPage(pageModel, parameters);
result = pageBuilder.renderPage(pageModel, parameters);
}
return result;

View File

@ -25,40 +25,40 @@ import javax.inject.Inject;
import java.util.Optional;
/**
* An abstract base class for implementations of the {@link PageBuilder}
* An abstract base class for implementations of the {@link PageRenderer}
* interface providing some functionality needed by all implementations of the
* {@link PageBuilder} interface.
* {@link PageRenderer} interface.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*
*/
public abstract class AbstractPageBuilder implements PageBuilder {
public abstract class AbstractPageRenderer implements PageRenderer {
@Inject
private ComponentBuilderManager componentBuilderManager;
private ComponentRendererManager componentRendererManager;
/**
* Build a {@code Page} based on a {@link PageModel}. This implementation
* first calls {@link #buildPage()} to create the page object. After that
* Renders a {@code Page} based on a {@link PageModel}. This implementation
* first calls {@link #renderPage()} to create the page object. After that
* all {@link ComponentModel}s of the {@link PageModel} are processed and
* the component objects created by the {@link ComponentBuilder}s are added
* the component objects created by the {@link ComponentRenderer}s are added
* to the page.
*
* @param pageModel The {@link PageModel} to process.
* @param parameters Parameters provided by application which wants to
* render a {@link PageModel}. The parameters are passed
* the {@link ComponentBuilder}s.
* the {@link ComponentRenderer}s.
*
* @return A page containing all components from the {@link PageModel}.
*/
@Override
public Map<String, Object> buildPage(final PageModel pageModel,
final Map<String, Object> parameters) {
public Map<String, Object> renderPage(final PageModel pageModel,
final Map<String, Object> parameters) {
final Map<String, Object> page = buildPage(parameters);
final Map<String, Object> page = renderPage(parameters);
for (final ComponentModel componentModel : pageModel.getComponents()) {
final Optional<Object> component = buildComponent(
final Optional<Object> component = renderComponent(
componentModel, componentModel.getClass(),
parameters);
if (component.isPresent()) {
@ -71,7 +71,7 @@ public abstract class AbstractPageBuilder implements PageBuilder {
}
/**
* Helper method for building the components.
* Helper method for rendering the components.
*
* @param <M> Generics variable for the type the component
* created.
@ -79,24 +79,24 @@ public abstract class AbstractPageBuilder implements PageBuilder {
* @param componentModelClass The class of the {@link ComponentModel}.
* @param parameters Parameters provided by application which wants
* to render a {@link PageModel}. The parameters
* are passed the {@link ComponentBuilder}s.
* are passed the {@link ComponentRenderer}s.
*
* @return The components described by the {@code componentModel}.
*/
protected <M extends ComponentModel> Optional<Object> buildComponent(
protected <M extends ComponentModel> Optional<Object> renderComponent(
final ComponentModel componentModel,
final Class<M> componentModelClass,
final Map<String, Object> parameters) {
componentBuilderManager.findComponentBuilder(componentModel.getClass());
componentRendererManager.findComponentRenderer(componentModel.getClass());
final Optional<ComponentBuilder<M>> builder = componentBuilderManager
.findComponentBuilder(componentModelClass);
final Optional<ComponentRenderer<M>> renderer = componentRendererManager
.findComponentRenderer(componentModelClass);
if (builder.isPresent()) {
if (renderer.isPresent()) {
@SuppressWarnings("unchecked")
final M model = (M) componentModel;
return Optional.of(builder.get().buildComponent(model, parameters));
return Optional.of(renderer.get().renderComponent(model, parameters));
} else {
return Optional.empty();
}

View File

@ -25,8 +25,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies for which component and view technology a {@link ComponentBuilder} builds the
* components.
* Specifies which type of components a {@link ComponentRenderer} implenentation
* renders.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ -37,5 +37,4 @@ public @interface ComponentModelType {
Class<? extends ComponentModel> componentModel();
}

View File

@ -21,16 +21,16 @@ package org.libreccm.pagemodel;
import java.util.Map;
/**
* A {@code ComponentBuilder} transforms a {@link ComponentModel} into a
* A {@code ComponentRenderer} transforms a {@link ComponentModel} into a
* component.
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <M> Type of the model the component builder processes.
* @param <M> Type of the model the component renderer processes.
*/
public interface ComponentBuilder<M extends ComponentModel> {
public interface ComponentRenderer<M extends ComponentModel> {
Map<String, Object> buildComponent(M componentModel,
Map<String, Object> renderComponent(M componentModel,
final Map<String, Object> parameters);
}

View File

@ -30,63 +30,63 @@ import java.util.Optional;
/**
* Provides access to all available implementations of the
* {@link ComponentBuilder} interface.
* {@link ComponentRenderer} interface.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class ComponentBuilderManager {
public class ComponentRendererManager {
private static final Logger LOGGER = LogManager.getLogger(
ComponentBuilderManager.class);
ComponentRendererManager.class);
@Inject
private Instance<ComponentBuilder<?>> componentBuilders;
private Instance<ComponentRenderer<?>> componentRenderers;
/**
* Find an implementation of the {@link ComponentBuilder} interface for a
* Find an implementation of the {@link ComponentRenderer} interface for a
* specific {@link ComponentModel}.
*
* @param <M> Generic variable for the subtype of
* {@link ComponentModel} which is produced by
* the {@link ComponentBuilder} implementation.
* the {@link ComponentRenderer} implementation.
* @param componentModelClass The sub class of the {@link ComponentModel}
* for which is processed by the
* {@link ComponentBuilder}.
* {@link ComponentRenderer}.
*
* @return An {@link Optional} containing the implementation of the
* {@link ComponentBuilder} interface for the specified parameters.
* {@link ComponentRenderer} interface for the specified parameters.
* If there is no implementation for the specified parameters an
* empty {@link Optional} is returned.
*/
@SuppressWarnings("unchecked")
public <M extends ComponentModel> Optional<ComponentBuilder<M>> findComponentBuilder(
public <M extends ComponentModel> Optional<ComponentRenderer<M>> findComponentRenderer(
final Class<M> componentModelClass) {
LOGGER.debug("Trying to find ComponentBuilder for ComponentModel\"{}\""
LOGGER.debug("Trying to find ComponentRenderer for ComponentModel\"{}\""
+ "and type \"{}\"...",
componentModelClass.getName());
final ComponentModelTypeLiteral literal = new ComponentModelTypeLiteral(
componentModelClass);
final Instance<ComponentBuilder<?>> instance = componentBuilders
final Instance<ComponentRenderer<?>> instance = componentRenderers
.select(literal);
if (instance.isUnsatisfied()) {
LOGGER.warn("No ComponentBuilder for component model \"%s\" "
LOGGER.warn("No ComponentRenderer for component model \"%s\" "
+ "and type \"%s\". Ignoring component model.");
return Optional.empty();
} else if (instance.isAmbiguous()) {
throw new IllegalStateException(String.format(
"Multiple ComponentBuilders for component model \"%s\"available. "
+ "Something is wrong",
"Multiple ComponentRenderers for component model \"%s\"available. "
+ "Something is wrong",
componentModelClass.getName()));
} else {
final Iterator<ComponentBuilder<?>> iterator = instance.
final Iterator<ComponentRenderer<?>> iterator = instance.
iterator();
final ComponentBuilder<?> componentBuilder = iterator.next();
final ComponentRenderer<?> componentRenderer = iterator.next();
return Optional.of((ComponentBuilder<M>) componentBuilder);
return Optional.of((ComponentRenderer<M>) componentRenderer);
}
}

View File

@ -50,14 +50,14 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* A {@link PageModel} is used by a {@link PageBuilder} implementation to build
* A {@link PageModel} is used by a {@link PageRenderer} implementation to render
* a page. The {@code PageModel} specifics which components are used on a page.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*
* @see PageModelRepository
* @see PageModelManager
* @see PageBuilder
* @see PageRenderer
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)

View File

@ -20,9 +20,8 @@ package org.libreccm.pagemodel;
import java.util.Map;
/**
* Interface for page builders. A page builder is invoked to build a page a
* Interface for page renderers. A page renderer is invoked to render a page of
* specific type. An implementation should be a CDI bean which is annotated with
* the qualifier {@link PageModelType}.
*
@ -33,35 +32,35 @@ import java.util.Map;
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface PageBuilder {
public interface PageRenderer {
/**
* Build a page for the view technology supported by this page builder
* Render a page for the view technology supported by this page renderer
* without any additional components.
* {@link #buildPage(org.libreccm.pagemodel.PageModel)} should use this
* {@link #renderPage(org.libreccm.pagemodel.PageModel)} should use this
* method for creating the default page.
*
* @param parameters Parameters provided by application which wants to
* render a {@link PageModel}. The parameters are passed
* the {@link ComponentBuilder}s.
* the {@link ComponentRenderer}s.
*
* @return A page with the default components.
*/
Map<String, Object> buildPage(Map<String, Object> parameters);
Map<String, Object> renderPage(Map<String, Object> parameters);
/**
* Build a page of type {@code P} using the provided {@link PageModel}.
* Implementations should call the implementation of {@link #buildPage()}
* Render a page of type {@code P} using the provided {@link PageModel}.
* Implementations should call the implementation of {@link #renderPage()}
* for creating the basic page with the default components.
*
* @param pageModel The {@link PageModel} from which the page is generated.
* @param parameters Parameters provided by application which wants to
* render a {@link PageModel}. The parameters are passed
* the {@link ComponentBuilder}s.
* the {@link ComponentRenderer}s.
*
* @return The page generated from the provided {@link PageModel}.
*/
Map<String, Object> buildPage(PageModel pageModel,
Map<String, Object> parameters);
Map<String, Object> renderPage(PageModel pageModel,
Map<String, Object> parameters);
}

View File

@ -24,19 +24,19 @@
* </p>
* <p>
* The Page Model system allows it to specify which components are used on a
* page are therefore which information is displayed on a page. It is intended
* page and therefore which information is displayed on a page. It is intended
* to be used for public pages (like the item page of a content item category
* page in ccm-cms. The Page Model system uses data containers which are read by
* some builder classes. Because we are not using any active code in the page
* a renderer class. Because we are not using any active code in the page
* models this avoids a potential attack point.
* </p>
* <p>
* The central interface is the {@link org.libreccm.pagemodel.PageBuilder}
* The central interface is the {@link org.libreccm.pagemodel.PageRenderer}
* interface. An implementation of this interface will take a
* {@link org.libreccm.pagemodel.PageModel} and process it and create a page
* from it using the view technology supported by the implementation.
* {@code PageBuilder}s are CDI beans. Implementations can be retrieved using
* the {@link org.libreccm.pagemodel.PageBuilderManager#findPageBuilder(String, Class)} method.
* {@code PageRenderer}s are CDI beans. Implementations can be retrieved using
* the {@link org.libreccm.pagemodel.PageRendererManager#findPageRenderer(String, Class)} method.
* </p>
*
*/