CCM NG: Abstract base classes for the PageBuilder interface of the PageModel system.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4461 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-12-05 12:43:14 +00:00
parent 80d3a02996
commit 3863a2f32f
9 changed files with 233 additions and 7 deletions

View File

@ -242,6 +242,16 @@ public class ContentSectionServlet extends BaseApplicationServlet {
final RequestContext ctx = DispatcherHelper.getRequestContext(); final RequestContext ctx = DispatcherHelper.getRequestContext();
final String url = ctx.getRemainingURLPart(); final String url = ctx.getRemainingURLPart();
//Only for testing PageModel
if (url != null && url.endsWith("page-model/")) {
getServletContext()
.getRequestDispatcher("/page-model.bebop")
.include(request, response);
return;
}
//End Test PageModel
LOGGER.info("Resolving URL {} and trying as item first."); LOGGER.info("Resolving URL {} and trying as item first.");
final ItemResolver itemResolver = getItemResolver(section); final ItemResolver itemResolver = getItemResolver(section);

View File

@ -1575,4 +1575,4 @@ alter table CCM_CMS.ARTICLE_LEADS
alter table CCM_CMS.WORKFLOW_TASKS alter table CCM_CMS.WORKFLOW_TASKS
add constraint FKge2x94m1y9tr7mk26ensyn674 add constraint FKge2x94m1y9tr7mk26ensyn674
foreign key (TASK_ID) foreign key (TASK_ID)
references CCM_CORE.WORKFLOW_USER_TASKS; references CCM_CORE.WORKFLOW_ASSIGNABLE_TASKS;

View File

@ -1,5 +1,3 @@
create table CCM_CMS.ARTICLE_LEADS ( create table CCM_CMS.ARTICLE_LEADS (
OBJECT_ID int8 not null, OBJECT_ID int8 not null,
LOCALIZED_VALUE text, LOCALIZED_VALUE text,
@ -1577,4 +1575,4 @@
alter table CCM_CMS.WORKFLOW_TASKS alter table CCM_CMS.WORKFLOW_TASKS
add constraint FKge2x94m1y9tr7mk26ensyn674 add constraint FKge2x94m1y9tr7mk26ensyn674
foreign key (TASK_ID) foreign key (TASK_ID)
references CCM_CORE.WORKFLOW_USER_TASKS; references CCM_CORE.WORKFLOW_ASSIGNABLE_TASKS;

View File

@ -495,6 +495,7 @@ public class CCMDispatcherServlet extends BaseServlet {
final StringBuffer target = new StringBuffer(128); final StringBuffer target = new StringBuffer(128);
target.append(m_typeURI); target.append(m_typeURI);
target.append("/");
target.append(path.substring(m_instanceURI.length())); target.append(path.substring(m_instanceURI.length()));
target.append("?"); target.append("?");
target.append(BaseApplicationServlet.APPLICATION_ID_PARAMETER); target.append(BaseApplicationServlet.APPLICATION_ID_PARAMETER);

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2016 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.libreccm.pagemodel;
import javax.inject.Inject;
/**
*
* @param <P> Page class
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*
*/
public abstract class AbstractPageBuilder<P> implements PageBuilder<P> {
@Inject
private ComponentBuilderManager componentBuilderManager;
@Override
public P buildPage(final PageModel pageModel) {
final P page = buildPage();
for (final ComponentModel componentModel : pageModel.getComponents()) {
final Object component = buildComponent(
componentModel, componentModel.getClass());
addComponent(page, component);
}
return page;
}
protected <M extends ComponentModel> Object buildComponent(
final ComponentModel componentModel,
final Class<M> componentModelClass) {
componentBuilderManager.findComponentBuilder(componentModel.getClass(),
getType());
final ComponentBuilder<M, ?> builder = componentBuilderManager
.findComponentBuilder(componentModelClass, getType());
return builder.buildComponent((M) componentModel);
}
protected abstract String getType();
protected abstract void addComponent(P page, Object component);
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2016 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.libreccm.pagemodel;
import java.util.Iterator;
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 ComponentBuilderManager {
@Inject
private Instance<ComponentBuilder<?, ?>> componentBuilders;
public <M extends ComponentModel> ComponentBuilder<M, ?> findComponentBuilder(
final Class<M> componentModelClass,
final String type) {
final ComponentModelTypeLiteral literal = new ComponentModelTypeLiteral(
componentModelClass, type);
final Instance<ComponentBuilder<?, ?>> instance = componentBuilders
.select(literal);
if (instance.isUnsatisfied()) {
throw new IllegalArgumentException(String.format(
"No ComponentBuilder for component model \"%s\" and type \"%s\" "
+ "available.",
componentModelClass.getName(),
type));
} else if(instance.isAmbiguous()) {
throw new IllegalArgumentException(String.format(
"Multiple ComponentBuilders for component model \"%s\" and type \"%s\" "
+ "available. Something is wrong",
componentModelClass.getName(),
type));
} else {
final Iterator<ComponentBuilder<?, ?>> iterator = instance.iterator();
final ComponentBuilder<?, ?> componentBuilder = iterator.next();
return (ComponentBuilder<M, ?>) componentBuilder;
}
}
private class ComponentModelTypeLiteral
extends AnnotationLiteral<ComponentModelType>
implements ComponentModelType {
private static final long serialVersionUID = -2601632434295178600L;
private final Class<? extends ComponentModel> componentModel;
private final String type;
public ComponentModelTypeLiteral(
final Class<? extends ComponentModel> componentModel,
final String type) {
this.componentModel = componentModel;
this.type = type;
}
@Override
public Class<? extends ComponentModel> componentModel() {
return componentModel;
}
@Override
public String type() {
return type;
}
}
}

View File

@ -26,7 +26,7 @@ import java.lang.annotation.Target;
import javax.inject.Qualifier; import javax.inject.Qualifier;
/** /**
* Specifies for which view technology a {@link ComponentBuilder} builds the * Specifies for which component and view technology a {@link ComponentBuilder} builds the
* components. * components.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -36,6 +36,8 @@ import javax.inject.Qualifier;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface ComponentModelType { public @interface ComponentModelType {
Class<? extends ComponentModel> componentModel();
String type(); String type();
} }

View File

@ -45,7 +45,6 @@ public class PageBuilderManager {
type, applicationType); type, applicationType);
final Instance<PageBuilder<?>> instance = pageBuilders.select(literal); final Instance<PageBuilder<?>> instance = pageBuilders.select(literal);
if (instance.isUnsatisfied()) { if (instance.isUnsatisfied()) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"No PageBuilder for type \"%s\" and application type \"%s\" " "No PageBuilder for type \"%s\" and application type \"%s\" "
@ -54,7 +53,7 @@ public class PageBuilderManager {
applicationType)); applicationType));
} else if (instance.isAmbiguous()) { } else if (instance.isAmbiguous()) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"There are more than one PageBuilders for type \"%s\" and " "Multiple PageBuilders for type \"%s\" and "
+ "application type \"%s\" avilable. Something is wrong.", + "application type \"%s\" avilable. Something is wrong.",
type, type,
applicationType)); applicationType));

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2016 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.libreccm.pagemodel.bebop;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageFactory;
import com.arsdigita.web.Web;
import org.libreccm.pagemodel.AbstractPageBuilder;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public abstract class AbstractBebopPageBuilder extends AbstractPageBuilder<Page>{
public static final String BEBOP = "Bebop";
@Override
protected String getType() {
return BEBOP;
}
@Override
protected void addComponent(final Page page, final Object component) {
final Component bebopComponent = (Component) component;
page.add(bebopComponent);
}
@Override
public Page buildPage() {
final String application = Web.getWebContext().getApplication().getPrimaryUrl();
final Page page = PageFactory.buildPage(application, "");
return page;
}
public abstract void addDefaultComponents(final Page page);
}