CCM NG: JavaDoc and missing files for PageModel
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4465 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 7b08adbdf7
pull/2/head
parent
b20e5c8443
commit
f0928243cb
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.librecms.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.Page;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class BasePage extends Page {
|
||||
|
||||
public void setPageAttribute(final String name, final String value) {
|
||||
super.setAttribute(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.librecms.pagemodel;
|
||||
|
||||
import com.arsdigita.templating.Templating;
|
||||
import com.arsdigita.xml.Document;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@WebServlet(urlPatterns = {"*.bebop"})
|
||||
public class PageModel extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1056528247823275004L;
|
||||
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest request,
|
||||
final HttpServletResponse response)
|
||||
throws ServletException {
|
||||
|
||||
final BasePage page = new BasePage();
|
||||
final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
|
||||
final ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(
|
||||
"JavaScript");
|
||||
scriptEngine.put("page", page);
|
||||
|
||||
try {
|
||||
scriptEngine.eval(
|
||||
"load(\'nashorn:mozilla_compat.js\');\n"
|
||||
+ "importClass(org.librecms.pagemodel.BasePage);\n"
|
||||
+ "var BasePage = Java.type('org.librecms.pagemodel.BasePage');\n"
|
||||
// + "var page = new BasePage;\n"
|
||||
// + "print(page.getClass().getName());\n"
|
||||
+ "page.setPageAttribute(\'name\', \'page-model-demo\');\n"
|
||||
+ "page.setPageAttribute(\'application\', \'content\');\n"
|
||||
+ "label = new com.arsdigita.bebop.Label(\'Test\');\n"
|
||||
+ "page.add(label);\n");
|
||||
} catch (ScriptException ex) {
|
||||
throw new ServletException(ex);
|
||||
}
|
||||
|
||||
// final BasePage page = (BasePage) scriptEngine.get("page");
|
||||
page.lock();
|
||||
|
||||
final Document document = page.buildDocument(request, response);
|
||||
Templating.getPresentationManager().servePage(document,
|
||||
request,
|
||||
response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.libreccm.pagemodel;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -37,25 +38,31 @@ public abstract class AbstractPageBuilder<P> implements PageBuilder<P> {
|
|||
final P page = buildPage();
|
||||
|
||||
for (final ComponentModel componentModel : pageModel.getComponents()) {
|
||||
final Object component = buildComponent(
|
||||
final Optional<Object> component = buildComponent(
|
||||
componentModel, componentModel.getClass());
|
||||
addComponent(page, component);
|
||||
if (component.isPresent()) {
|
||||
addComponent(page, component);
|
||||
}
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
protected <M extends ComponentModel> Object buildComponent(
|
||||
final ComponentModel componentModel,
|
||||
protected <M extends ComponentModel> Optional<Object> buildComponent(
|
||||
final ComponentModel componentModel,
|
||||
final Class<M> componentModelClass) {
|
||||
|
||||
componentBuilderManager.findComponentBuilder(componentModel.getClass(),
|
||||
getType());
|
||||
|
||||
final ComponentBuilder<M, ?> builder = componentBuilderManager
|
||||
|
||||
final Optional<ComponentBuilder<M, ?>> builder = componentBuilderManager
|
||||
.findComponentBuilder(componentModelClass, getType());
|
||||
|
||||
return builder.buildComponent((M) componentModel);
|
||||
|
||||
if (builder.isPresent()) {
|
||||
return Optional.of(builder.get().buildComponent((M) componentModel));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getType();
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@
|
|||
package org.libreccm.pagemodel;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
import javax.inject.Inject;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -31,37 +34,44 @@ import javax.inject.Inject;
|
|||
@RequestScoped
|
||||
public class ComponentBuilderManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ComponentBuilderManager.class);
|
||||
|
||||
@Inject
|
||||
private Instance<ComponentBuilder<?, ?>> componentBuilders;
|
||||
|
||||
public <M extends ComponentModel> ComponentBuilder<M, ?> findComponentBuilder(
|
||||
public <M extends ComponentModel> Optional<ComponentBuilder<M, ?>> findComponentBuilder(
|
||||
final Class<M> componentModelClass,
|
||||
final String type) {
|
||||
|
||||
LOGGER.debug("Trying to find ComponentBuilder for ComponentModel\"{}\""
|
||||
+ "and type \"{}\"...",
|
||||
componentModelClass.getName(),
|
||||
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));
|
||||
LOGGER.warn("No ComponentBuilder 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\" and "
|
||||
+ "type \"%s\" available. Something is wrong",
|
||||
componentModelClass.getName(),
|
||||
type));
|
||||
} else {
|
||||
final Iterator<ComponentBuilder<?, ?>> iterator = instance.iterator();
|
||||
final Iterator<ComponentBuilder<?, ?>> iterator = instance.
|
||||
iterator();
|
||||
final ComponentBuilder<?, ?> componentBuilder = iterator.next();
|
||||
|
||||
return (ComponentBuilder<M, ?>) componentBuilder;
|
||||
|
||||
return Optional.of((ComponentBuilder<M, ?>) componentBuilder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class ComponentModelTypeLiteral
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
|
@ -41,6 +43,7 @@ import javax.validation.constraints.NotNull;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@Table(name = "PAGE_MODEL_COMPONENT_MODELS", schema = CoreConstants.DB_SCHEMA)
|
||||
public class ComponentModel implements Serializable {
|
||||
|
||||
|
|
|
|||
|
|
@ -57,5 +57,7 @@ public interface PageBuilder<P> {
|
|||
* @return The page generated from the provided {@link PageModel}.
|
||||
*/
|
||||
P buildPage(PageModel pageModel);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ import org.libreccm.pagemodel.AbstractPageBuilder;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public abstract class AbstractBebopPageBuilder extends AbstractPageBuilder<Page>{
|
||||
public abstract class AbstractBebopPageBuilder extends AbstractPageBuilder<Page> {
|
||||
|
||||
public static final String BEBOP = "Bebop";
|
||||
|
||||
|
||||
@Override
|
||||
protected String getType() {
|
||||
return BEBOP;
|
||||
|
|
@ -40,18 +40,21 @@ public abstract class AbstractBebopPageBuilder extends AbstractPageBuilder<Page>
|
|||
@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, "");
|
||||
|
||||
|
||||
final String application = Web.getWebContext().getApplication().
|
||||
getPrimaryUrl();
|
||||
final Page page = PageFactory.buildPage(application, "");
|
||||
|
||||
addDefaultComponents(page);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
public abstract void addDefaultComponents(final Page page);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,18 +17,27 @@
|
|||
* MA 02110-1301 USA
|
||||
*/
|
||||
/**
|
||||
* <p>
|
||||
* The {@code pagemodel} packages provides an abstraction layer between the data
|
||||
* model of page and its generating components. This layer replaces the JSP
|
||||
* templates which were used in previous versions for this purpose.
|
||||
*
|
||||
* </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
|
||||
* 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 container which are read by
|
||||
* some builder classes. Because we are not using an active code in the page
|
||||
* 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
|
||||
* models this avoids a potential attack point.
|
||||
* </p>
|
||||
* <p>
|
||||
* The central interface is the {@link org.libreccm.pagemodel.PageBuilder}
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.libreccm.pagemodel;
|
||||
|
|
|
|||
Loading…
Reference in New Issue