diff --git a/ccm-cms/src/main/java/org/librecms/pages/PagesController.java b/ccm-cms/src/main/java/org/librecms/pages/PagesController.java
index 12323ead4..1615825ab 100644
--- a/ccm-cms/src/main/java/org/librecms/pages/PagesController.java
+++ b/ccm-cms/src/main/java/org/librecms/pages/PagesController.java
@@ -33,6 +33,7 @@ import org.libreccm.theming.Themes;
import org.libreccm.theming.mvc.ThemesMvc;
import org.librecms.contentsection.ContentItemVersion;
import org.librecms.pages.models.CategoryModel;
+import org.librecms.pages.models.ContentItemModel;
import org.librecms.pages.models.SiteInfoModel;
import java.net.URI;
@@ -61,6 +62,95 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/**
+ * Controller for the pages MVC application responsible for initializing the
+ * models used by themes for displaying the pages.
+ *
+ * This controller is the main entry point for the Pages application, which is
+ * the primary entry point for most public sites powered by LibreCMS. Based on
+ * the provided path it looks up the matching category and initalizes the models
+ * used by the themes to create the public pages. The application is ,as most
+ * other frontends of LibreCCM/LibreCMS, based on the EE MVC framework.
+ *
+ * In the following description, {placeholder} stands for a
+ * placeholder for a parameter. The placeholder {path} stands for
+ * the requested path. The path might be empty, in this case the root category
+ * of the category system associated with the instance of the pages application
+ * is used.
+ *
+ * Depending on the provided path in the URL this controller does the following:
+ *
+ *
+ * -
+ * If the requested path does not end with
.html or
+ * .{lang}.html: Determine the language to use, select the most
+ * appropriate language. Redirect the request the
+ * /@pages/{path}/index.{lang}.de, where lang is the most
+ * approbriate language determined (also called negotiated language).
+ *
+ * -
+ * If the requested path ends matches
/@pages/{path}/index.html
+ * (the exact regex pattern can be found in the documentation of the responsible
+ * methods) determine the most appropriate of the available languages and
+ * redirect the request /@pages/{path}/index.{lang}.html, where
+ * {lang} is the negotiated language.
+ *
+ * -
+ * If the requested path ends matches
+ *
/@pages/{path}/{itemname}.html (the exact regex patterns for
+ * {path} and itemname can be found in the
+ * documentation of the responsible methods) determine the most appropriate of
+ * the available languages and redirect the request to
+ * /@pages/{path}/{itemname}.{lang}.html, , where
+ * {lang} is the negotiated language.
+ *
+ * -
+ * If the request path matches
/@pages/{path}/index.{lang}.html
+ * display the index page of the category together with the index item of the
+ * category, if the category has an index item. If the category has an index
+ * item and the index item is not available in the language requested by the
+ * {lang} parameter in the path, raise a 404 Not Found
+ * error using a {@link WebApplicationException}.
+ *
+ * * -
+ * If the request path matches
+ *
/@pages/{path}/{itemname}.{lang}.html display the item with the
+ * name provided in the {itemname} parameter. If no item with a
+ * matching name is assigned to the category raise a 404 Not Found
+ * using a {@link WebApplicationException}. Also, if there is a matching item,
+ * but it is not available in the language requested by the {lang}
+ * parameter, raise a 404 Not Found Error using a
+ * {@link WebApplicationException}.
+ *
+ *
+ *
+ * In the last two cases this controller will initialize the basic models to
+ * provide soem data for displaying theme, and delegate to the theme by calling
+ * {@link ThemesMvc#getMvcTemplate(javax.ws.rs.core.UriInfo, java.lang.String, java.lang.String)}.
+ * {@link ThemesMvc} will determine the theme to use from the requested URL. For
+ * details please refer to the documentation of {@link ThemesMvc}.
+ *
+ * The following models are initialized by this controller:
+ *
+ * - {@link CategoryModel}
+ * - {@link ContentItemModel}
+ * - {@link SiteInfoModel}
+ *
+ *
+ * The language to use is determined using the following algorithm:
+ *
+ * -
+ * Check if one of the languages sent by the user agent in the
+ *
Accept-Language header is a supported language (see
+ * {@link KernelConfig#supportedLanguages}. If not fall back to the default
+ * language (see {@link KernelConfig#defaultLanguage}.
+ *
+ * -
+ * Check if the requested item is available in the selected language, or if a
+ * category without an index item is requested, if the category is avaiable for
+ * the selected language. If yes use the selected language otherwise fallback to
+ * the default default configured in {@link KernelConfig#defaultLanguage}.
+ *
+ *
*
* @author Jens Pelzetter
*/
@@ -77,11 +167,14 @@ public class PagesController {
@Inject
private CategoryRepository categoryRepo;
+ @Inject
+ private GlobalizationHelper globalizationHelper;
+
@Inject
private ConfigurationManager confManager;
@Inject
- private GlobalizationHelper globalizationHelper;
+ private ContentItemModel contentItemModel;
@Inject
private PageManager pageManager;
@@ -114,7 +207,6 @@ public class PagesController {
@Path("/")
@Transactional(Transactional.TxType.REQUIRED)
public Response redirectToIndexPage(@Context final UriInfo uriInfo) {
-
final String domain = uriInfo.getBaseUri().getHost();
final Pages pages = getPages(domain);
final Category category = getCategory(domain, pages, "/");
@@ -130,8 +222,8 @@ public class PagesController {
@Transactional(Transactional.TxType.REQUIRED)
public Response getRootPage(
@Context final UriInfo uriInfo,
- @PathParam("name") final String itemName) {
-
+ @PathParam("name") final String itemName
+ ) {
final String domain = uriInfo.getBaseUri().getHost();
final Pages pages = getPages(domain);
final Category category = getCategory(domain, pages, "/");
@@ -187,8 +279,11 @@ public class PagesController {
) {
final Versions versions = generateFromPreviewParam(preview);
- final Site site = getSite(uriInfo);
-
+ globalizationHelper.setSelectedLocale(new Locale(language));
+
+ contentItemModel.setItemName(itemName);
+ contentItemModel.setItemVersion(versions.getContentItemVersion());
+
return themesMvc.getMvcTemplate(uriInfo, "pages", "page");
}
@@ -308,6 +403,8 @@ public class PagesController {
final String preview
) {
final Versions versions = generateFromPreviewParam(preview);
+ contentItemModel.setItemName(itemName);
+ contentItemModel.setItemVersion(versions.getContentItemVersion());
final Site site = getSite(uriInfo);
return themesMvc.getMvcTemplate(uriInfo, "pages", "page");
@@ -538,7 +635,7 @@ public class PagesController {
this.themeVersion = themeVersion;
}
- public ContentItemVersion getContentVersion() {
+ public ContentItemVersion getContentItemVersion() {
return contentVersion;
}
diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/ContentItemModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/ContentItemModel.java
index 61ce14e8b..11f725503 100644
--- a/ccm-cms/src/main/java/org/librecms/pages/models/ContentItemModel.java
+++ b/ccm-cms/src/main/java/org/librecms/pages/models/ContentItemModel.java
@@ -93,6 +93,14 @@ public class ContentItemModel {
public void setItemName(final String itemName) {
this.itemName = itemName;
}
+
+ public ContentItemVersion getItemVersion() {
+ return itemVersion;
+ }
+
+ public void setItemVersion(final ContentItemVersion itemVersion) {
+ this.itemVersion = itemVersion;
+ }
/**
* Retrieves the current content item. Depending if {@link #itemName} has
@@ -252,7 +260,7 @@ public class ContentItemModel {
builder.equal(from.get("displayName"), itemName),
builder.equal(
from.get("version"),
- ContentItemVersion.DRAFT
+ itemVersion
),
builder.equal(join.get("category"), category)
)));