From 709b952470934bfd8f254ef1fabd8b85a41e71d7 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 21 Dec 2019 17:05:37 +0100 Subject: [PATCH] Bugfixes for pagem model components and FTL libs Former-commit-id: 07c57f21f808d94b54f964d86826393695530652 --- .../CategoryTreeComponentRenderer.java | 8 ++- .../java/org/librecms/pages/PagesRouter.java | 19 +++--- .../themes/freemarker/ccm-cms/pages.ftl | 54 ++++++++++++---- .../themes/ftllibs-devel/page.html.ftl | 62 +++++++++++++++++-- 4 files changed, 119 insertions(+), 24 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/CategoryTreeComponentRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/CategoryTreeComponentRenderer.java index c1f552893..56b755053 100644 --- a/ccm-cms/src/main/java/org/librecms/pagemodel/CategoryTreeComponentRenderer.java +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/CategoryTreeComponentRenderer.java @@ -44,7 +44,7 @@ import org.libreccm.pagemodel.RendersComponent; /** * Renderer for the {@link CategoryTreeComponent}. - * + * * @author Jens Pelzetter */ @RequestScoped @@ -106,6 +106,8 @@ public class CategoryTreeComponentRenderer final Category rootCategory = findRootCategory(category); + result.put("categoryId", Long.toString(rootCategory.getObjectId())); + result.put("uuid", rootCategory.getUuid()); result.put("categoryName", rootCategory.getName()); result.put("categoryPath", categoryManager.getCategoryPath(rootCategory)); @@ -141,6 +143,8 @@ public class CategoryTreeComponentRenderer final Locale language) { final Map result = new HashMap<>(); + result.put("categoryId", Long.toString(category.getObjectId())); + result.put("uuid", category.getUuid()); result.put("categoryName", category.getName()); result.put("categoryPath", categoryManager.getCategoryPath(category)); result.put("categoryTitle", category.getTitle().getValue(language)); @@ -153,6 +157,8 @@ public class CategoryTreeComponentRenderer final Locale language) { final Map result = new HashMap<>(); + result.put("categoryId", Long.toString(category.getObjectId())); + result.put("uuid", category.getUuid()); result.put("categoryName", category.getName()); result.put("categoryPath", categoryManager.getCategoryPath(category)); result.put("categoryTitle", category.getTitle().getValue(language)); diff --git a/ccm-cms/src/main/java/org/librecms/pages/PagesRouter.java b/ccm-cms/src/main/java/org/librecms/pages/PagesRouter.java index dfb811d9b..8cb850f88 100644 --- a/ccm-cms/src/main/java/org/librecms/pages/PagesRouter.java +++ b/ccm-cms/src/main/java/org/librecms/pages/PagesRouter.java @@ -67,7 +67,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import static org.apache.logging.log4j.ThreadContext.*; import static org.librecms.pages.PagesConstants.*; /** @@ -81,9 +80,13 @@ public class PagesRouter { protected static final String PAGE_PATH = "pagePath"; + protected static final String PAGE_PATH_CATEGORY_ID = "categoryId"; + protected static final String PAGE_PATH_CATEGORY_NAME = "categoryName"; protected static final String PAGE_PATH_CATEGORY_TITLE = "categoryTitle"; + + protected static final String PAGE_PATH_CATEGORY_UUID = "uuid"; protected static final String SITE_INFO = "siteInfo"; @@ -329,7 +332,7 @@ public class PagesRouter { * @return */ @GET - @Path("/{page:[\\w/]+}/{name:[\\w\\-]+}") + @Path("/{page:[\\w\\-/]+}/{name:[\\w\\-]+}") @Transactional(Transactional.TxType.REQUIRED) public Response getPage( @Context final UriInfo uriInfo, @@ -369,7 +372,7 @@ public class PagesRouter { * @return */ @GET - @Path("/{page:[\\w/]+}/{name:[\\w\\-]+}.html") + @Path("/{page:[\\w\\-/]+}/{name:[\\w\\-]+}.html") @Transactional(Transactional.TxType.REQUIRED) public Response getPageAsHtml( @Context final UriInfo uriInfo, @@ -411,7 +414,7 @@ public class PagesRouter { * @return */ @GET - @Path("/{page:[\\w/]+}/{name:[\\w\\-]+}.{lang:\\w+}.html") + @Path("/{page:[\\w\\-/]+}/{name:[\\w\\-]+}.{lang:\\w+}.html") @Produces("text/html") @Transactional(Transactional.TxType.REQUIRED) public String getPageAsHtml( @@ -466,7 +469,7 @@ public class PagesRouter { * @return */ @GET - @Path("/{page:[\\w/]+}/{name:[\\w\\-]+}.{lang:\\w+}.json") + @Path("/{page:[\\w\\-/]+}/{name:[\\w\\-]+}.{lang:\\w+}.json") @Produces("application/json") @Transactional(Transactional.TxType.REQUIRED) public String getPageAsJson( @@ -521,7 +524,7 @@ public class PagesRouter { * @return */ @GET - @Path("/{page:[\\w/]+}/{name:[\\w\\-]+}.{lang:\\w+}.xml") + @Path("/{page:[\\w\\-/]+}/{name:[\\w\\-]+}.{lang:\\w+}.xml") @Produces("text/xml") @Transactional(Transactional.TxType.REQUIRED) public String getPageAsXml( @@ -718,7 +721,7 @@ public class PagesRouter { pagePath, language, parameters); - + final PageModel pageModel; if (pageModelVersion == PageModelVersion.DRAFT) { pageModel = pageModelManager @@ -783,6 +786,8 @@ public class PagesRouter { ) { final Map result = new HashMap<>(); + result.put(PAGE_PATH_CATEGORY_ID, Long.toString(category.getObjectId())); + result.put(PAGE_PATH_CATEGORY_UUID, category.getUuid()); result.put(PAGE_PATH_CATEGORY_NAME, category.getName()); result.put( PAGE_PATH_CATEGORY_TITLE, category.getTitle().getValue(language) diff --git a/ccm-cms/src/main/resources/themes/freemarker/ccm-cms/pages.ftl b/ccm-cms/src/main/resources/themes/freemarker/ccm-cms/pages.ftl index b7279a7b2..2310ad31d 100644 --- a/ccm-cms/src/main/resources/themes/freemarker/ccm-cms/pages.ftl +++ b/ccm-cms/src/main/resources/themes/freemarker/ccm-cms/pages.ftl @@ -37,7 +37,7 @@ <#if isRootPage()> <#return null> <#elseif getPagePath()??> - <#return getPathPath()?last> + <#return getPagePath()?last> <#else> <#return null> @@ -49,7 +49,11 @@ @return The ID of the currently selected category. --> <#function getSelectedCategoryId> - <#return getSelectedCategory().categoryId> + <#if getSelectedCategory()??> + <#return getSelectedCategory().categoryId> + <#else> + <#return ""> + <#--doc @@ -58,10 +62,12 @@ @param The model of a category as returned by several functions in this library. + @depcrecated Use the title property directly + @return The title of the category. --> <#function getCategoryTitle category> - <#return category.title> + <#return category.categoryTitle> <#-- @@ -70,6 +76,8 @@ @param The model of a category as returned by several functions in this library. + @depcrecated Use the categoryId of uuid property directly + @return The ID of the provided category. --> <#function getCategoryId category> @@ -82,10 +90,12 @@ @param The model of a category as returned by several functions in this library. + @depcrecated Use the selected property directly + @return `true` if the category is selected, `false` if not. --> <#function isCategorySelected category> - <#return category.isSelected> + <#return category.selected> <#--doc @@ -98,7 +108,7 @@ provided ID. --> <#function getNavigationRootUrl navigationId="categoryTree" containerId="container"> - <#return [container][navigationId].url> + <#return containerId?eval[navigationId].categoryPath> <#--doc @@ -107,23 +117,25 @@ @param navigationId The ID of the navigation system to use. @param containerId Container of the category menu + @depcrecated Without replacement + @return The title of the navigation. --> <#function getNavigationTitle navigationId="categoryMenu" containerId="container"> - <#return [containerId][navigationId].categoryTitle> + <#return containerId?eval[navigationId].categoryTitle> <#--doc Retrieves the first level of categories from the category hierachy with the - provided ID. If no id is provided 'categoryNav' is used. + provided ID. If no id is provided 'categoryTree' is used. - @param hierarchyId The ID of the category hierachy to use. + @param hierarchyId The ID of the category hierarchy to use. @param containerId Container of the category hierarchy @return The first level of categories in the hierarchy. --> -<#function getCategoryHierarchy hierarchyId="categoryNav" containerId="container"> - <#return [containerId][hierarchyId].subCategories> +<#function getCategoryHierarchy hierarchyId="categoryTree" containerId="container"> + <#return containerId?eval[hierarchyId].subCategories> <#--doc @@ -131,10 +143,12 @@ @param ofCategory The model of the category. + @depcrected Use the subCategories property directly + @return The sub categories of the provided category. --> <#function getSubCategories ofCategory> - <#return ofCategory.subcategories> + <#return ofCategory.subCategories> <#--doc @@ -142,6 +156,8 @@ @param categoryId The ID of the category to use. + @depcrecated Without replacement + @return Nothing --> <#function getSubCategoriesOfCategoryWithId categoryId> @@ -156,6 +172,20 @@ @return The model of the index item. --> +<#function getIndexItem containerId="container"> + <#return containerId?eval.greetingItem> + + +<#--doc + Gets the greeting/index item of the current navigation page. The returned + model can be processed with usual functions for processing content items. + + @param containerId Container of the index item. + + @depcrecated Use getIndexItem + + @return The model of the index item. +--> <#function getGreetingItem containerId="container"> - <#return eval(containerId).greetingItem> + <#return getIndexItem(containerId)> \ No newline at end of file diff --git a/ccm-theme-ftllibs-devel/src/main/resources/themes/ftllibs-devel/page.html.ftl b/ccm-theme-ftllibs-devel/src/main/resources/themes/ftllibs-devel/page.html.ftl index 5b5f4cddc..93db7ec10 100644 --- a/ccm-theme-ftllibs-devel/src/main/resources/themes/ftllibs-devel/page.html.ftl +++ b/ccm-theme-ftllibs-devel/src/main/resources/themes/ftllibs-devel/page.html.ftl @@ -126,7 +126,7 @@
Name
${cat.categoryName}
Title
-
${cat.categoryTitle}
+
${cat.categoryTitle!""}
@@ -146,7 +146,7 @@
Name
${cat.categoryName}
Title
-
${cat.categoryTitle}
+
${cat.categoryTitle!""}
@@ -162,12 +162,50 @@
Pages.getSelectedCategory()
<#if Pages.getSelectedCategory()??> - ${Pages.getSelectedCategory()} + ${Pages.getSelectedCategory().categoryName} <#else> No category selected.
+
+
Pages.getSelectedCategoryId()
+
+ ${Pages.getSelectedCategoryId()} +
+
+
+
Pages.getNavigationRootUrl()
+ ${Pages.getNavigationRootUrl()} +
+
+
Pages.getCategoryHierarchy()
+
+ <#list Pages.getCategoryHierarchy()> +
    + <#items as cat> +
  • + ${cat.categoryId}:${cat.categoryName} +
  • + +
+ <#else> + No categories in hierarchy. + +
+
+
+
Pages.getIndexItem()
+
+ <#assign indexItem = Pages.getIndexItem()> + <#if (indexItem?keys?size > 0)> + ${indexItem.uuid}:${indexItem.name}:${indexItem.title} + <#else> + No index item + +
+
+

ccm-navigation/navigation.ftl as Navigation

@@ -176,7 +214,23 @@

Navigation.getCategoryPath
-
${Navigation.getCategoryPath()}
+
+ Path length: ${Navigation.getCategoryPath()?size} + <#list Navigation.getCategoryPath()> +
    + <#items as cat> +
  • +
    +
    Name
    +
    ${cat.categoryName}
    +
    Title
    +
    ${cat.categoryTitle!""}
    +
    +
  • + +
+ +