From 6383aec674aed7df582bb8b61560c5a0636905b7 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 13 Nov 2021 11:07:02 +0100 Subject: [PATCH] JavaDoc for PagesController --- .../org/librecms/pages/PagesController.java | 111 ++++++++++++++++-- .../pages/models/ContentItemModel.java | 10 +- 2 files changed, 113 insertions(+), 8 deletions(-) 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: + * + * + * + * 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: + * + * + * The language to use is determined using the following algorithm: + *
    + *
  1. + * 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}. + *
  2. + *
  3. + * 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}. + *
  4. + *
* * @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) )));