CCM NG: Next part of the sites/pages/themes complex

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5038 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-10-11 13:36:54 +00:00
parent cdc2904a3b
commit d71d5de149
13 changed files with 483 additions and 164 deletions

View File

@ -16,15 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.sites;
package org.librecms.pages;
import org.libreccm.categorization.Domain;
import org.libreccm.sites.Site;
import org.libreccm.web.CcmApplication;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
@ -39,48 +39,50 @@ import static org.librecms.CmsConstants.*;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "SITES", schema = DB_SCHEMA)
@Table(name = "PAGES", schema = DB_SCHEMA)
@NamedQueries({
@NamedQuery(
name = "Site.findByName",
query = "SELECT s FROM Site s WHERE s.name = :name"
name = "Pages.findForSite",
query = "SELECT p FROM Pages p JOIN p.site s "
+ "WHERE s.domainOfSite = :domain")
,
@NamedQuery(
name = "Pages.findForDefaultSite",
query = "SELECT p FROM Pages p JOIN p.site s "
+ "WHERE s.defaultSite = true"
)
,
@NamedQuery(
name = "Pages.availableForSite",
query = "SELECT (CASE WHEN COUNT(s) > 0 THEN true ELSE false END) "
+ "FROM Pages p JOIN p.site s "
+ "WHERE s.domainOfSite = :domain")
,
@NamedQuery(
name = "Pages.availableForDefaultSite",
query = "SELECT (CASE WHEN COUNT(p) > 0 THEN true ELSE false END) "
+ "FROM Pages p JOIN p.site s "
+ "WHERE s.defaultSite = true"),
})
public class Site extends CcmApplication implements Serializable {
public class Pages extends CcmApplication implements Serializable {
private static final long serialVersionUID = -352205318143692477L;
/**
* The domain of the site.
*/
@Column(name = "NAME", unique = true)
private String name;
/**
* Should this be the default site which is used when there is no matching
* site?
*/
@Column(name = "DEFAULT_SITE")
private boolean defaultSite;
@OneToOne
@JoinColumn(name = "SITE_ID")
private Site site;
@OneToOne
@JoinColumn(name = "CATEGORY_DOMAIN_ID")
private Domain categoryDomain;
public String getName() {
return name;
public Site getSite() {
return site;
}
public void setName(final String name) {
this.name = name;
}
public boolean isDefaultSite() {
return defaultSite;
}
public void setDefaultSite(boolean defaultSite) {
this.defaultSite = defaultSite;
protected void setSite(final Site site) {
this.site = site;
}
public Domain getCategoryDomain() {
@ -94,9 +96,8 @@ public class Site extends CcmApplication implements Serializable {
@Override
public int hashCode() {
int hash = 7;
hash = 17 * hash + Objects.hashCode(name);
hash = 17 * hash + (defaultSite ? 1 : 0);
hash = 17 * hash + Objects.hashCode(categoryDomain);
hash = 17 * hash + Objects.hashCode(site);
return hash;
}
@ -115,19 +116,16 @@ public class Site extends CcmApplication implements Serializable {
return false;
}
if (!(obj instanceof Site)) {
if (!(obj instanceof Pages)) {
return false;
}
final Site other = (Site) obj;
final Pages other = (Pages) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(name, other.getName())) {
return false;
}
if (defaultSite != other.isDefaultSite()) {
if (!Objects.equals(site, other.getSite())) {
return false;
}
@ -136,17 +134,15 @@ public class Site extends CcmApplication implements Serializable {
@Override
public boolean canEqual(final Object obj) {
return obj instanceof Site;
return obj instanceof Pages;
}
@Override
public String toString(final String data) {
return super.toString(String.format(
", name = \"%s\","
+ "defaultSite = %b%s",
name,
defaultSite,
", site = \"%s\"%s",
Objects.toString(site),
data
));
}

View File

@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.sites;
package org.librecms.pages;
import java.util.HashSet;
import java.util.Set;
@ -30,14 +30,14 @@ import javax.ws.rs.core.Application;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ApplicationPath("/pages")
public class Sites extends Application {
public class PagesApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
classes.add(Pages.class);
classes.add(PagesRouter.class);
return classes;
}

View File

@ -16,29 +16,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.sites;
import org.libreccm.core.CcmObjectRepository;
import javax.enterprise.context.RequestScoped;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
package org.librecms.pages;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class SiteRepository extends CcmObjectRepository {
public final class PagesConstants {
@Transactional(Transactional.TxType.REQUIRED)
public Site findByName(final String name) {
final TypedQuery<Site> query = getEntityManager()
.createNamedQuery("Site.findByName", Site.class);
query.setParameter("name", name);
return query.getSingleResult();
private PagesConstants() {
//Nothing
}
public static final String CATEGORIZATION_TYPE_PAGE_MODEL_INDEX
= "page_model_index";
public static final String CATEGORIZATION_TYPE_PAGE_MODEL_ITEM
= "page_model_item";
}

View File

@ -0,0 +1,95 @@
/*
* 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.pages;
import com.arsdigita.ui.admin.AdminUiConstants;
import org.libreccm.core.AbstractEntityRepository;
import org.libreccm.core.CcmObjectRepository;
import org.libreccm.core.CoreConstants;
import org.libreccm.security.RequiresPrivilege;
import org.libreccm.sites.SiteRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class PagesRepository extends AbstractEntityRepository<Long, Pages> {
@Inject
private SiteRepository siteRepo;
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Pages> findPagesForSite(final String domainOfSite) {
if (siteRepo.hasSiteForDomain(domainOfSite)) {
final TypedQuery<Pages> query = getEntityManager()
.createNamedQuery("Pages.findForSite", Pages.class);
query.setParameter("domain", domainOfSite);
try {
return Optional.of(query.getSingleResult());
} catch(NoResultException ex) {
return Optional.empty();
}
} else {
final TypedQuery<Pages> query = getEntityManager()
.createNamedQuery("Pages.findForDefaultSite", Pages.class);
try {
return Optional.of(query.getSingleResult());
} catch (NoResultException ex) {
return Optional.empty();
}
}
}
@Override
public Class<Pages> getEntityClass() {
return Pages.class;
}
@Override
public boolean isNew(final Pages pages) {
return pages.getObjectId() == 0;
}
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Override
public void save(final Pages pages) {
super.save(pages);
}
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Override
public void delete(final Pages pages) {
super.delete(pages);
}
}

View File

@ -16,22 +16,22 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.sites;
package org.librecms.pages;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.pagemodel.PageModelManager;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
@ -41,7 +41,7 @@ import javax.ws.rs.core.UriInfo;
*/
@RequestScoped
@Path("/{page:.+}")
public class Pages {
public class PagesRouter {
@Inject
private CategoryManager categoryManager;
@ -49,36 +49,56 @@ public class Pages {
@Inject
private CategoryRepository categoryRepo;
@Inject
private PageModelManager pageModelManager;
@Inject
private SiteRepository siteRepo;
private PagesRepository siteRepo;
@Path("/")
@Path("/index.{lang}.html")
@Produces("text/html")
@Transactional(Transactional.TxType.REQUIRED)
public String getPage(@Context final UriInfo uriInfo,
@PathParam("page") final String page) {
public String getCategoryIndexPage(
@Context final UriInfo uriInfo,
@PathParam("page") final String page,
@PathParam("lang") final String language,
@QueryParam("theme") @DefaultValue("--DEFAULT--") final String theme) {
final String siteName = uriInfo.getBaseUri().getHost();
final String domain = uriInfo.getBaseUri().getHost();
final Site site = siteRepo.findByName(siteName);
final Category category =categoryRepo
.findByPath(site.getCategoryDomain(), page)
final Pages pages = siteRepo
.findPagesForSite(domain)
.orElseThrow(() -> new NotFoundException(String
.format("No Pages for domain \"%s\" available.",
domain)));
final Category category = categoryRepo
.findByPath(pages.getCategoryDomain(), page)
.orElseThrow(() -> new NotFoundException(String.format(
"No page for path \"%s\" in site \"%s\"",
page,
siteName)));
domain)));
// ToDo Get PageModelBuilder
// ToDo Build page
// ToDo Get Theme Processor
// ToDo Pass page to theme processor
// ToDo Return result of ThemeProcessor
throw new UnsupportedOperationException();
}
@Path("/{name}.{lang}.html")
public String getPage(
@Context final UriInfo uriInfo,
@PathParam("page") final String page,
@PathParam("lang") final String language,
@QueryParam("theme") @DefaultValue("--DEFAULT--") final String theme) {
throw new UnsupportedOperationException();
}
}

View File

@ -29,9 +29,6 @@ import java.util.Optional;
* interface providing some functionality needed by all implementations of the
* {@link PageBuilder} interface.
*
* @param <P> Generics variable for the class which represents the page created
* by the {@link PageBuilder}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*
*/
@ -47,18 +44,23 @@ public abstract class AbstractPageBuilder implements PageBuilder {
* the component objects created by the {@link ComponentBuilder}s are added
* to the page.
*
* @param pageModel The {@link PageModel\ to process.
* @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.
*
* @return A page containing all components from the {@link PageModel}.
*/
@Override
public Map<String, Object> buildPage(final PageModel pageModel) {
public Map<String, Object> buildPage(final PageModel pageModel,
final Map<String, Object> parameters) {
final Map<String, Object> page = buildPage();
final Map<String, Object> page = buildPage(parameters);
for (final ComponentModel componentModel : pageModel.getComponents()) {
final Optional<Object> component = buildComponent(
componentModel, componentModel.getClass());
componentModel, componentModel.getClass(),
parameters);
if (component.isPresent()) {
page.put(componentModel.getIdAttribute(),
component);
@ -75,12 +77,16 @@ public abstract class AbstractPageBuilder implements PageBuilder {
* created.
* @param componentModel The {@link ComponentModel} to process.
* @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.
*
* @return The components described by the {@code componentModel}.
*/
protected <M extends ComponentModel> Optional<Object> buildComponent(
final ComponentModel componentModel,
final Class<M> componentModelClass) {
final Class<M> componentModelClass,
final Map<String, Object> parameters) {
componentBuilderManager.findComponentBuilder(componentModel.getClass());
@ -90,7 +96,7 @@ public abstract class AbstractPageBuilder implements PageBuilder {
if (builder.isPresent()) {
@SuppressWarnings("unchecked")
final M model = (M) componentModel;
return Optional.of(builder.get().buildComponent(model));
return Optional.of(builder.get().buildComponent(model, parameters));
} else {
return Optional.empty();
}

View File

@ -30,6 +30,7 @@ import java.util.Map;
*/
public interface ComponentBuilder<M extends ComponentModel> {
Map<String, Object> buildComponent(M componentModel);
Map<String, Object> buildComponent(M componentModel,
final Map<String, Object> parameters);
}

View File

@ -43,9 +43,13 @@ public interface PageBuilder {
* {@link #buildPage(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.
*
* @return A page with the default components.
*/
Map<String, Object> buildPage();
Map<String, Object> buildPage(Map<String, Object> parameters);
/**
* Build a page of type {@code P} using the provided {@link PageModel}.
@ -53,11 +57,13 @@ public interface PageBuilder {
* 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.
*
* @return The page generated from the provided {@link PageModel}.
*/
Map<String, Object> buildPage(PageModel pageModel);
Map<String, Object> buildPage(PageModel pageModel,
Map<String, Object> parameters);
}

View File

@ -18,6 +18,7 @@
*/
package org.libreccm.pagemodel;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CoreConstants;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.web.CcmApplication;
@ -25,6 +26,7 @@ import org.libreccm.web.CcmApplication;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -35,9 +37,6 @@ import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
@ -110,27 +109,10 @@ import javax.persistence.Table;
+ "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE"
)
})
public class PageModel implements Serializable {
public class PageModel extends CcmObject implements Serializable {
private static final long serialVersionUID = 7252512839926020978L;
/**
* The ID of the entity in the database.
*/
@Id
@Column(name = "PAGE_MODEL_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long pageModelId;
/**
* The UUID of this {@code PageModel}. Please note that this UUID identifies
* the dataset not the model. Therefore the draft and the live version have
* different values for this field.
*/
@Column(name = "UUID", length = 255, nullable = false)
@NotNull
private String uuid;
/**
* The UUID of the model. Same for draft and live version.
*/
@ -203,22 +185,6 @@ public class PageModel implements Serializable {
description = new LocalizedString();
}
public long getPageModelId() {
return pageModelId;
}
protected void setPageModelId(final long pageModelId) {
this.pageModelId = pageModelId;
}
public String getUuid() {
return uuid;
}
protected void setUuid(final String uuid) {
this.uuid = uuid;
}
public String getModelUuid() {
return modelUuid;
}
@ -282,7 +248,7 @@ public class PageModel implements Serializable {
}
protected void setComponents(final List<ComponentModel> components) {
this.components = components;
this.components = new ArrayList<>(components);
}
protected void addComponent(final ComponentModel component) {
@ -299,9 +265,7 @@ public class PageModel implements Serializable {
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + (int) (pageModelId ^ (pageModelId >>> 32));
hash = 71 * hash + Objects.hashCode(uuid);
int hash = super.hashCode();
hash = 71 * hash + Objects.hashCode(name);
hash = 71 * hash + Objects.hashCode(title);
hash = 71 * hash + Objects.hashCode(description);
@ -317,6 +281,11 @@ public class PageModel implements Serializable {
if (obj == null) {
return false;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof PageModel)) {
return false;
}
@ -324,12 +293,6 @@ public class PageModel implements Serializable {
if (!other.canEqual(this)) {
return false;
}
if (pageModelId != other.getPageModelId()) {
return false;
}
if (!Objects.equals(uuid, other.getUuid())) {
return false;
}
if (!Objects.equals(name, other.getName())) {
return false;
}
@ -342,31 +305,21 @@ public class PageModel implements Serializable {
return Objects.equals(description, other.getDescription());
}
@Override
public boolean canEqual(final Object obj) {
return obj instanceof PageModel;
}
@Override
public final String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "pageModelId = %d, "
+ "uuid = %s, "
+ "name = \"%s\", "
return super.toString(String.format(", name = \"%s\", "
+ "title = %s, "
+ "description = %s, "
+ "type = \"%s\""
+ " }",
+ "description = %s%s",
super.toString(),
pageModelId,
uuid,
name,
Objects.toString(title),
Objects.toString(description),
type);
data));
}
}

View File

@ -0,0 +1,139 @@
/*
* 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.libreccm.sites;
import static org.libreccm.core.CoreConstants.*;
import org.libreccm.core.CcmObject;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "SITES", schema = DB_SCHEMA)
@NamedQueries({
@NamedQuery(
name = "Site.findByDomain",
query = "SELECT s FROM Site s WHERE s.domainOfSite = :domain"
)
,
@NamedQuery(
name = "Site.hasSiteForDomain",
query = "SELECT (CASE WHEN COUNT(s) > 0 THEN true ELSE false END) "
+ "FROM Site s "
+ "WHERE s.domainOfSite = :domain")
})
public class Site extends CcmObject {
private static final long serialVersionUID = 7993361616050713139L;
@Column(name = "DOMAIN_OF_SITE", unique = true)
private String domainOfSite;
@Column(name = "DEFAULT_SITE")
private boolean defaultSite;
@Column(name = "DEFAULT_THEME")
private String defaultTheme;
public String getDomainOfSite() {
return domainOfSite;
}
public void setDomainOfSite(final String domainOfSite) {
this.domainOfSite = domainOfSite;
}
public boolean isDefaultSite() {
return defaultSite;
}
public void setDefaultSite(final boolean defaultSite) {
this.defaultSite = defaultSite;
}
public String getDefaultTheme() {
return defaultTheme;
}
public void setDefaultTheme(final String defaultTheme) {
this.defaultTheme = defaultTheme;
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + Objects.hashCode(domainOfSite);
hash = 67 * hash + (defaultSite ? 1 : 0);
hash = 67 * hash + Objects.hashCode(defaultTheme);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!super.canEqual(obj)) {
return false;
}
if (!(obj instanceof Site)) {
return false;
}
final Site other = (Site) obj;
if (defaultSite != other.isDefaultSite()) {
return false;
}
if (!Objects.equals(domainOfSite, other.getDomainOfSite())) {
return false;
}
return Objects.equals(defaultTheme, other.getDefaultTheme());
}
@Override
public boolean canEqual(final Object obj) {
return obj instanceof Site;
}
@Override
public String toString(final String data) {
return super.toString(String.format(", domainOfSite = \"%s\", "
+ "defaultSite = %b, "
+ "defaultTheme = \"%s\"%s",
domainOfSite,
defaultSite,
defaultTheme,
data));
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.libreccm.sites;
import org.libreccm.core.AbstractEntityRepository;
import org.libreccm.core.CcmObjectRepository;
import org.libreccm.core.CoreConstants;
import org.libreccm.security.RequiresPrivilege;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class SiteRepository extends AbstractEntityRepository<Long, Site> {
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Site> findByDomain(final String domain) {
final TypedQuery<Site> query = getEntityManager()
.createNamedQuery("Site.findByDomain", Site.class);
query.setParameter("domain", domain);
try {
return Optional.of(query.getSingleResult());
} catch (NoResultException ex) {
return Optional.empty();
}
}
@Transactional(Transactional.TxType.REQUIRED)
public boolean hasSiteForDomain(final String domain) {
final TypedQuery<Boolean> query = getEntityManager()
.createNamedQuery("Site.hasSiteForDomain", Boolean.class);
query.setParameter("domain", domain);
return query.getSingleResult();
}
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Override
public void save(final Site site) {
super.save(site);
}
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Override
public void delete(final Site site) {
super.delete(site);
}
@Override
public Class<Site> getEntityClass() {
return Site.class;
}
@Override
public boolean isNew(final Site site) {
return site.getObjectId() == 0;
}
}

View File

@ -64,6 +64,19 @@ public interface ThemeProvider {
*/
Optional<ThemeInfo> getThemeInfo(String theme, ThemeVersion version);
/**
* This method can be used to determine if a theme provider provides a
* specific theme.
*
* @param theme The name of the theme.
* @param version The version. Implementations which do not support
* live/draft themes should ignore this parameter.
*
* @return {@code true} if the provider has a theme with the provided name
* in the provided version, {@code false} otherwise.
*/
boolean providesTheme(String theme, ThemeVersion version);
/**
* List all files in a theme at the specified path.
*

View File

@ -25,6 +25,7 @@ import org.libreccm.core.UnexpectedErrorException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
@ -66,6 +67,17 @@ public class Themes {
return themes;
}
public Optional<ThemeInfo> getTheme(final String name, final ThemeVersion version) {
for(final ThemeProvider provider : providers) {
if (provider.providesTheme(name, version)) {
return provider.getThemeInfo(name, version);
}
}
return Optional.empty();
}
public String process(Map<String, Object> page, ThemeInfo theme) {
final ThemeTypeLiteral themeType = new ThemeTypeLiteral(theme.getType());